Skip to content

Commit 4ef59f3

Browse files
committed
refactor: extract strategy constants to fix goconst lint
1 parent 45fce0d commit 4ef59f3

4 files changed

Lines changed: 25 additions & 19 deletions

File tree

internal/config/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import (
1111
"gopkg.in/yaml.v3"
1212
)
1313

14+
// StrategyCommit pushes directly to the default branch.
15+
const StrategyCommit = "commit"
16+
17+
// StrategyPR creates a branch and opens a pull request.
18+
const StrategyPR = "pr"
19+
1420
// CLIConfig holds all CLI-level configuration.
1521
type CLIConfig struct {
1622
Org string
@@ -43,7 +49,7 @@ var issueConfigRe = regexp.MustCompile(`(?s)<!--\s*issuebot\s*\n(.*?)\n-->`)
4349
func DefaultCLIConfig() CLIConfig {
4450
return CLIConfig{
4551
Label: "",
46-
Strategy: "commit",
52+
Strategy: StrategyCommit,
4753
Interval: 30 * time.Second,
4854
Workers: 5,
4955
MaxRetries: 3,

internal/config/config_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ branch: my-feature
1919
More text.`
2020

2121
cfg := ParseIssueConfig(body)
22-
if cfg.Strategy != "commit" {
23-
t.Errorf("strategy: got %q, want %q", cfg.Strategy, "commit")
22+
if cfg.Strategy != StrategyCommit {
23+
t.Errorf("strategy: got %q, want %q", cfg.Strategy, StrategyCommit)
2424
}
2525

2626
if cfg.Branch != "my-feature" {
@@ -65,8 +65,8 @@ another: thing
6565
-->`
6666

6767
cfg := ParseIssueConfig(body)
68-
if cfg.Strategy != "pr" {
69-
t.Errorf("strategy: got %q, want %q", cfg.Strategy, "pr")
68+
if cfg.Strategy != StrategyPR {
69+
t.Errorf("strategy: got %q, want %q", cfg.Strategy, StrategyPR)
7070
}
7171

7272
if cfg.Branch != "fix-123" {
@@ -82,7 +82,7 @@ func TestDefaultConfig(t *testing.T) {
8282
got interface{}
8383
want interface{}
8484
}{
85-
{"strategy", cfg.Strategy, "commit"},
85+
{"strategy", cfg.Strategy, StrategyCommit},
8686
{"interval", cfg.Interval, 30 * time.Second},
8787
{"workers", cfg.Workers, 5},
8888
{"max-retries", cfg.MaxRetries, 3},
@@ -124,18 +124,18 @@ func TestDefaultConfig_WorkspaceUsesHomeDir(t *testing.T) {
124124
func TestResolveStrategy_IssueOverrides(t *testing.T) {
125125
cli := DefaultCLIConfig()
126126

127-
issue := IssueConfig{Strategy: "commit"}
128-
if got := ResolveStrategy(cli, issue); got != "commit" {
129-
t.Errorf("got %q, want %q", got, "commit")
127+
issue := IssueConfig{Strategy: StrategyCommit}
128+
if got := ResolveStrategy(cli, issue); got != StrategyCommit {
129+
t.Errorf("got %q, want %q", got, StrategyCommit)
130130
}
131131
}
132132

133133
func TestResolveStrategy_FallbackToCLI(t *testing.T) {
134134
cli := DefaultCLIConfig()
135135

136136
issue := IssueConfig{}
137-
if got := ResolveStrategy(cli, issue); got != "commit" {
138-
t.Errorf("got %q, want %q", got, "commit")
137+
if got := ResolveStrategy(cli, issue); got != StrategyCommit {
138+
t.Errorf("got %q, want %q", got, StrategyCommit)
139139
}
140140
}
141141

internal/worker/worker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (w *Worker) ProcessIssue(ctx context.Context, repo string, issue *github.Is
153153
}
154154

155155
// If PR strategy, create branch.
156-
if strategy == "pr" {
156+
if strategy == config.StrategyPR {
157157
cmd := exec.CommandContext(ctx, "git", "-C", repoDir, "checkout", "-b", branch)
158158

159159
cmd.Stderr = os.Stderr
@@ -205,7 +205,7 @@ func (w *Worker) ProcessIssue(ctx context.Context, repo string, issue *github.Is
205205
}
206206

207207
// Push and optionally create PR.
208-
if strategy == "pr" {
208+
if strategy == config.StrategyPR {
209209
if err := w.pushAndCreatePR(ctx, key, logger, repoDir, repo, branch, issue, attempts, issueCfg); err != nil {
210210
return
211211
}

internal/worker/worker_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func testWorker(t *testing.T) *Worker {
9191
return &Worker{
9292
State: st,
9393
Notifier: notify.New(""),
94-
CLIConfig: config.CLIConfig{Strategy: "pr", MaxRetries: 3, Workspace: filepath.Join(dir, "repos"), PromptFile: promptFile, Command: testEchoCmd},
94+
CLIConfig: config.CLIConfig{Strategy: config.StrategyPR, MaxRetries: 3, Workspace: filepath.Join(dir, "repos"), PromptFile: promptFile, Command: testEchoCmd},
9595
}
9696
}
9797

@@ -251,7 +251,7 @@ func TestWorker_ProcessIssue_PRStrategy(t *testing.T) {
251251
Client: ghClient,
252252
State: st,
253253
Notifier: notify.New(""),
254-
CLIConfig: config.CLIConfig{Strategy: "pr", MaxRetries: 3, Workspace: filepath.Join(dir, "repos"), PromptFile: promptFile, Command: cmdPath},
254+
CLIConfig: config.CLIConfig{Strategy: config.StrategyPR, MaxRetries: 3, Workspace: filepath.Join(dir, "repos"), PromptFile: promptFile, Command: cmdPath},
255255

256256
CloneURL: bare,
257257
}
@@ -294,7 +294,7 @@ func TestWorker_ProcessIssue_DryRun(t *testing.T) {
294294
w := &Worker{
295295
State: st,
296296
Notifier: notify.New(""),
297-
CLIConfig: config.CLIConfig{Strategy: "pr", MaxRetries: 3, Workspace: filepath.Join(dir, "repos"), PromptFile: promptFile, DryRun: true, Command: cmdPath},
297+
CLIConfig: config.CLIConfig{Strategy: config.StrategyPR, MaxRetries: 3, Workspace: filepath.Join(dir, "repos"), PromptFile: promptFile, DryRun: true, Command: cmdPath},
298298

299299
CloneURL: bare,
300300
}
@@ -370,7 +370,7 @@ func TestWorker_ProcessIssue_PostCommand(t *testing.T) {
370370
Client: ghClient,
371371
State: st,
372372
Notifier: notify.New(""),
373-
CLIConfig: config.CLIConfig{Strategy: "pr", MaxRetries: 3, Workspace: filepath.Join(dir, "repos"), PromptFile: promptFile, Command: cmdPath},
373+
CLIConfig: config.CLIConfig{Strategy: config.StrategyPR, MaxRetries: 3, Workspace: filepath.Join(dir, "repos"), PromptFile: promptFile, Command: cmdPath},
374374

375375
CloneURL: bare,
376376
}
@@ -401,8 +401,8 @@ func TestWorker_ProcessIssue_IssueConfigOverride(t *testing.T) {
401401
issueCfg := config.ParseIssueConfig(body)
402402

403403
strategy := config.ResolveStrategy(cli, issueCfg)
404-
if strategy != "pr" {
405-
t.Errorf("strategy = %q, want %q", strategy, "pr")
404+
if strategy != config.StrategyPR {
405+
t.Errorf("strategy = %q, want %q", strategy, config.StrategyPR)
406406
}
407407

408408
branch := config.ResolveBranch(issueCfg, 5)

0 commit comments

Comments
 (0)