Update sonar-check.yml to manage coverage comments (#13878)
diff --git a/.github/workflows/sonar-check.yml b/.github/workflows/sonar-check.yml
index fbb3cb9..7f2a1bd 100644
--- a/.github/workflows/sonar-check.yml
+++ b/.github/workflows/sonar-check.yml
@@ -80,12 +80,14 @@
const emojiMap = { A: '🟢', B: '🟡', C: '🟠', D: '🔴', F: '⛔' };
const emoji = emojiMap[grade] ?? '❓';
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
+ const marker = '<!-- coverage-grade-bot -->';
const branchRow = branchPct !== 'N/A'
? `| Branch coverage | **${branchPct}%** |`
: '';
const body = [
+ marker,
`## ${emoji} Test Coverage Grade: \`${grade}\` — ${label}`,
'',
'| Metric | Value |',
@@ -106,10 +108,26 @@
`> [View full Actions run](${runUrl})`,
].filter(l => l !== undefined).join('\n');
- await github.rest.issues.createComment({
+ const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
- body: body,
});
- console.log('Posted coverage grade comment');
+ const existing = comments.find(c => c.user.login === 'github-actions[bot]' && c.body.includes(marker));
+ if (existing) {
+ await github.rest.issues.updateComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ comment_id: existing.id,
+ body: body,
+ });
+ console.log('Updated existing coverage grade comment');
+ } else {
+ await github.rest.issues.createComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: context.issue.number,
+ body: body,
+ });
+ console.log('Posted coverage grade comment');
+ }