-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_schema.go
76 lines (60 loc) · 1.51 KB
/
config_schema.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package core
func NewConfig() *Config {
return &Config{
Templates: &TemplatesConfig{
Repos: map[string]*GhRepoConfig{},
Branches: map[string]*GhBranchConfig{},
BranchProtections: map[string]*GhBranchProtectionConfig{},
},
Repos: []*GhRepoConfig{},
}
}
type Config struct {
Templates *TemplatesConfig `yaml:"templates,omitempty"`
Repos []*GhRepoConfig `yaml:"repos,omitempty"`
// Org ...
// Teams ...
}
func (c *Config) AppendRepo(repo *GhRepoConfig) {
c.Repos = append(c.Repos, repo)
}
func (c *Config) GetRepo(name string) *GhRepoConfig {
for _, r := range c.Repos {
if r.Name != nil && *r.Name == name {
return r
}
}
return nil
}
type TemplatesConfig struct {
Repos map[string]*GhRepoConfig `yaml:"repos,omitempty"`
Branches map[string]*GhBranchConfig `yaml:"branches,omitempty"`
BranchProtections map[string]*GhBranchProtectionConfig `yaml:"branch-protections,omitempty"`
}
func (c *TemplatesConfig) GetRepo(name string) *GhRepoConfig {
if c.Repos == nil {
return nil
}
if tpl, ok := c.Repos[name]; ok {
return tpl
}
return nil
}
func (c *TemplatesConfig) GetBranch(name string) *GhBranchConfig {
if c.Branches == nil {
return nil
}
if tpl, ok := c.Branches[name]; ok {
return tpl
}
return nil
}
func (c *TemplatesConfig) GetBranchProtection(name string) *GhBranchProtectionConfig {
if c.BranchProtections == nil {
return nil
}
if tpl, ok := c.BranchProtections[name]; ok {
return tpl
}
return nil
}