Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit d239beb

Browse files
committed
try to update existing comment
1 parent 5baf16f commit d239beb

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

scripts/comment-handler-sizes.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,41 @@ const postCommentToPullRequest = async (
3737
const octokit = new Octokit({
3838
auth: `token ${process.env.GITHUB_TOKEN}`
3939
});
40-
await octokit.issues.createComment({
40+
41+
// Try to find existing report comment
42+
const comments = await octokit.issues.listComments({
4143
owner: "serverless-nextjs",
4244
repo: "serverless-next.js",
43-
issue_number: prNumber,
44-
body: comment
45+
issue_number: prNumber
4546
});
47+
48+
let existingCommentId;
49+
50+
for (const comment of comments.data) {
51+
if (
52+
comment.body.includes("# Handler Size Report") &&
53+
comment.user.login === "slsnextbot"
54+
) {
55+
existingCommentId = comment.id;
56+
}
57+
}
58+
59+
if (existingCommentId) {
60+
await octokit.issues.updateComment({
61+
comment_id: existingCommentId,
62+
owner: "serverless-nextjs",
63+
repo: "serverless-next.js",
64+
issue_number: prNumber,
65+
body: comment
66+
});
67+
} else {
68+
await octokit.issues.createComment({
69+
owner: "serverless-nextjs",
70+
repo: "serverless-next.js",
71+
issue_number: prNumber,
72+
body: comment
73+
});
74+
}
4675
};
4776

4877
const main = async (): Promise<void> => {
@@ -60,7 +89,7 @@ const main = async (): Promise<void> => {
6089
// Get sizes from PR branch latest commit
6190
const newSizes: Record<string, any> = calculateHandlerSizes();
6291

63-
let output = "# Handler Size Analysis\n";
92+
let output = "# Handler Size Report\n";
6493
output += `### Base Handler Sizes (kB) (commit ${GITHUB_BASE_SHA})\n`;
6594
output += "```ts\n";
6695
output += JSON.stringify(baseSizes, null, 4) + "\n";

0 commit comments

Comments
 (0)