Skip to content

Commit cacfed2

Browse files
committed
Update lint workflow to replace or update PR comment instead of duplicating it
1 parent 13088d4 commit cacfed2

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

.github/workflows/lint.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,26 @@ jobs:
5050
const output = fs.readFileSync('lint-output.txt', 'utf8');
5151
const exitCode = '${{ steps.lint.outputs.exit_code }}';
5252
const title = exitCode === '0' ? '✅ Lint passed' : '❌ Lint found issues';
53-
const body = `### ${title}\n\n<details><summary>Show output</summary>\n\n\`\`\`\n${output.slice(-60000)}\n\`\`\`\n\n</details>`;
53+
const marker = '<!-- lint-report:adev-nextjs-blog -->';
54+
const body = `${marker}\n### ${title}\n\n<details><summary>Show output</summary>\n\n\`\`\`\n${output.slice(-60000)}\n\`\`\`\n\n</details>`;
5455
const { owner, repo } = context.repo;
5556
const issue_number = context.issue.number;
5657
if (!issue_number) {
5758
core.info('No pull request context detected, skipping comment.');
5859
} else {
59-
await github.rest.issues.createComment({ owner, repo, issue_number, body });
60+
// Find existing comment with the marker and update it; otherwise create a new one
61+
const comments = await github.paginate(github.rest.issues.listComments, {
62+
owner,
63+
repo,
64+
issue_number,
65+
per_page: 100,
66+
});
67+
const existing = comments.find(c => typeof c.body === 'string' && c.body.includes(marker));
68+
if (existing) {
69+
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
70+
} else {
71+
await github.rest.issues.createComment({ owner, repo, issue_number, body });
72+
}
6073
}
6174
6275
- name: Fail if lint failed

0 commit comments

Comments
 (0)