-
Notifications
You must be signed in to change notification settings - Fork 86
Add pagination for finding commitId #201
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
base: main
Are you sure you want to change the base?
Conversation
When searching the branch for the commitId, use pagination to search more commits
meeroslav
left a comment
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.
The current solution doesn't work.
Can you replace it with a suggested async iterator and build the code so that the PR contains both source and the dist files?
Thanks!
| let commitFound = false; | ||
| yield octokit.paginate("GET /repos/{owner}/{repo}/commits", { | ||
| owner, | ||
| repo, | ||
| sha: branchName, | ||
| per_page: 100, | ||
| }, (response, done) => { | ||
| if (response.data.some((commit: { sha: string }) => commit.sha === commitSha)) { | ||
| commitFound = true; | ||
| done(); // Stop pagination if commit is found | ||
| } | ||
|
|
||
| return commits.data.some( | ||
| (commit: { sha: string }) => commit.sha === commitSha, | ||
| // Decrement maxPages and stop if limit reached | ||
| if (maxPages <= 1) { // Use <= 1 because it's decremented after checking | ||
| done(); | ||
| } | ||
| maxPages--; | ||
| return response; | ||
| } | ||
| ); | ||
|
|
||
| return commitFound; |
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.
This doesn't work outside of a generator. Can you modify it to use async iterrator instead?
let maxPages = 20; // TODO: This could be made an input param to allow larger/longer searches
for await (const response of octokit.paginate.iterator(
'GET /repos/{owner}/{repo}/commits',
{
owner,
repo,
sha: branchName,
per_page: 100,
},
)) {
if (
response.data.some(
(commit: { sha: string }) => commit.sha === commitSha,
)
) {
return true;
}
maxPages--;
if (maxPages <= 1) {
break;
}
}
return false;
When searching the branch for the commitId, use pagination to search more commits
Fixes #144