-
Notifications
You must be signed in to change notification settings - Fork 3
/
config_org.go
64 lines (51 loc) · 1.42 KB
/
config_org.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
package gitdir
import (
"github.com/belak/go-gitdir/internal/git"
"github.com/belak/go-gitdir/models"
)
func (c *Config) loadOrgConfigs() error {
// Bail early if we don't need to load anything.
if !c.Options.OrgConfig {
return nil
}
errors := make([]error, 0, len(c.Orgs))
for orgName := range c.Orgs {
errors = append(errors, c.loadOrgConfig(orgName))
}
// Because we want to display all the errors, we return this as a
// multi-error rather than bailing on the first error.
return newMultiError(errors...)
}
func (c *Config) loadOrgConfig(orgName string) error {
orgRepo, err := git.EnsureRepo(c.fs, "admin/org-"+orgName)
if err != nil {
return err
}
err = orgRepo.Checkout(c.orgRepos[orgName])
if err != nil {
return err
}
data, err := orgRepo.GetFile("config.yml")
if err != nil {
return err
}
orgConfig, err := models.ParseOrgConfig(data)
if err != nil {
return err
}
c.Orgs[orgName].Admin = append(c.Orgs[orgName].Admin, orgConfig.Admin...)
c.Orgs[orgName].Write = append(c.Orgs[orgName].Write, orgConfig.Write...)
c.Orgs[orgName].Read = append(c.Orgs[orgName].Read, orgConfig.Read...)
if c.Options.OrgConfigRepos {
for repoName, repo := range orgConfig.Repos {
// If it's already defined, skip it.
//
// TODO: this should throw a validation error
if _, ok := c.Orgs[orgName].Repos[repoName]; ok {
continue
}
c.Orgs[orgName].Repos[repoName] = repo
}
}
return nil
}