Skip to content

Commit 2c2b10b

Browse files
refactor: add pagination for comments and improve code clarity
Co-authored-by: jacksonpradolima <[email protected]>
1 parent c684c19 commit 2c2b10b

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

.github/workflows/pr-labeler.yml

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,39 @@ jobs:
171171
return;
172172
}
173173
174-
// Get all comments on the PR (issue comments)
175-
const comments = await github.rest.issues.listComments({
176-
owner: context.repo.owner,
177-
repo: context.repo.repo,
178-
issue_number: pullNumber,
179-
per_page: 100
180-
});
174+
// Get all comments on the PR (issue comments) with pagination
175+
let allComments = [];
176+
let page = 1;
177+
let hasMore = true;
178+
while (hasMore) {
179+
const comments = await github.rest.issues.listComments({
180+
owner: context.repo.owner,
181+
repo: context.repo.repo,
182+
issue_number: pullNumber,
183+
per_page: 100,
184+
page: page
185+
});
186+
allComments = allComments.concat(comments.data);
187+
hasMore = comments.data.length === 100;
188+
page++;
189+
}
181190
182-
// Get review comments
183-
const reviewComments = await github.rest.pulls.listReviewComments({
184-
owner: context.repo.owner,
185-
repo: context.repo.repo,
186-
pull_number: pullNumber,
187-
per_page: 100
188-
});
191+
// Get review comments with pagination
192+
let allReviewComments = [];
193+
page = 1;
194+
hasMore = true;
195+
while (hasMore) {
196+
const reviewComments = await github.rest.pulls.listReviewComments({
197+
owner: context.repo.owner,
198+
repo: context.repo.repo,
199+
pull_number: pullNumber,
200+
per_page: 100,
201+
page: page
202+
});
203+
allReviewComments = allReviewComments.concat(reviewComments.data);
204+
hasMore = reviewComments.data.length === 100;
205+
page++;
206+
}
189207
190208
// Get PR details for body and title
191209
const pr = await github.rest.pulls.get({
@@ -198,8 +216,8 @@ jobs:
198216
const allText = [
199217
pr.data.title.toLowerCase(),
200218
pr.data.body?.toLowerCase() || '',
201-
...comments.data.map(c => c.body?.toLowerCase() || ''),
202-
...reviewComments.data.map(c => c.body?.toLowerCase() || '')
219+
...allComments.map(c => c.body?.toLowerCase() || ''),
220+
...allReviewComments.map(c => c.body?.toLowerCase() || '')
203221
].join(' ');
204222
205223
// Helper function to escape regex special characters
@@ -302,9 +320,9 @@ jobs:
302320
303321
// Get the latest review per reviewer, excluding dismissed reviews
304322
const latestReviewsByUser = {};
305-
for (const review of reviews.data) {
306-
if (review.state === 'DISMISSED') continue;
307-
323+
const activeReviews = reviews.data.filter(review => review.state !== 'DISMISSED');
324+
325+
for (const review of activeReviews) {
308326
const userId = review.user.id;
309327
if (!latestReviewsByUser[userId] ||
310328
new Date(review.submitted_at) > new Date(latestReviewsByUser[userId].submitted_at)) {

0 commit comments

Comments
 (0)