diff --git a/.github/workflows/pyrefly-diff-comment.yml b/.github/workflows/pyrefly-diff-comment.yml
index 7f82942e7e..8e16baf933 100644
--- a/.github/workflows/pyrefly-diff-comment.yml
+++ b/.github/workflows/pyrefly-diff-comment.yml
@@ -77,10 +77,28 @@ jobs:
}
if (diff.trim()) {
- await github.rest.issues.createComment({
+ const body = '### Pyrefly Diff\n\nbase → PR
\n\n```diff\n' + diff + '\n```\n ';
+ const marker = '### Pyrefly Diff';
+ const { data: comments } = await github.rest.issues.listComments({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
- body: '### Pyrefly Diff\n\nbase → PR
\n\n```diff\n' + diff + '\n```\n ',
});
+ const existing = comments.find((comment) => comment.body.startsWith(marker));
+
+ if (existing) {
+ await github.rest.issues.updateComment({
+ comment_id: existing.id,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body,
+ });
+ } else {
+ await github.rest.issues.createComment({
+ issue_number: prNumber,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body,
+ });
+ }
}
diff --git a/.github/workflows/pyrefly-diff.yml b/.github/workflows/pyrefly-diff.yml
index 0cf54e3585..386bd25751 100644
--- a/.github/workflows/pyrefly-diff.yml
+++ b/.github/workflows/pyrefly-diff.yml
@@ -103,9 +103,26 @@ jobs:
].join('\n')
: '### Pyrefly Diff\nNo changes detected.';
- await github.rest.issues.createComment({
+ const marker = '### Pyrefly Diff';
+ const { data: comments } = await github.rest.issues.listComments({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
- body,
});
+ const existing = comments.find((comment) => comment.body.startsWith(marker));
+
+ if (existing) {
+ await github.rest.issues.updateComment({
+ comment_id: existing.id,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body,
+ });
+ } else {
+ await github.rest.issues.createComment({
+ issue_number: prNumber,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body,
+ });
+ }