(gitcmd git.GitInterface)
| 14 | ) |
| 15 | |
| 16 | func 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 | |
| 71 | func CheckConfig(cfg *config.Config) error { |
| 72 | if strings.Contains(cfg.Repo.GitHubBranch, "/") { |
no test coverage detected