MCPcopy Create free account
hub / github.com/ejoffe/spr / ParseConfig

Function ParseConfig

config/config_parser/config_parser.go:16–69  ·  view source on GitHub ↗
(gitcmd git.GitInterface)

Source from the content-addressed store, hash-verified

14)
15
16func ParseConfig(gitcmd git.GitInterface) *config.Config {
17 cfg := config.EmptyConfig()
18
19 rake.LoadSources(cfg.Repo,
20 rake.DefaultSource(),
21 NewGitHubRemoteSource(cfg, gitcmd),
22 rake.YamlFileSource(RepoConfigFilePath(gitcmd)),
23 NewRemoteBranchSource(gitcmd),
24 )
25 if cfg.Repo.GitHubHost == "" {
26 fmt.Println("unable to auto configure repository host - must be set manually in .spr.yml")
27 os.Exit(2)
28 }
29 if cfg.Repo.GitHubRepoOwner == "" {
30 fmt.Println("unable to auto configure repository owner - must be set manually in .spr.yml")
31 os.Exit(3)
32 }
33
34 if cfg.Repo.GitHubRepoName == "" {
35 fmt.Println("unable to auto configure repository name - must be set manually in .spr.yml")
36 os.Exit(4)
37 }
38
39 rake.LoadSources(cfg.User,
40 rake.DefaultSource(),
41 rake.YamlFileSource(UserConfigFilePath()),
42 )
43
44 rake.LoadSources(cfg.State,
45 rake.DefaultSource(),
46 rake.YamlFileSource(InternalConfigFilePath()),
47 )
48
49 cfg.State.RunCount = cfg.State.RunCount + 1
50
51 rake.LoadSources(cfg.State,
52 rake.YamlFileWriter(InternalConfigFilePath()))
53
54 // init case : if yaml config files not found : create them
55 if _, err := os.Stat(RepoConfigFilePath(gitcmd)); errors.Is(err, os.ErrNotExist) {
56 rake.LoadSources(cfg.Repo,
57 rake.YamlFileWriter(RepoConfigFilePath(gitcmd)))
58 }
59
60 if _, err := os.Stat(UserConfigFilePath()); errors.Is(err, os.ErrNotExist) {
61 rake.LoadSources(cfg.User,
62 rake.YamlFileWriter(UserConfigFilePath()))
63 }
64
65 // Normalize config (e.g., set PRTemplateType to "custom" if PRTemplatePath is provided)
66 cfg.Normalize()
67
68 return cfg
69}
70
71func CheckConfig(cfg *config.Config) error {
72 if strings.Contains(cfg.Repo.GitHubBranch, "/") {

Callers 2

mainFunction · 0.92
mainFunction · 0.92

Calls 7

EmptyConfigFunction · 0.92
NewGitHubRemoteSourceFunction · 0.85
RepoConfigFilePathFunction · 0.85
NewRemoteBranchSourceFunction · 0.85
UserConfigFilePathFunction · 0.85
InternalConfigFilePathFunction · 0.85
NormalizeMethod · 0.80

Tested by

no test coverage detected