Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions applier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/patch2pr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions graphql_applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/base64"
"fmt"
"io/ioutil"
"io"
"os"
"path"

Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading