diff --git a/go.mod b/go.mod index 62dc59b5d6f..71a6a96b139 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/goark/go-cvss v1.6.6 github.com/golang/protobuf v1.5.3 github.com/google/go-containerregistry v0.16.1 - github.com/google/go-github/v53 v53.2.0 + github.com/google/go-github/v56 v56.0.0 github.com/google/safetext v0.0.0-20230106111101-7156a760e523 github.com/google/uuid v1.4.0 github.com/hashicorp/go-multierror v1.1.1 @@ -41,7 +41,7 @@ require ( sigs.k8s.io/bom v0.5.2-0.20230519223618-1ebaa9ce375f sigs.k8s.io/mdtoc v1.1.0 sigs.k8s.io/promo-tools/v3 v3.6.0 - sigs.k8s.io/release-sdk v0.10.3 + sigs.k8s.io/release-sdk v0.10.4 sigs.k8s.io/release-utils v0.7.7 sigs.k8s.io/yaml v1.4.0 ) diff --git a/go.sum b/go.sum index a93c1bf8a4c..8b8501bd98f 100644 --- a/go.sum +++ b/go.sum @@ -551,10 +551,10 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-containerregistry v0.16.1 h1:rUEt426sR6nyrL3gt+18ibRcvYpKYdpsa5ZW7MA08dQ= github.com/google/go-containerregistry v0.16.1/go.mod h1:u0qB2l7mvtWVR5kNcbFIhFY1hLbf8eeGapA+vbFDCtQ= -github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/XUvTtI= -github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao= github.com/google/go-github/v55 v55.0.0 h1:4pp/1tNMB9X/LuAhs5i0KQAE40NmiR/y6prLNb9x9cg= github.com/google/go-github/v55 v55.0.0/go.mod h1:JLahOTA1DnXzhxEymmFF5PP2tSS9JVNj68mSZNDwskA= +github.com/google/go-github/v56 v56.0.0 h1:TysL7dMa/r7wsQi44BjqlwaHvwlFlqkK8CtBWCX3gb4= +github.com/google/go-github/v56 v56.0.0/go.mod h1:D8cdcX98YWJvi7TLo7zM4/h8ZTx6u6fwGEkCdisopo0= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -1575,8 +1575,8 @@ sigs.k8s.io/mdtoc v1.1.0 h1:q3YtqYzmC2e0hgLXRIOm7/QLuPux1CX3ZHCwlbABxZo= sigs.k8s.io/mdtoc v1.1.0/go.mod h1:QZLVEdHH2iNIR4uHAZyvFRtjloHgVItk8lo/mzCtq3w= sigs.k8s.io/promo-tools/v3 v3.6.0 h1:C2L08ezrWm1aZI8Emd3iZPZQserLPRgzuqQVxvI0PUI= sigs.k8s.io/promo-tools/v3 v3.6.0/go.mod h1:XJ3jy0hJYs+hWKt8XsLHFzGQV8PUtvllvbxjN/E5RXI= -sigs.k8s.io/release-sdk v0.10.3 h1:OUDWndR0jXex7w1g/y2TI2TDmzJB0u1AFH4U8he/WAE= -sigs.k8s.io/release-sdk v0.10.3/go.mod h1:EBZWXznKbtE6XHsdsB5lx+eGCv4gW+TuHJmnev7i//8= +sigs.k8s.io/release-sdk v0.10.4 h1:Ji75SfmHXTaZUUKteCUWEIHKJkOk8H0uxTuRdEnbBQU= +sigs.k8s.io/release-sdk v0.10.4/go.mod h1:H9TsZQFDpdAmViPe69C4OkP8vlOPZ0YUmf1dqUNiqZ4= sigs.k8s.io/release-utils v0.7.7 h1:JKDOvhCk6zW8ipEOkpTGDH/mW3TI+XqtPp16aaQ79FU= sigs.k8s.io/release-utils v0.7.7/go.mod h1:iU7DGVNi3umZJ8q6aHyUFzsDUIaYwNnNKGHo3YE5E3s= sigs.k8s.io/structured-merge-diff/v4 v4.3.0 h1:UZbZAZfX0wV2zr7YZorDz6GXROfDFj6LvqCRm4VUVKk= diff --git a/pkg/fastforward/fastforward_test.go b/pkg/fastforward/fastforward_test.go index 2235c46ead3..3d1e7c801f3 100644 --- a/pkg/fastforward/fastforward_test.go +++ b/pkg/fastforward/fastforward_test.go @@ -22,7 +22,7 @@ import ( "strings" "testing" - gogithub "github.com/google/go-github/v53/github" + gogithub "github.com/google/go-github/v56/github" "github.com/stretchr/testify/require" "k8s.io/release/pkg/fastforward/fastforwardfakes" ) diff --git a/pkg/fastforward/fastforwardfakes/fake_impl.go b/pkg/fastforward/fastforwardfakes/fake_impl.go index 1e210eaf709..bfd89446ded 100644 --- a/pkg/fastforward/fastforwardfakes/fake_impl.go +++ b/pkg/fastforward/fastforwardfakes/fake_impl.go @@ -20,7 +20,7 @@ package fastforwardfakes import ( "sync" - "github.com/google/go-github/v53/github" + "github.com/google/go-github/v56/github" "k8s.io/release/pkg/gcp/gcb" "sigs.k8s.io/release-sdk/git" ) diff --git a/pkg/fastforward/impl.go b/pkg/fastforward/impl.go index 916cf452365..cba4260520a 100644 --- a/pkg/fastforward/impl.go +++ b/pkg/fastforward/impl.go @@ -22,7 +22,7 @@ import ( "k8s.io/release/pkg/gcp/gcb" "k8s.io/release/pkg/release" - gogithub "github.com/google/go-github/v53/github" + gogithub "github.com/google/go-github/v56/github" "sigs.k8s.io/release-sdk/git" "sigs.k8s.io/release-sdk/github" "sigs.k8s.io/release-utils/env" diff --git a/pkg/notes/notes.go b/pkg/notes/notes.go index 70fb165bebe..e388113bafd 100644 --- a/pkg/notes/notes.go +++ b/pkg/notes/notes.go @@ -35,7 +35,7 @@ import ( "time" "unicode" - gogithub "github.com/google/go-github/v53/github" + gogithub "github.com/google/go-github/v56/github" "github.com/nozzle/throttler" "github.com/sirupsen/logrus" "golang.org/x/text/cases" @@ -911,12 +911,9 @@ func canWaitAndRetry(r *gogithub.Response, err error) bool { // prsForCommitFromSHA retrieves the PR numbers for a commit given its sha func (g *Gatherer) prsForCommitFromSHA(sha string) (prs []*gogithub.PullRequest, err error) { - plo := &gogithub.PullRequestListOptions{ - State: "closed", - ListOptions: gogithub.ListOptions{ - Page: 1, - PerPage: 100, - }, + plo := &gogithub.ListOptions{ + Page: 1, + PerPage: 100, } prs = []*gogithub.PullRequest{} @@ -936,12 +933,18 @@ func (g *Gatherer) prsForCommitFromSHA(sha string) (prs []*gogithub.PullRequest, break } } - prs = append(prs, pResult...) + + for _, result := range pResult { + if result.GetState() == "closed" { + prs = append(prs, result) + } + } + if resp.NextPage == 0 { break } - plo.ListOptions.Page++ - if plo.ListOptions.Page > resp.LastPage { + plo.Page++ + if plo.Page > resp.LastPage { break } } diff --git a/pkg/notes/notes_gatherer_test.go b/pkg/notes/notes_gatherer_test.go index 1a4f8c5ed93..75c8e026c9f 100644 --- a/pkg/notes/notes_gatherer_test.go +++ b/pkg/notes/notes_gatherer_test.go @@ -27,7 +27,7 @@ import ( "sync/atomic" "testing" - "github.com/google/go-github/v53/github" + "github.com/google/go-github/v56/github" "github.com/sirupsen/logrus" "sigs.k8s.io/release-sdk/git" "sigs.k8s.io/release-sdk/github/githubfakes" @@ -235,7 +235,7 @@ func TestListCommits(t *testing.T) { func TestGatherNotes(t *testing.T) { type getPullRequestStub func(context.Context, string, string, int) (*github.PullRequest, *github.Response, error) - type listPullRequestsWithCommitStub func(context.Context, string, string, string, *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error) + type listPullRequestsWithCommitStub func(context.Context, string, string, string, *github.ListOptions) ([]*github.PullRequest, *github.Response, error) tests := map[string]struct { // listPullRequestsWithCommitStubber is a function that needs to return @@ -276,7 +276,7 @@ func TestGatherNotes(t *testing.T) { repoCommit("some-random-sha", "some-random-commit-msg"), }, listPullRequestsWithCommitStubber: func(t *testing.T) listPullRequestsWithCommitStub { - return func(_ context.Context, org, repo, sha string, _ *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error) { + return func(_ context.Context, org, repo, sha string, _ *github.ListOptions) ([]*github.PullRequest, *github.Response, error) { checkOrgRepo(t, org, repo) if e, a := "some-random-sha", sha; e != a { t.Errorf("Expected ListPullRequestsWithCommit(...) to be called for SHA '%s', have been called for '%s'", e, a) @@ -312,7 +312,7 @@ func TestGatherNotes(t *testing.T) { "when GetPullRequest(...) returns an error": { commitList: []*github.RepositoryCommit{repoCommit("some-sha", "some #123 thing")}, listPullRequestsWithCommitStubber: func(t *testing.T) listPullRequestsWithCommitStub { - return func(_ context.Context, _, _, _ string, _ *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error) { + return func(_ context.Context, _, _, _ string, _ *github.ListOptions) ([]*github.PullRequest, *github.Response, error) { return nil, nil, fmt.Errorf("some-error-from-get-pull-request") } }, @@ -322,7 +322,7 @@ func TestGatherNotes(t *testing.T) { "when ListPullRequestsWithCommit(...) returns an error": { commitList: []*github.RepositoryCommit{repoCommit("some-sha", "some-msg")}, listPullRequestsWithCommitStubber: func(t *testing.T) listPullRequestsWithCommitStub { - return func(_ context.Context, _, _, _ string, _ *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error) { + return func(_ context.Context, _, _, _ string, _ *github.ListOptions) ([]*github.PullRequest, *github.Response, error) { return nil, nil, fmt.Errorf("some-error-from-list-pull-requests-with-commit") } }, @@ -334,27 +334,28 @@ func TestGatherNotes(t *testing.T) { listPullRequestsWithCommitStubber: func(t *testing.T) listPullRequestsWithCommitStub { prsPerCall := [][]*github.PullRequest{ // explicitly excluded - {pullRequest(1, "something ```release-note\nN/a\n``` something")}, - {pullRequest(2, "something ```release-note\nNa\n``` something")}, - {pullRequest(3, "something ```release-note\nNone \n``` something")}, - {pullRequest(4, "something ```release-note\n'None' \n``` something")}, - {pullRequest(5, "something /release-note-none something")}, + {pullRequest(1, "something ```release-note\nN/a\n``` something", "closed")}, + {pullRequest(2, "something ```release-note\nNa\n``` something", "closed")}, + {pullRequest(3, "something ```release-note\nNone \n``` something", "closed")}, + {pullRequest(4, "something ```release-note\n'None' \n``` something", "closed")}, + {pullRequest(5, "something /release-note-none something", "closed")}, // multiple PRs { // first does no match, second one matches, rest is ignored - pullRequest(6, ""), - pullRequest(7, " something ```release-note\nTest\n``` something"), - pullRequest(8, "does-not-matter--is-not-considered"), + pullRequest(6, "", "closed"), + pullRequest(7, " something ```release-note\nTest\n``` something", "closed"), + pullRequest(8, "does-not-matter--is-not-considered", "closed"), }, // some other strange things - {pullRequest(9, "release-note /release-note-none")}, // excluded, the exclusion filters take precedence - {pullRequest(10, "```release-note\nNAAAAAAAAAA\n```")}, // included, does not match the N/A filter, but the 'release-note' check - {pullRequest(11, "```release-note\nnone something\n```")}, // included, does not match the N/A filter, but the 'release-note' check + {pullRequest(9, "release-note /release-note-none", "closed")}, // excluded, the exclusion filters take precedence + {pullRequest(10, "```release-note\nNAAAAAAAAAA\n```", "closed")}, // included, does not match the N/A filter, but the 'release-note' check + {pullRequest(11, "```release-note\nnone something\n```", "closed")}, // included, does not match the N/A filter, but the 'release-note' check // empty release note block shouldn't be matched - {pullRequest(12, "```release-note\n\n```")}, + {pullRequest(12, "```release-note\n\n```", "closed")}, + {pullRequest(13, "```release-note\n\n```", "open")}, } var callCount int64 = -1 - return func(_ context.Context, _, _, _ string, _ *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error) { + return func(_ context.Context, _, _, _ string, _ *github.ListOptions) ([]*github.PullRequest, *github.Response, error) { callCount := int(atomic.AddInt64(&callCount, 1)) if a, e := callCount+1, len(prsPerCall); a > e { return nil, &github.Response{}, nil @@ -407,10 +408,11 @@ func TestGatherNotes(t *testing.T) { } } -func pullRequest(id int, msg string) *github.PullRequest { +func pullRequest(id int, msg, state string) *github.PullRequest { return &github.PullRequest{ Body: strPtr(msg), Number: intPtr(id), + State: strPtr(state), } }