Skip to content

Commit 0d35d36

Browse files
xtqqczzesylvestre
authored andcommitted
CI/GnuComment: enhance PR commenting logic to update existing comments
1 parent 7bf7fff commit 0d35d36

1 file changed

Lines changed: 31 additions & 8 deletions

File tree

.github/workflows/GnuComment.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,37 @@ jobs:
4949
with:
5050
github-token: ${{ secrets.GITHUB_TOKEN }}
5151
script: |
52-
var fs = require('fs');
53-
var issue_number = Number(fs.readFileSync('./NR'));
54-
var content = fs.readFileSync('./result.txt');
55-
if (content.toString().trim().length > 7) { // 7 because we have backquote + \n
52+
const fs = require('fs');
53+
const issue_number = Number(fs.readFileSync('./NR'));
54+
const content = fs.readFileSync('./result.txt').toString();
55+
56+
if (content.trim().length <= 7) { // 7 because we have backquote + \n
57+
return;
58+
}
59+
60+
const marker = '<!-- gnu-comment-bot -->';
61+
const body = `${marker}\nGNU testsuite comparison:\n\`\`\`\n${content}\n\`\`\``;
62+
63+
const { data: comments } = await github.rest.issues.listComments({
64+
...context.repo,
65+
issue_number
66+
});
67+
68+
const existing = comments.find(c =>
69+
c.user.login === 'github-actions[bot]' &&
70+
c.body.includes(marker)
71+
);
72+
73+
if (existing) {
74+
await github.rest.issues.updateComment({
75+
...context.repo,
76+
comment_id: existing.id,
77+
body
78+
});
79+
} else {
5680
await github.rest.issues.createComment({
57-
owner: context.repo.owner,
58-
repo: context.repo.repo,
59-
issue_number: issue_number,
60-
body: 'GNU testsuite comparison:\n```\n' + content + '```'
81+
...context.repo,
82+
issue_number,
83+
body
6184
});
6285
}

0 commit comments

Comments
 (0)