diff options
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 20 | ||||
| -rw-r--r-- | internal/config/config_test.go | 27 |
2 files changed, 42 insertions, 5 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 48e6d5f..4e40cdf 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -19,11 +19,12 @@ type Organization struct { // Config holds the application configuration type Config struct { - Organizations []Organization `json:"organizations"` - Repositories []string `json:"repositories,omitempty"` - ExcludeBranches []string `json:"exclude_branches,omitempty"` // Regex patterns for branches to exclude - WorkDir string `json:"work_dir,omitempty"` // Working directory for cloning repositories - ExcludeFromShowcase []string `json:"exclude_from_showcase,omitempty"` // Repository names to exclude from showcase + Organizations []Organization `json:"organizations"` + Repositories []string `json:"repositories,omitempty"` + ExcludeBranches []string `json:"exclude_branches,omitempty"` // Regex patterns for branches to exclude + WorkDir string `json:"work_dir,omitempty"` // Working directory for cloning repositories + ExcludeFromShowcase []string `json:"exclude_from_showcase,omitempty"` // Repository names to exclude from showcase + ShowcaseStatsBranches map[string]string `json:"showcase_stats_branches,omitempty"` // Repository names mapped to the branch used for showcase stats/code snippets // SkipReleases maps a repository name to a list of tag names for which // releases should NOT be created on any platform (GitHub/Codeberg) SkipReleases map[string][]string `json:"skip_releases,omitempty"` @@ -102,6 +103,15 @@ func (c *Config) Validate() error { } } + for repo, branch := range c.ShowcaseStatsBranches { + if strings.TrimSpace(repo) == "" { + return fmt.Errorf("showcase_stats_branches: repository name cannot be empty") + } + if strings.TrimSpace(branch) == "" { + return fmt.Errorf("showcase_stats_branches[%q]: branch name cannot be empty", repo) + } + } + return nil } diff --git a/internal/config/config_test.go b/internal/config/config_test.go new file mode 100644 index 0000000..db70457 --- /dev/null +++ b/internal/config/config_test.go @@ -0,0 +1,27 @@ +package config + +import ( + "strings" + "testing" +) + +func TestValidate_ShowcaseStatsBranchesRejectsEmptyBranch(t *testing.T) { + t.Parallel() + + cfg := &Config{ + Organizations: []Organization{ + {Host: "git@github.com", Name: "test-user"}, + }, + ShowcaseStatsBranches: map[string]string{ + "foo.zone": " ", + }, + } + + err := cfg.Validate() + if err == nil { + t.Fatal("Validate() error = nil, want branch validation error") + } + if !strings.Contains(err.Error(), "showcase_stats_branches") { + t.Fatalf("Validate() error = %q, want showcase_stats_branches context", err) + } +} |
