Skip to content

Commit 3ab09c4

Browse files
authored
Apply modernizations from 'go fix' (#154)
1 parent 3f6f9e2 commit 3ab09c4

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

applier_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ func assertPatchResult(t *testing.T, tctx *TestContext, name string, c *github.C
123123
}
124124

125125
relpath := filepath.ToSlash(strings.TrimPrefix(path, root))
126-
if strings.HasSuffix(relpath, DeletedExt) {
127-
delete(expected, strings.TrimSuffix(relpath, DeletedExt))
126+
if path, ok := strings.CutSuffix(relpath, DeletedExt); ok {
127+
delete(expected, path)
128128
return nil
129129
}
130130

cmd/patch2pr/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ func execute(ctx context.Context, client *github.Client, patchFiles []string, op
214214
}
215215
}
216216

217-
if strings.HasPrefix(patchBase, "refs/") {
218-
ref, _, err := client.Git.GetRef(ctx, targetRepo.Owner, targetRepo.Name, strings.TrimPrefix(patchBase, "refs/"))
217+
if baseRef, ok := strings.CutPrefix(patchBase, "refs/"); ok {
218+
ref, _, err := client.Git.GetRef(ctx, targetRepo.Owner, targetRepo.Name, baseRef)
219219
if err != nil {
220220
return nil, fmt.Errorf("get ref for patch base %q failed: %w", patchBase, err)
221221
}

cmd/patch2pr/mbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (r *mboxMessageReader) Read(p []byte) (n int, err error) {
7474
}
7575

7676
func (r *mboxMessageReader) scanForHeader(p []byte, n int) int {
77-
for i := 0; i < n; i++ {
77+
for i := range n {
7878
if isSpace(p[i]) {
7979
r.isLineStart = p[i] == '\n'
8080
continue

error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
)
77

8-
func unsupported(msg string, args ...interface{}) error {
8+
func unsupported(msg string, args ...any) error {
99
return unsupportedErr{reason: fmt.Sprintf(msg, args...)}
1010
}
1111

graphql_applier.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (a *GraphQLApplier) getContent(ctx context.Context, filePath string) ([]byt
200200
} `graphql:"object(expression: $expr)"`
201201
} `graphql:"repository(owner: $owner, name: $name)"`
202202
}
203-
vars := map[string]interface{}{
203+
vars := map[string]any{
204204
"owner": githubv4.String(a.owner),
205205
"name": githubv4.String(a.repo),
206206
"expr": githubv4.String(fmt.Sprintf("%s:%s", a.commit, filePath)),
@@ -249,7 +249,7 @@ func (a *GraphQLApplier) getMode(ctx context.Context, filePath string) (os.FileM
249249
} `graphql:"object(expression: $expr)"`
250250
} `graphql:"repository(owner: $owner, name: $name)"`
251251
}
252-
vars := map[string]interface{}{
252+
vars := map[string]any{
253253
"owner": githubv4.String(a.owner),
254254
"name": githubv4.String(a.repo),
255255
"expr": githubv4.String(fmt.Sprintf("%s:%s", a.commit, treePath(filePath))),

0 commit comments

Comments
 (0)