-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
go.mod
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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{}) { |
There was a problem hiding this comment.
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]>
cc @leodido (sorry for the ping!) |
There was a problem hiding this 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
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.