diff --git a/.golangci.yml b/.golangci.yml index adbb8a0c4d6..71bac87e79b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -287,11 +287,11 @@ linters: - IssueListByRepoOptions.Sort # TODO: Issues - IssueListByRepoOptions.Sort # TODO: Issues - IssueListByRepoOptions.State # TODO: Issues - - IssueListOptions.Direction # TODO: Issues - - IssueListOptions.Filter # TODO: Issues - - IssueListOptions.Since # TODO: Issues - - IssueListOptions.Sort # TODO: Issues - - IssueListOptions.State # TODO: Issues + - IssueListOptions.Direction # TODO: Issues + - IssueListOptions.Filter # TODO: Issues + - IssueListOptions.Since # TODO: Issues + - IssueListOptions.Sort # TODO: Issues + - IssueListOptions.State # TODO: Issues - IssueRequest.Assignees # TODO: Issues - IssueRequest.Labels # TODO: Issues - License.Conditions # TODO: Licenses diff --git a/github/github-iterators.go b/github/github-iterators.go index b1f330da02d..90a057e63d2 100644 --- a/github/github-iterators.go +++ b/github/github-iterators.go @@ -1312,10 +1312,9 @@ func (s *IssuesService) ListIter(ctx context.Context, all bool, opts *IssueListO } } - if resp.Cursor == "" && resp.NextPage == 0 { + if resp.NextPage == 0 { break } - opts.ListCursorOptions.Cursor = resp.Cursor opts.ListOptions.Page = resp.NextPage } } @@ -1375,10 +1374,9 @@ func (s *IssuesService) ListByOrgIter(ctx context.Context, org string, opts *Iss } } - if resp.Cursor == "" && resp.NextPage == 0 { + if resp.NextPage == 0 { break } - opts.ListCursorOptions.Cursor = resp.Cursor opts.ListOptions.Page = resp.NextPage } } @@ -3767,10 +3765,9 @@ func (s *SubIssueService) ListByIssueIter(ctx context.Context, owner string, rep } } - if resp.Cursor == "" && resp.NextPage == 0 { + if resp.NextPage == 0 { break } - opts.ListCursorOptions.Cursor = resp.Cursor opts.ListOptions.Page = resp.NextPage } } diff --git a/github/github-iterators_test.go b/github/github-iterators_test.go index 73289af8eea..85a0bca6431 100644 --- a/github/github-iterators_test.go +++ b/github/github-iterators_test.go @@ -2975,7 +2975,7 @@ func TestIssuesService_ListIter(t *testing.T) { callNum++ switch callNum { case 1: - w.Header().Set("Link", `; rel="next"`) + w.Header().Set("Link", `; rel="next"`) fmt.Fprint(w, `[{},{},{}]`) case 2: fmt.Fprint(w, `[{},{},{},{}]`) @@ -3119,7 +3119,7 @@ func TestIssuesService_ListByOrgIter(t *testing.T) { callNum++ switch callNum { case 1: - w.Header().Set("Link", `; rel="next"`) + w.Header().Set("Link", `; rel="next"`) fmt.Fprint(w, `[{},{},{}]`) case 2: fmt.Fprint(w, `[{},{},{},{}]`) @@ -8663,7 +8663,7 @@ func TestSubIssueService_ListByIssueIter(t *testing.T) { callNum++ switch callNum { case 1: - w.Header().Set("Link", `; rel="next"`) + w.Header().Set("Link", `; rel="next"`) fmt.Fprint(w, `[{},{},{}]`) case 2: fmt.Fprint(w, `[{},{},{},{}]`) diff --git a/github/issues.go b/github/issues.go index 861c3fa5f90..95cb13582a4 100644 --- a/github/issues.go +++ b/github/issues.go @@ -125,10 +125,7 @@ type IssueListOptions struct { // Since filters issues by time. Since time.Time `url:"since,omitempty"` - ListCursorOptions - // Add ListOptions so offset pagination with integer type "page" query parameter is accepted - // since ListCursorOptions accepts "page" as string only. ListOptions } @@ -245,6 +242,7 @@ type IssueListByRepoOptions struct { // Since filters issues by time. Since time.Time `url:"since,omitempty"` + // ListCursorOptions specifies the optional parameters for cursor pagination. ListCursorOptions // Add ListOptions so offset pagination with integer type "page" query parameter is accepted diff --git a/github/issues_test.go b/github/issues_test.go index 53fe46aa81d..04cdb1c05ad 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -28,22 +28,21 @@ func TestIssuesService_List_all(t *testing.T) { "labels": "a,b", "sort": "updated", "direction": "asc", - "since": "2002-02-10T15:30:00Z", + "since": referenceTime.Format(time.RFC3339), "page": "1", "per_page": "2", - "before": "foo", - "after": "bar", }) fmt.Fprint(w, `[{"number":1}]`) }) opt := &IssueListOptions{ - "all", "closed", - []string{"a", "b"}, - "updated", "asc", - time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), - ListCursorOptions{Before: "foo", After: "bar"}, - ListOptions{Page: 1, PerPage: 2}, + Filter: "all", + State: "closed", + Labels: []string{"a", "b"}, + Sort: "updated", + Direction: "asc", + Since: referenceTime, + ListOptions: ListOptions{Page: 1, PerPage: 2}, } ctx := t.Context() issues, _, err := client.Issues.List(ctx, true, opt) @@ -158,22 +157,26 @@ func TestIssuesService_ListByRepo(t *testing.T) { "labels": "a,b", "sort": "updated", "direction": "asc", - "since": "2002-02-10T15:30:00Z", + "since": referenceTime.Format(time.RFC3339), "per_page": "1", - "before": "foo", - "after": "bar", }) fmt.Fprint(w, `[{"number":1}]`) }) + // IssueListByRepoOptions uses standard strings (not pointers) and ListCursorOptions opt := &IssueListByRepoOptions{ - "*", "closed", "a", "c", "m", - []string{"a", "b"}, - "updated", "asc", - time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), - ListCursorOptions{PerPage: 1, Before: "foo", After: "bar"}, - ListOptions{0, 0}, + Milestone: "*", + State: "closed", + Assignee: "a", + Creator: "c", + Mentioned: "m", + Labels: []string{"a", "b"}, + Sort: "updated", + Direction: "asc", + Since: referenceTime, + ListCursorOptions: ListCursorOptions{PerPage: 1}, } + ctx := t.Context() issues, _, err := client.Issues.ListByRepo(ctx, "o", "r", opt) if err != nil {