diff --git a/.github/workflows/sonar-check.yml b/.github/workflows/sonar-check.yml index fbb3cb9f540d..d2d6f55cc5fb 100644 --- a/.github/workflows/sonar-check.yml +++ b/.github/workflows/sonar-check.yml @@ -80,12 +80,14 @@ jobs: 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 = ''; const branchRow = branchPct !== 'N/A' ? `| Branch coverage | **${branchPct}%** |` : ''; const body = [ + marker, `## ${emoji} Test Coverage Grade: \`${grade}\` — ${label}`, '', '| Metric | Value |', @@ -106,10 +108,26 @@ jobs: `> [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'); + }