about summary refs log tree commit diff stats
path: root/internal/config/repository.go
blob: 957cad4c73f65f9349311a9d060314b422485e1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package config

import (
	"fmt"
	"strings"
)

type RepoType int

const (
	UnknownRepoType = iota
	GitHub
)

type Repository struct {
	Type     string `default:"github"`
	Owner    string
	Repo     string
	Revision string
}

func (f RepoType) String() string {
	switch f {
	case GitHub:
		return "github"
	default:
		return fmt.Sprintf("RepoType(%d)", f)
	}
}

func parseRepoType(name string) (RepoType, error) {
	switch strings.ToLower(name) {
	case "github":
		return GitHub, nil
	default:
		return UnknownRepoType, fmt.Errorf("unsupported repo type %s", name)
	}
}

func (f *RepoType) UnmarshalText(text []byte) error {
	var err error
	*f, err = parseRepoType(string(text))

	return err
}