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

Add pagination to comment lookup query #59

Merged
merged 11 commits into from
Feb 5, 2024
Merged
26 changes: 17 additions & 9 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,28 @@ export default class GitHub {
body: commentMessage,
};

const comments = (await this.octokit.rest.issues.listComments(commentInfo))
.data;
for (const currentComment of comments) {
if (
currentComment.user.type === "Bot" &&
currentComment.body.includes( 'The following accounts have interacted with this PR and/or linked issues.' )
) {
commentId = currentComment.id;
for await (const response of this.octokit.paginate.iterator(
this.octokit.rest.issues.listComments,
commentInfo
)) {
for (const currentComment of response.data) {
if (
currentComment.user.type === "Bot" &&
currentComment.body.includes( 'The following accounts have interacted with this PR and/or linked issues.' )
) {
commentId = currentComment.id;
break;
}
}

if (commentId) {
break;
}
}

if (commentId) {
core.info(`Updating previous comment #${commentId}`);

try {
await this.octokit.rest.issues.updateComment({
...context.repo,
Expand All @@ -194,7 +202,7 @@ export default class GitHub {

// No previous or edit comment failed.
if (!commentId) {
core.info("Creating new comment");
core.info("No previous comment found. Creating a new one.");
try {
await this.octokit.rest.issues.createComment(comment);
} catch (e) {
Expand Down