Skip to content

Commit

Permalink
Add pagination to comment lookup query (#59)
Browse files Browse the repository at this point in the history
* Add pagination to comment lookup query.

* Add test repository info.

* Some debug code.

* More debuggin.

* More debugging.

* Use correct method.

* Allow the comment to be posted on the current repo.

* Remove debug code.

* Correct break logic.

* Remove test configuration.

* Clarify comment.

Co-authored-by: desrosj <desrosj@git.wordpress.org>
Co-authored-by: aaronjorbin <jorbin@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
  • Loading branch information
5 people authored Feb 5, 2024
1 parent f10ee17 commit d099497
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
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

0 comments on commit d099497

Please sign in to comment.