mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
CI/SizeComment: enhance PR commenting logic to update existing comments
This commit is contained in:
committed by
Sylvestre Ledru
parent
e5a6b519ad
commit
4011e6dae6
@@ -58,26 +58,48 @@ jobs:
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
var fs = require('fs');
|
||||
const fs = require('fs');
|
||||
if (!fs.existsSync('./NR') || !fs.existsSync('./result.txt')) {
|
||||
core.info("No size comment payload to post.");
|
||||
return;
|
||||
}
|
||||
var issue_number = Number(fs.readFileSync('./NR'));
|
||||
const issue_number = Number(fs.readFileSync('./NR'));
|
||||
if (!issue_number) {
|
||||
core.info("No PR number; skipping.");
|
||||
return;
|
||||
}
|
||||
var content = fs.readFileSync('./result.txt');
|
||||
// Only comment when there is something meaningful to say.
|
||||
// compare_size_results.py only writes the file when there is a
|
||||
// significant change, so an empty/short body is treated as
|
||||
// "nothing to report".
|
||||
if (content.toString().trim().length > 0) {
|
||||
const content = fs.readFileSync('./result.txt').toString();
|
||||
|
||||
const marker = '<!-- size-comment-bot -->';
|
||||
const body = `${marker}\nBinary size comparison:\n\`\`\`\n${content}\n\`\`\``;
|
||||
|
||||
const { data: comments } = await github.rest.issues.listComments({
|
||||
...context.repo,
|
||||
issue_number
|
||||
});
|
||||
|
||||
const existing = comments.find(c =>
|
||||
c.user.login === 'github-actions[bot]' &&
|
||||
c.body.includes(marker)
|
||||
);
|
||||
|
||||
if (existing) {
|
||||
await github.rest.issues.updateComment({
|
||||
...context.repo,
|
||||
comment_id: existing.id,
|
||||
body
|
||||
});
|
||||
} else {
|
||||
// Only comment when there is something meaningful to say.
|
||||
// compare_size_results.py only writes the file when there is a
|
||||
// significant change, so an empty/short body is treated as
|
||||
// "nothing to report".
|
||||
if (content.trim().length == 0) {
|
||||
return;
|
||||
}
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue_number,
|
||||
body: 'Binary size comparison:\n```\n' + content + '```'
|
||||
...context.repo,
|
||||
issue_number,
|
||||
body
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user