@@ -185,20 +185,23 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
185185 }
186186
187187 query := fragments + `
188- query($owner: String!, $repo: String!, $limit: Int, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) {
189- repository(owner: $owner, name: $repo) {
190- hasIssuesEnabled
191- issues(first: $limit, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee}) {
192- nodes {
193- ...issue
194- }
195- }
196- }
197- }
198- `
188+ query($owner: String!, $repo: String!, $limit: Int, $endCursor: String, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) {
189+ repository(owner: $owner, name: $repo) {
190+ hasIssuesEnabled
191+ issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee}) {
192+ nodes {
193+ ...issue
194+ }
195+ pageInfo {
196+ hasNextPage
197+ endCursor
198+ }
199+ }
200+ }
201+ }
202+ `
199203
200204 variables := map [string ]interface {}{
201- "limit" : limit ,
202205 "owner" : repo .RepoOwner (),
203206 "repo" : repo .RepoName (),
204207 "states" : states ,
@@ -210,25 +213,49 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
210213 variables ["assignee" ] = assigneeString
211214 }
212215
213- var resp struct {
216+ var response struct {
214217 Repository struct {
215218 Issues struct {
216- Nodes []Issue
219+ Nodes []Issue
220+ PageInfo struct {
221+ HasNextPage bool
222+ EndCursor string
223+ }
217224 }
218225 HasIssuesEnabled bool
219226 }
220227 }
221228
222- err := client .GraphQL (query , variables , & resp )
223- if err != nil {
224- return nil , err
225- }
229+ var issues []Issue
230+ pageLimit := min (limit , 100 )
226231
227- if ! resp .Repository .HasIssuesEnabled {
228- return nil , fmt .Errorf ("the '%s' repository has disabled issues" , ghrepo .FullName (repo ))
232+ loop:
233+ for {
234+ variables ["limit" ] = pageLimit
235+ err := client .GraphQL (query , variables , & response )
236+ if err != nil {
237+ return nil , err
238+ }
239+ if ! response .Repository .HasIssuesEnabled {
240+ return nil , fmt .Errorf ("the '%s' repository has disabled issues" , ghrepo .FullName (repo ))
241+ }
242+
243+ for _ , issue := range response .Repository .Issues .Nodes {
244+ issues = append (issues , issue )
245+ if len (issues ) == limit {
246+ break loop
247+ }
248+ }
249+
250+ if response .Repository .Issues .PageInfo .HasNextPage {
251+ variables ["endCursor" ] = response .Repository .Issues .PageInfo .EndCursor
252+ pageLimit = min (pageLimit , limit - len (issues ))
253+ } else {
254+ break
255+ }
229256 }
230257
231- return resp . Repository . Issues . Nodes , nil
258+ return issues , nil
232259}
233260
234261func IssueByNumber (client * Client , repo ghrepo.Interface , number int ) (* Issue , error ) {
0 commit comments