Skip to content

Iterator generation issues caused by incorrect or unsupported pagination options #3976

@Not-Dhananjay-Mishra

Description

@Not-Dhananjay-Mishra

While trying new Iter when i run client.Users.ListAllIter it went into infinite loop, I found out that client.Users.ListAll doesn't support Page based pagination. so i decide to find if there exist more functions with similar or some sort of problems.

Here are my findings -


  1. UsersService.ListAll don't have page acc to docs if you run ListAllIter it will go in infinite loop since its pagination is powered exclusively by the since parameter.

    go-github/github/users.go

    Lines 224 to 227 in c8fd3f7

    // GitHub API docs: https://docs.github.com/rest/users/users#list-users
    //
    //meta:operation GET /users
    func (s *UsersService) ListAll(ctx context.Context, opts *UserListOptions) ([]*User, *Response, error) {

    Solution : Replacing UserListOptions.ListOptions with UserListOptions.PerPage which will also result in removal of ListAllIter

  1. PackageGetAllVersions handles two endpoints one of them doesn't support pagination acc to docs also for some reason it's Iter dosen't generated maybe because it dose not contain List as prefix.
    // PackageGetAllVersions gets all versions of a package for a user. Passing the empty string for "user" will
    // get versions for the authenticated user.
    //
    // GitHub API docs: https://docs.github.com/rest/packages/packages#list-package-versions-for-a-package-owned-by-a-user
    //
    // GitHub API docs: https://docs.github.com/rest/packages/packages#list-package-versions-for-a-package-owned-by-the-authenticated-user
    //
    //meta:operation GET /user/packages/{package_type}/{package_name}/versions
    //meta:operation GET /users/{username}/packages/{package_type}/{package_name}/versions
    func (s *UsersService) PackageGetAllVersions(ctx context.Context, user, packageType, packageName string, opts *PackageListOptions) ([]*PackageVersion, *Response, error) {

    Solution : Dividing PackageGetAllVersions into two separate functions, if Iter is required then add List to prefix of new function

  1. SubIssueService.ListByIssue dosen't support cursor based pagination acc to docs
    // GitHub API docs: https://docs.github.com/rest/issues/sub-issues#list-sub-issues
    //
    //meta:operation GET /repos/{owner}/{repo}/issues/{issue_number}/sub_issues
    func (s *SubIssueService) ListByIssue(ctx context.Context, owner, repo string, issueNumber int64, opts *IssueListOptions) ([]*SubIssue, *Response, error) {

    Solution : Remove IssueListOptions.ListCursorOptions

  1. RepositoriesService.ListAllTopics also support pagination acc to docs.

    go-github/github/repos.go

    Lines 1928 to 1931 in c8fd3f7

    // GitHub API docs: https://docs.github.com/rest/repos/repos#get-all-repository-topics
    //
    //meta:operation GET /repos/{owner}/{repo}/topics
    func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo string) ([]string, *Response, error) {

    Solution : Add ListOptions

  1. RepositoriesService.ListCustomDeploymentRuleIntegrations also support pagination acc to docs.
    btw its Iter will not generate because it doesn't return []*T kind of result
    // GitHub API docs: https://docs.github.com/rest/deployments/protection-rules#list-custom-deployment-rule-integrations-available-for-an-environment
    //
    //meta:operation GET /repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules/apps
    func (s *RepositoriesService) ListCustomDeploymentRuleIntegrations(ctx context.Context, owner, repo, environment string) (*ListCustomDeploymentRuleIntegrationsResponse, *Response, error) {

    Solution : Add ListOptions

  1. RepositoriesService.ListDeploymentBranchPolicies also support pagination acc to docs.
    btw its Iter will not generate because it doesn't return []*T kind of result
    // GitHub API docs: https://docs.github.com/rest/deployments/branch-policies#list-deployment-branch-policies
    //
    //meta:operation GET /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies
    func (s *RepositoriesService) ListDeploymentBranchPolicies(ctx context.Context, owner, repo, environment string) (*DeploymentBranchPolicyResponse, *Response, error) {

    Solution : Add ListOptions

  1. RepositoriesService.ListAutolinks dosen't support pagination acc to docs.
    // GitHub API docs: https://docs.github.com/rest/repos/autolinks#get-all-autolinks-of-a-repository
    //
    //meta:operation GET /repos/{owner}/{repo}/autolinks
    func (s *RepositoriesService) ListAutolinks(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Autolink, *Response, error) {

    Solution : Remove ListOptions

  1. PullRequestsService.ListReviewers dosen't support pagination acc to docs.
    // GitHub API docs: https://docs.github.com/rest/pulls/review-requests#get-all-requested-reviewers-for-a-pull-request
    //
    //meta:operation GET /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers
    func (s *PullRequestsService) ListReviewers(ctx context.Context, owner, repo string, number int, opts *ListOptions) (*Reviewers, *Response, error) {

    Solution : Remove ListOptions

  1. OrganizationsService.ListAll don't have page acc to docs if you run ListAllIter it will go in infinite loop since its pagination is powered exclusively by the since parameter.

    go-github/github/orgs.go

    Lines 171 to 174 in c8fd3f7

    // GitHub API docs: https://docs.github.com/rest/orgs/orgs#list-organizations
    //
    //meta:operation GET /organizations
    func (s *OrganizationsService) ListAll(ctx context.Context, opts *OrganizationsListOptions) ([]*Organization, *Response, error) {

    Solution : Replacing OrganizationsListOptions.ListOptions with UserListOptions.PerPage which will also result in removal of ListAllIter

  1. OrganizationsService.ListCodeSecurityConfigurations docs and OrganizationsService.ListCodeSecurityConfigurationRepositories docs support cursor pagination but its option are not properly made so Iter is missing for it.
    // GitHub API docs: https://docs.github.com/rest/code-security/configurations#get-code-security-configurations-for-an-organization
    //
    //meta:operation GET /orgs/{org}/code-security/configurations
    func (s *OrganizationsService) ListCodeSecurityConfigurations(ctx context.Context, org string, opts *ListOrgCodeSecurityConfigurationOptions) ([]*CodeSecurityConfiguration, *Response, error) {

    // GitHub API docs: https://docs.github.com/rest/code-security/configurations#get-repositories-associated-with-a-code-security-configuration
    //
    //meta:operation GET /orgs/{org}/code-security/configurations/{configuration_id}/repositories
    func (s *OrganizationsService) ListCodeSecurityConfigurationRepositories(ctx context.Context, org string, configurationID int64, opts *ListCodeSecurityConfigurationRepositoriesOptions) ([]*RepositoryAttachment, *Response, error) {

    Solution : Add ListCursorOptions to ListCodeSecurityConfigurationRepositoriesOptions and ListOrgCodeSecurityConfigurationOptions

  1. LicensesService.List support pagination acc to docs.
    // GitHub API docs: https://docs.github.com/rest/licenses/licenses#get-all-commonly-used-licenses
    //
    //meta:operation GET /licenses
    func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, error) {

    Solution : Add support for ListOptions

  1. IssuesService.List docs , IssuesService.ListByOrg docs and IssuesService.ListByRepo docs only suppost normal pagination not cursor.

    go-github/github/issues.go

    Lines 162 to 168 in c8fd3f7

    // GitHub API docs: https://docs.github.com/rest/issues/issues#list-issues-assigned-to-the-authenticated-user
    //
    // GitHub API docs: https://docs.github.com/rest/issues/issues#list-user-account-issues-assigned-to-the-authenticated-user
    //
    //meta:operation GET /issues
    //meta:operation GET /user/issues
    func (s *IssuesService) List(ctx context.Context, all bool, opts *IssueListOptions) ([]*Issue, *Response, error) {

    go-github/github/issues.go

    Lines 257 to 260 in c8fd3f7

    // GitHub API docs: https://docs.github.com/rest/issues/issues#list-repository-issues
    //
    //meta:operation GET /repos/{owner}/{repo}/issues
    func (s *IssuesService) ListByRepo(ctx context.Context, owner, repo string, opts *IssueListByRepoOptions) ([]*Issue, *Response, error) {

    go-github/github/issues.go

    Lines 181 to 184 in c8fd3f7

    // GitHub API docs: https://docs.github.com/rest/issues/issues#list-organization-issues-assigned-to-the-authenticated-user
    //
    //meta:operation GET /orgs/{org}/issues
    func (s *IssuesService) ListByOrg(ctx context.Context, org string, opts *IssueListOptions) ([]*Issue, *Response, error) {

    Solution : Remove ListCursorOptions

  1. EnterpriseService.ListCodeSecurityConfigurations docs and EnterpriseService.ListCodeSecurityConfigurationRepositories docs support cursor pagination but its option are not properly made so Iter is missing for it.
    // GitHub API docs: https://docs.github.com/rest/code-security/configurations#get-code-security-configurations-for-an-enterprise
    //
    //meta:operation GET /enterprises/{enterprise}/code-security/configurations
    func (s *EnterpriseService) ListCodeSecurityConfigurations(ctx context.Context, enterprise string, opts *ListEnterpriseCodeSecurityConfigurationOptions) ([]*CodeSecurityConfiguration, *Response, error) {

    // GitHub API docs: https://docs.github.com/rest/code-security/configurations#get-repositories-associated-with-an-enterprise-code-security-configuration
    //
    //meta:operation GET /enterprises/{enterprise}/code-security/configurations/{configuration_id}/repositories
    func (s *EnterpriseService) ListCodeSecurityConfigurationRepositories(ctx context.Context, enterprise string, configurationID int64, opts *ListCodeSecurityConfigurationRepositoriesOptions) ([]*RepositoryAttachment, *Response, error) {

    Solution : Add ListCursorOptions to ListCodeSecurityConfigurationRepositoriesOptions and ListEnterpriseCodeSecurityConfigurationOptions

It take so much time to find and write all these 😵

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions