@@ -37,12 +37,41 @@ const postCommentToPullRequest = async (
37
37
const octokit = new Octokit ( {
38
38
auth : `token ${ process . env . GITHUB_TOKEN } `
39
39
} ) ;
40
- await octokit . issues . createComment ( {
40
+
41
+ // Try to find existing report comment
42
+ const comments = await octokit . issues . listComments ( {
41
43
owner : "serverless-nextjs" ,
42
44
repo : "serverless-next.js" ,
43
- issue_number : prNumber ,
44
- body : comment
45
+ issue_number : prNumber
45
46
} ) ;
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
+ }
46
75
} ;
47
76
48
77
const main = async ( ) : Promise < void > => {
@@ -60,7 +89,7 @@ const main = async (): Promise<void> => {
60
89
// Get sizes from PR branch latest commit
61
90
const newSizes : Record < string , any > = calculateHandlerSizes ( ) ;
62
91
63
- let output = "# Handler Size Analysis \n" ;
92
+ let output = "# Handler Size Report \n" ;
64
93
output += `### Base Handler Sizes (kB) (commit ${ GITHUB_BASE_SHA } )\n` ;
65
94
output += "```ts\n" ;
66
95
output += JSON . stringify ( baseSizes , null , 4 ) + "\n" ;
0 commit comments