From f9f301ed28d3ec65e4899a34c9553f8f3f2cfc74 Mon Sep 17 00:00:00 2001 From: Billy Keyes Date: Sat, 27 Jun 2026 12:15:26 -0400 Subject: [PATCH] Apply modernizations from 'go fix' Also manually replace usage of 'ioutil', since this wasn't automatically converted for some reason. --- applier.go | 23 +++++++++++------------ applier_test.go | 8 ++++---- cmd/patch2pr/main.go | 5 ++--- graphql_applier.go | 4 ++-- reference.go | 2 +- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/applier.go b/applier.go index 08d093f..27f93df 100644 --- a/applier.go +++ b/applier.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "strconv" "strings" "time" @@ -77,7 +76,7 @@ func (a *Applier) Apply(ctx context.Context, f *gitdiff.File) (*github.TreeEntry if entry.Content != nil { blob, _, err := a.client.Git.CreateBlob(ctx, a.owner, a.repo, github.Blob{ Content: entry.Content, - Encoding: github.String("base64"), + Encoding: github.Ptr("base64"), }) if err != nil { return nil, fmt.Errorf("create blob failed: %w", err) @@ -106,8 +105,8 @@ func (a *Applier) applyCreate(ctx context.Context, f *gitdiff.File) (*github.Tre path := f.NewName newEntry := &github.TreeEntry{ Path: &path, - Mode: github.String(getMode(f, nil)), - Type: github.String("blob"), + Mode: github.Ptr(getMode(f, nil)), + Type: github.Ptr("blob"), Content: &c, } a.entries[path] = newEntry @@ -131,7 +130,7 @@ func (a *Applier) applyDelete(ctx context.Context, f *gitdiff.File) (*github.Tre return nil, fmt.Errorf("get blob content failed: %w", err) } - if err := apply(ioutil.Discard, bytes.NewReader(data), f.OldName, f); err != nil { + if err := apply(io.Discard, bytes.NewReader(data), f.OldName, f); err != nil { return nil, err } @@ -157,8 +156,8 @@ func (a *Applier) applyModify(ctx context.Context, f *gitdiff.File) (*github.Tre path := f.NewName newEntry := &github.TreeEntry{ Path: &path, - Mode: github.String(getMode(f, entry)), - Type: github.String("blob"), + Mode: github.Ptr(getMode(f, entry)), + Type: github.Ptr("blob"), } if len(f.TextFragments) > 0 || f.BinaryFragment != nil { @@ -251,19 +250,19 @@ func (a *Applier) Commit(ctx context.Context, tmpl *github.Commit, header *gitdi } c.Tree = &github.Tree{ - SHA: github.String(a.tree), + SHA: github.Ptr(a.tree), } c.Parents = []*github.Commit{ a.commit, } if header != nil { - c.Message = github.String(header.Message()) + c.Message = github.Ptr(header.Message()) c.Author = makeCommitAuthor(header.Author, header.AuthorDate) c.Committer = makeCommitAuthor(header.Committer, header.CommitterDate) } if c.Message == nil || *c.Message == "" { - c.Message = github.String("Apply patch with patch2pr") + c.Message = github.Ptr("Apply patch with patch2pr") } commit, _, err := a.client.Git.CreateCommit(ctx, a.owner, a.repo, c, nil) @@ -400,10 +399,10 @@ func makeCommitAuthor(id *gitdiff.PatchIdentity, d time.Time) *github.CommitAuth a := &github.CommitAuthor{} if id != nil { if id.Name != "" { - a.Name = github.String(id.Name) + a.Name = github.Ptr(id.Name) } if id.Email != "" { - a.Email = github.String(id.Email) + a.Email = github.Ptr(id.Email) } } if !d.IsZero() { diff --git a/applier_test.go b/applier_test.go index 775abdb..d4fe5c6 100644 --- a/applier_test.go +++ b/applier_test.go @@ -278,14 +278,14 @@ func createBranch(t *testing.T, tctx *TestContext) { treePath := strings.TrimPrefix(path, root) entry := github.TreeEntry{ Path: &treePath, - Type: github.String("blob"), - Mode: github.String(getGitMode(info)), + Type: github.Ptr("blob"), + Mode: github.Ptr(getGitMode(info)), } if strings.HasSuffix(d.Name(), ".bin") { c := base64.StdEncoding.EncodeToString(content) blob, _, err := tctx.Client.Git.CreateBlob(tctx, tctx.Repo.Owner, tctx.Repo.Name, github.Blob{ - Encoding: github.String("base64"), + Encoding: github.Ptr("base64"), Content: &c, }) if err != nil { @@ -314,7 +314,7 @@ func createBranch(t *testing.T, tctx *TestContext) { } commitToCreate := github.Commit{ - Message: github.String("Base commit for test"), + Message: github.Ptr("Base commit for test"), Tree: tree, } diff --git a/cmd/patch2pr/main.go b/cmd/patch2pr/main.go index 025f788..a979378 100644 --- a/cmd/patch2pr/main.go +++ b/cmd/patch2pr/main.go @@ -8,7 +8,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "net/http" "os" "strings" @@ -63,7 +62,7 @@ func main() { var opts Options fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) - fs.SetOutput(ioutil.Discard) + fs.SetOutput(io.Discard) fs.Usage = func() {} fs.StringVar(&opts.BaseBranch, "base-branch", "", "base-branch") @@ -299,7 +298,7 @@ func execute(ctx context.Context, client *github.Client, patchFiles []string, op if sourceRepo == targetRepo { prSpec.Head = &headBranch } else { - prSpec.Head = github.String(fmt.Sprintf("%s:%s", sourceRepo.Owner, headBranch)) + prSpec.Head = github.Ptr(fmt.Sprintf("%s:%s", sourceRepo.Owner, headBranch)) prSpec.HeadRepo = &sourceRepo.Name } diff --git a/graphql_applier.go b/graphql_applier.go index 6d1a17d..abd1d9a 100644 --- a/graphql_applier.go +++ b/graphql_applier.go @@ -5,7 +5,7 @@ import ( "context" "encoding/base64" "fmt" - "io/ioutil" + "io" "os" "path" @@ -148,7 +148,7 @@ func (a *GraphQLApplier) applyDelete(ctx context.Context, f *gitdiff.File) error return &Conflict{Type: ConflictDeletedFileMissing, File: f.OldName} } - if err := apply(ioutil.Discard, bytes.NewReader(data), f.OldName, f); err != nil { + if err := apply(io.Discard, bytes.NewReader(data), f.OldName, f); err != nil { return err } diff --git a/reference.go b/reference.go index dbc0813..5522202 100644 --- a/reference.go +++ b/reference.go @@ -75,7 +75,7 @@ func (r *Reference) PullRequest(ctx context.Context, spec *github.NewPullRequest } specCopy := *spec - specCopy.Head = github.String(strings.TrimPrefix(r.ref, "refs/heads/")) + specCopy.Head = github.Ptr(strings.TrimPrefix(r.ref, "refs/heads/")) pr, _, err := r.client.PullRequests.Create(ctx, r.owner, r.repo, &specCopy) if err != nil {