Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit cc6bd7b

Browse files
authored
fix list comments (#38)
<!-- This is an auto-generated comment: release notes by openai --> ### Summary by OpenAI **Release Notes** Improved pagination for listing comments. This pull request fixes the issue with pagination while listing comments. The changes made in this pull request will help users to view all the comments on a particular issue without any issues. <!-- end of auto-generated comment: release notes by openai -->
1 parent 598bd86 commit cc6bd7b

File tree

2 files changed

+35
-37
lines changed

2 files changed

+35
-37
lines changed

dist/index.js

Lines changed: 17 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commenter.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -285,25 +285,25 @@ const find_comment_with_tag = async (tag: string, target: number) => {
285285
}
286286

287287
const list_comments = async (target: number, page: number = 1) => {
288+
const comments: any[] = []
288289
try {
289-
let {data: comments} = await octokit.issues.listComments({
290-
owner: repo.owner,
291-
repo: repo.repo,
292-
issue_number: target,
293-
page,
294-
per_page: 100
295-
})
296-
if (!comments) {
297-
return []
298-
}
299-
if (comments.length >= 100) {
300-
comments = comments.concat(await list_comments(target, page + 1))
301-
return comments
302-
} else {
303-
return comments
304-
}
290+
let data
291+
do {
292+
;({data} = await octokit.issues.listComments({
293+
owner: repo.owner,
294+
repo: repo.repo,
295+
issue_number: target,
296+
page,
297+
per_page: 100
298+
}))
299+
300+
comments.push(...data)
301+
page++
302+
} while (data.length >= 100)
303+
304+
return comments
305305
} catch (e: any) {
306-
core.warning(`Failed to list comments: ${e}`)
307-
return []
306+
console.warn(`Failed to list comments: ${e}`)
307+
return comments
308308
}
309309
}

0 commit comments

Comments
 (0)