Skip to content

Commit 09b2e39

Browse files
Excavator: Run go fix to apply Go 1.26+ modernizers (#733)
1 parent 5a179fb commit 09b2e39

8 files changed

Lines changed: 36 additions & 42 deletions

File tree

bulldozer/evaluate_test.go

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ func TestShouldUpdatePR(t *testing.T) {
557557
IsDraftValue: true,
558558
},
559559
updateConfig: UpdateConfig{
560-
IgnoreDrafts: boolVal(true),
560+
IgnoreDrafts: new(true),
561561
},
562562
expectingUpdate: false,
563563
},
@@ -566,7 +566,7 @@ func TestShouldUpdatePR(t *testing.T) {
566566
IsDraftValue: false,
567567
},
568568
updateConfig: UpdateConfig{
569-
IgnoreDrafts: boolVal(true),
569+
IgnoreDrafts: new(true),
570570
},
571571
expectingUpdate: true,
572572
},
@@ -576,7 +576,7 @@ func TestShouldUpdatePR(t *testing.T) {
576576
LabelValue: []string{"trigger"},
577577
},
578578
updateConfig: UpdateConfig{
579-
IgnoreDrafts: boolVal(true),
579+
IgnoreDrafts: new(true),
580580
Trigger: Signals{
581581
Labels: []string{"trigger"},
582582
},
@@ -589,7 +589,7 @@ func TestShouldUpdatePR(t *testing.T) {
589589
LabelValue: []string{"trigger"},
590590
},
591591
updateConfig: UpdateConfig{
592-
IgnoreDrafts: boolVal(true),
592+
IgnoreDrafts: new(true),
593593
Trigger: Signals{
594594
Labels: []string{"trigger"},
595595
},
@@ -602,7 +602,7 @@ func TestShouldUpdatePR(t *testing.T) {
602602
LabelValue: []string{"ignore"},
603603
},
604604
updateConfig: UpdateConfig{
605-
IgnoreDrafts: boolVal(true),
605+
IgnoreDrafts: new(true),
606606
Ignore: Signals{
607607
Labels: []string{"ignore"},
608608
},
@@ -615,7 +615,7 @@ func TestShouldUpdatePR(t *testing.T) {
615615
LabelValue: []string{"ignore"},
616616
},
617617
updateConfig: UpdateConfig{
618-
IgnoreDrafts: boolVal(true),
618+
IgnoreDrafts: new(true),
619619
Ignore: Signals{
620620
Labels: []string{"ignore"},
621621
},
@@ -628,7 +628,7 @@ func TestShouldUpdatePR(t *testing.T) {
628628
LabelValue: []string{"ignore", "trigger"},
629629
},
630630
updateConfig: UpdateConfig{
631-
IgnoreDrafts: boolVal(true),
631+
IgnoreDrafts: new(true),
632632
Ignore: Signals{
633633
Labels: []string{"ignore"},
634634
},
@@ -644,7 +644,7 @@ func TestShouldUpdatePR(t *testing.T) {
644644
LabelValue: []string{"ignore", "trigger"},
645645
},
646646
updateConfig: UpdateConfig{
647-
IgnoreDrafts: boolVal(true),
647+
IgnoreDrafts: new(true),
648648
Ignore: Signals{
649649
Labels: []string{"ignore"},
650650
},
@@ -659,7 +659,7 @@ func TestShouldUpdatePR(t *testing.T) {
659659
IsDraftValue: true,
660660
},
661661
updateConfig: UpdateConfig{
662-
IgnoreDrafts: boolVal(true),
662+
IgnoreDrafts: new(true),
663663
Ignore: Signals{
664664
Labels: []string{"ignore"},
665665
},
@@ -671,7 +671,7 @@ func TestShouldUpdatePR(t *testing.T) {
671671
IsDraftValue: true,
672672
},
673673
updateConfig: UpdateConfig{
674-
IgnoreDrafts: boolVal(true),
674+
IgnoreDrafts: new(true),
675675
Trigger: Signals{
676676
Labels: []string{"trigger"},
677677
},
@@ -822,7 +822,7 @@ func TestShouldUpdatePR(t *testing.T) {
822822
SuccessStatusesValue: []string{"status1"},
823823
},
824824
updateConfig: UpdateConfig{
825-
IgnoreDrafts: boolVal(true),
825+
IgnoreDrafts: new(true),
826826
RequiredStatuses: []string{"status1", "status2"},
827827
},
828828
expectingUpdate: false,
@@ -833,7 +833,7 @@ func TestShouldUpdatePR(t *testing.T) {
833833
SuccessStatusesValue: []string{"status1", "status2"},
834834
},
835835
updateConfig: UpdateConfig{
836-
IgnoreDrafts: boolVal(true),
836+
IgnoreDrafts: new(true),
837837
RequiredStatuses: []string{"status1", "status2"},
838838
},
839839
expectingUpdate: false,
@@ -844,7 +844,7 @@ func TestShouldUpdatePR(t *testing.T) {
844844
SuccessStatusesValue: []string{"status1"},
845845
},
846846
updateConfig: UpdateConfig{
847-
IgnoreDrafts: boolVal(true),
847+
IgnoreDrafts: new(true),
848848
RequiredStatuses: []string{"status1", "status2"},
849849
},
850850
expectingUpdate: false,
@@ -855,7 +855,7 @@ func TestShouldUpdatePR(t *testing.T) {
855855
SuccessStatusesValue: []string{"status1", "status2"},
856856
},
857857
updateConfig: UpdateConfig{
858-
IgnoreDrafts: boolVal(true),
858+
IgnoreDrafts: new(true),
859859
RequiredStatuses: []string{"status1", "status2"},
860860
},
861861
expectingUpdate: true,
@@ -872,7 +872,3 @@ func TestShouldUpdatePR(t *testing.T) {
872872
})
873873
}
874874
}
875-
876-
func boolVal(b bool) *bool {
877-
return &b
878-
}

bulldozer/merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (m *GitHubMerger) ffOnlyMerge(ctx context.Context, pullCtx pull.Context) (s
7676
headCommitSHA := pullCtx.HeadSHA()
7777
newRef, _, err := m.client.Git.UpdateRef(ctx, pullCtx.Owner(), pullCtx.Repo(), ref.GetRef(), github.UpdateRef{
7878
SHA: headCommitSHA,
79-
Force: github.Ptr(false),
79+
Force: new(false),
8080
})
8181
if err != nil {
8282
return "", errors.Wrap(err, "could not perform ff-only merge")

bulldozer/merge_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ func TestBaseBranchChangedRetry(t *testing.T) {
193193
&http.Response{
194194
StatusCode: http.StatusMethodNotAllowed,
195195
Body: io.NopCloser(
196-
bytes.NewReader([]byte(
197-
fmt.Sprintf(`{"message": "%s"}`, "Base branch was modified. Review and try the merge again.")))),
196+
bytes.NewReader(
197+
fmt.Appendf(nil, `{"message": "%s"}`, "Base branch was modified. Review and try the merge again."))),
198198
},
199199
),
200200
}
201201
ctx := context.Background()
202-
pullCtx := &pulltest.MockPullContext{MergeStateValue: &pull.MergeState{Closed: false, Mergeable: boolVal(true)}}
202+
pullCtx := &pulltest.MockPullContext{MergeStateValue: &pull.MergeState{Closed: false, Mergeable: new(true)}}
203203

204204
_, retry := attemptMerge(ctx, pullCtx, merger, SquashAndMerge, CommitMessage{})
205205
assert.True(t, retry, "should retry on base branch changed error")

bulldozer/signals.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020
"regexp"
21+
"slices"
2122
"strings"
2223

2324
"github.com/palantir/bulldozer/pull"
@@ -221,10 +222,8 @@ func (signal CommentsSignal) Matches(ctx context.Context, pullCtx pull.Context,
221222
if body == signalComment {
222223
return true, fmt.Sprintf("pull request body is a %s comment: %q", tag, signalComment), nil
223224
}
224-
for _, comment := range comments {
225-
if comment == signalComment {
226-
return true, fmt.Sprintf("pull request has a %s comment: %q", tag, signalComment), nil
227-
}
225+
if slices.Contains(comments, signalComment) {
226+
return true, fmt.Sprintf("pull request has a %s comment: %q", tag, signalComment), nil
228227
}
229228
}
230229

bulldozer/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func UpdatePR(ctx context.Context, pullCtx pull.Context, client *github.Client,
5454

5555
logger.Debug().Msg("Pull request is not up to date, attempting an update")
5656
mergeCommit, _, err := client.Repositories.Merge(ctx, pullCtx.Owner(), pullCtx.Repo(), &github.RepositoryMergeRequest{
57-
Base: github.String(pr.Head.GetRef()),
58-
Head: github.String(baseRef),
57+
Base: new(pr.Head.GetRef()),
58+
Head: new(baseRef),
5959
})
6060
if err != nil {
6161
logger.Error().Err(errors.WithStack(err)).Msg("Update merge failed unexpectedly")

cmd/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package cmd
1616

1717
import (
18-
"io/ioutil"
1918
"os"
2019

2120
"github.com/palantir/bulldozer/server"
@@ -48,7 +47,7 @@ func readServerConfig(cfgFile string) (*server.Config, error) {
4847
}
4948

5049
var bytes []byte
51-
bytes, err = ioutil.ReadFile(cfgFile)
50+
bytes, err = os.ReadFile(cfgFile)
5251
if err != nil {
5352
return nil, errors.Wrapf(err, "failed reading server config file: %s", cfgFile)
5453
}

pull/pull_requests_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func TestGetOpenPullRequestsForSHA(t *testing.T) {
4747
sha := "sha"
4848

4949
pr := &github.PullRequest{
50-
State: github.String("open"),
51-
Head: &github.PullRequestBranch{SHA: github.String(sha)},
50+
State: new("open"),
51+
Head: &github.PullRequestBranch{SHA: new(sha)},
5252
}
5353

5454
mockClient.On("ListPullRequestsWithCommit", ctx, owner, repo, sha, mock.Anything).Return([]*github.PullRequest{pr}, &github.Response{NextPage: 0}, nil)
@@ -69,8 +69,8 @@ func TestListOpenPullRequestsForSHA(t *testing.T) {
6969
sha := "sha"
7070

7171
pr := &github.PullRequest{
72-
State: github.String("open"),
73-
Head: &github.PullRequestBranch{SHA: github.String(sha)},
72+
State: new("open"),
73+
Head: &github.PullRequestBranch{SHA: new(sha)},
7474
}
7575

7676
mockClient.On("List", ctx, owner, repo, mock.Anything).Return([]*github.PullRequest{pr}, &github.Response{NextPage: 0}, nil)
@@ -91,8 +91,8 @@ func TestGetAllPossibleOpenPullRequestsForSHA_FirstMethodReturnsResults(t *testi
9191
sha := "sha"
9292

9393
pr := &github.PullRequest{
94-
State: github.String("open"),
95-
Head: &github.PullRequestBranch{SHA: github.String(sha)},
94+
State: new("open"),
95+
Head: &github.PullRequestBranch{SHA: new(sha)},
9696
}
9797

9898
// Mock the first method to return a valid pull request.
@@ -116,8 +116,8 @@ func TestGetAllPossibleOpenPullRequestsForSHA_SecondMethodReturnsResults(t *test
116116
sha := "sha"
117117

118118
pr := &github.PullRequest{
119-
State: github.String("open"),
120-
Head: &github.PullRequestBranch{SHA: github.String(sha)},
119+
State: new("open"),
120+
Head: &github.PullRequestBranch{SHA: new(sha)},
121121
}
122122

123123
// Mock the first method to return no results.
@@ -178,8 +178,8 @@ func TestListOpenPullRequestsForRef(t *testing.T) {
178178
ref := "refs/heads/main"
179179

180180
pr := &github.PullRequest{
181-
State: github.String("open"),
182-
Base: &github.PullRequestBranch{Ref: github.String("main")},
181+
State: new("open"),
182+
Base: &github.PullRequestBranch{Ref: new("main")},
183183
}
184184

185185
mockClient.On("List", ctx, owner, repo, mock.Anything).Return([]*github.PullRequest{pr}, &github.Response{NextPage: 0}, nil)

server/handler/push.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ func (h *Push) Handle(ctx context.Context, eventType, deliveryID string, payload
4646

4747
// todo: fixup PushEventRepository != Repository
4848
ghRepo := &github.Repository{
49-
Name: github.String(repoName),
49+
Name: new(repoName),
5050
Owner: &github.User{
51-
Login: github.String(owner),
51+
Login: new(owner),
5252
},
5353
}
5454

0 commit comments

Comments
 (0)