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

Commit d216f9d

Browse files
authored
fix review list comments (#39)
<!-- This is an auto-generated comment: release notes by openai --> ### Summary by OpenAI **Release Notes** This pull request includes a refactor of the `list_review_comments` function in `src/commenter.ts`. The function now uses a do-while loop instead of recursion for better performance and readability. An empty array is also added to store comments and return it in case of failure. This change improves the reliability of the codebase. <!-- end of auto-generated comment: release notes by openai -->
1 parent cc6bd7b commit d216f9d

File tree

3 files changed

+35
-42
lines changed

3 files changed

+35
-42
lines changed

action.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ inputs:
6868
6969
In this session, we will summarize a pull request.
7070
71-
Please provide a bullet point list containing the filename and a short
72-
summary (within 30 words) for each file's diff.
73-
7471
I will provide diffs for each file to be summarized. In every response,
7572
you will provide/update the bullet point list containing the filename and
7673
diff summary (within 30 words) of each file.

dist/index.js

Lines changed: 17 additions & 20 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 & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,28 +139,27 @@ ${tag}`
139139
}
140140
}
141141

142-
// recursively list review comments
143142
const list_review_comments = async (target: number, page: number = 1) => {
143+
const comments: any[] = []
144144
try {
145-
let {data: comments} = await octokit.pulls.listReviewComments({
146-
owner: repo.owner,
147-
repo: repo.repo,
148-
pull_number: target,
149-
page: page,
150-
per_page: 100
151-
})
152-
if (!comments) {
153-
return []
154-
}
155-
if (comments.length >= 100) {
156-
comments = comments.concat(await list_review_comments(target, page + 1))
157-
return comments
158-
} else {
159-
return comments
160-
}
145+
let data
146+
do {
147+
;({data} = await octokit.pulls.listReviewComments({
148+
owner: repo.owner,
149+
repo: repo.repo,
150+
pull_number: target,
151+
page,
152+
per_page: 100
153+
}))
154+
155+
comments.push(...data)
156+
page++
157+
} while (data.length >= 100)
158+
159+
return comments
161160
} catch (e: any) {
162-
core.warning(`Failed to list review comments: ${e}`)
163-
return []
161+
console.warn(`Failed to list review comments: ${e}`)
162+
return comments
164163
}
165164
}
166165

0 commit comments

Comments
 (0)