Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pkg): fixed pull request lister pagination support. #13

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Jan 8, 2024

Moreover, properly adhere to github API pr lister limits (100 per-page). Plus, avoid a second call to github API to check if PR was merged, since the info is already present in the pull request list return schema.

Finally, when no token is passed, properly enforce a github rate limiting client, so that we should never get rate limited.

Also, bumped go module deps versions.

go.mod Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go get -u

go.sum Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go mod tidy.

// Eventually create an authenticated client
if token != "" {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(context.Background(), ts)
client = github.NewClient(tc)
} else {
// Force use a rate limited client. It will be slow but should overcome rate limiting issues.
rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient(nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force a rate limited github client when no token is passed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

//
// The number of results per page (max 100). For more information, see "Using pagination in the REST API."
// Default: 30
PerPage: 100,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adhere to github API limits for the List options.

// Default: 1
page := 1
prs := make([]*github.PullRequest, 0)
for {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collect all PRs supporting pagination.

}
if !isMerged {
// It means PR has been closed but not merged in
if p.GetMergedAt().Equal(time.Time{}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid a call to github API to retrieve the merged state.
Note: p.GetMerged() always returns false because merged is always empty since github API does not provide it anymore.
See https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests schema:

 "required": [
      "_links",
      "assignee",
      "labels",
      "base",
      "body",
      "closed_at",
      "comments_url",
      "commits_url",
      "created_at",
      "diff_url",
      "head",
      "html_url",
      "id",
      "node_id",
      "issue_url",
      "merge_commit_sha",
      "merged_at",
      "milestone",
      "number",
      "patch_url",
      "review_comment_url",
      "review_comments_url",
      "statuses_url",
      "state",
      "locked",
      "title",
      "updated_at",
      "url",
      "user",
      "author_association",
      "auto_merge"
    ]

We use merged_at now.

Moreover, properly adhere to github API pr lister limits (100 per-page).
Plus, avoid a second call to github API to check if PR was merged, since the info is already present
in the pull request list return schema.

Finally, when no token is passed, properly enforce a github rate limiting client, so that we should never
get rate limited.

Also, bumped go module deps versions.

Signed-off-by: Federico Di Pierro <[email protected]>
@FedeDP
Copy link
Contributor Author

FedeDP commented Jan 9, 2024

cc @leodido (sorry for the ping!)

Copy link
Owner

@leodido leodido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, Federico!

// Eventually create an authenticated client
if token != "" {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(context.Background(), ts)
client = github.NewClient(tc)
} else {
// Force use a rate limited client. It will be slow but should overcome rate limiting issues.
rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient(nil)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@leodido leodido merged commit 1378404 into leodido:master Jan 11, 2024
1 check passed
@FedeDP FedeDP deleted the fix/pagination branch January 11, 2024 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants