Skip to content

Commit 7ccc6b6

Browse files
Add pagination support to GraphQL-based tools (#683)
* initial pagination for `ListDiscussions` * redo category id var cast * add GraphQL pagination support for discussion comments and categories * remove pageinfo returns * fix out ref for linter * update docs * move to unified pagination for consensus on params * update docs * refactor pagination handling * update docs * linter fix * conv rest to gql params for safe lint * add nolint * add error handling for perPage value in ToGraphQLParams * refactor pagination error handling * unified params for rest andn graphql and rennamed to be uniform for golang * add 'after' for pagination * update docs * Update pkg/github/discussions.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update pkg/github/discussions.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update pkg/github/discussions_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * update default page size const * reduce default pagination size from 100 to 30 in discussion tests * update pagination for reverse and total * update pagination to remove from discussions * updated README * improve the `ToGraphQLParams` function --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 7496452 commit 7ccc6b6

File tree

12 files changed

+430
-201
lines changed

12 files changed

+430
-201
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,21 +449,21 @@ The following sets of tools are available (all are on by default):
449449
- `repo`: Repository name (string, required)
450450

451451
- **get_discussion_comments** - Get discussion comments
452+
- `after`: Cursor for pagination. Use the endCursor from the previous page's PageInfo for GraphQL APIs. (string, optional)
452453
- `discussionNumber`: Discussion Number (number, required)
453454
- `owner`: Repository owner (string, required)
455+
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
454456
- `repo`: Repository name (string, required)
455457

456458
- **list_discussion_categories** - List discussion categories
457-
- `after`: Cursor for pagination, use the 'after' field from the previous response (string, optional)
458-
- `before`: Cursor for pagination, use the 'before' field from the previous response (string, optional)
459-
- `first`: Number of categories to return per page (min 1, max 100) (number, optional)
460-
- `last`: Number of categories to return from the end (min 1, max 100) (number, optional)
461459
- `owner`: Repository owner (string, required)
462460
- `repo`: Repository name (string, required)
463461

464462
- **list_discussions** - List discussions
463+
- `after`: Cursor for pagination. Use the endCursor from the previous page's PageInfo for GraphQL APIs. (string, optional)
465464
- `category`: Optional filter by discussion category ID. If provided, only discussions with this category are listed. (string, optional)
466465
- `owner`: Repository owner (string, required)
466+
- `perPage`: Results per page for pagination (min 1, max 100) (number, optional)
467467
- `repo`: Repository name (string, required)
468468

469469
</details>

pkg/github/actions.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ func ListWorkflows(getClient GetClientFn, t translations.TranslationHelperFunc)
6262

6363
// Set up list options
6464
opts := &github.ListOptions{
65-
PerPage: pagination.perPage,
66-
Page: pagination.page,
65+
PerPage: pagination.PerPage,
66+
Page: pagination.Page,
6767
}
6868

6969
workflows, resp, err := client.Actions.ListWorkflows(ctx, owner, repo, opts)
@@ -200,8 +200,8 @@ func ListWorkflowRuns(getClient GetClientFn, t translations.TranslationHelperFun
200200
Event: event,
201201
Status: status,
202202
ListOptions: github.ListOptions{
203-
PerPage: pagination.perPage,
204-
Page: pagination.page,
203+
PerPage: pagination.PerPage,
204+
Page: pagination.Page,
205205
},
206206
}
207207

@@ -503,8 +503,8 @@ func ListWorkflowJobs(getClient GetClientFn, t translations.TranslationHelperFun
503503
opts := &github.ListWorkflowJobsOptions{
504504
Filter: filter,
505505
ListOptions: github.ListOptions{
506-
PerPage: pagination.perPage,
507-
Page: pagination.page,
506+
PerPage: pagination.PerPage,
507+
Page: pagination.Page,
508508
},
509509
}
510510

@@ -1025,8 +1025,8 @@ func ListWorkflowRunArtifacts(getClient GetClientFn, t translations.TranslationH
10251025

10261026
// Set up list options
10271027
opts := &github.ListOptions{
1028-
PerPage: pagination.perPage,
1029-
Page: pagination.page,
1028+
PerPage: pagination.PerPage,
1029+
Page: pagination.Page,
10301030
}
10311031

10321032
artifacts, resp, err := client.Actions.ListWorkflowRunArtifacts(ctx, owner, repo, runID, opts)

0 commit comments

Comments
 (0)