Skip to content

Commit 3e31c1d

Browse files
committed
update comment editing logic
1 parent e8ad3a9 commit 3e31c1d

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed

.github/workflows/preview-release.yml

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -92,59 +92,33 @@ jobs:
9292
throw error;
9393
}
9494
95-
- name: Comment on PR
95+
- name: Find existing preview comment
9696
if: github.event_name == 'pull_request'
97-
uses: actions/github-script@v7
97+
uses: peter-evans/find-comment@v3
98+
id: find-comment
9899
with:
99-
github-token: ${{ secrets.GITHUB_TOKEN }}
100-
script: |
101-
// Unique identifier for this bot's comments
102-
const commentIdentifier = '<!-- realtime-js-preview-status -->';
103-
104-
const body = `${commentIdentifier}
100+
token: ${{ secrets.GITHUB_TOKEN }}
101+
issue-number: ${{ github.event.pull_request.number }}
102+
comment-author: 'github-actions[bot]'
103+
body-includes: '<!-- realtime-js-preview-status -->'
104+
105+
- name: Create or update preview comment
106+
if: github.event_name == 'pull_request'
107+
uses: peter-evans/create-or-update-comment@v4
108+
with:
109+
token: ${{ secrets.GITHUB_TOKEN }}
110+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
111+
issue-number: ${{ github.event.pull_request.number }}
112+
body: |
113+
<!-- realtime-js-preview-status -->
105114
🚀 **Preview release created!**
106115
107116
supabase-js CI tests have been automatically triggered on feature branch to verify compatibility.
108117
109-
**Preview package:** \`${{ needs.preview.outputs.preview-url }}\`
118+
**Preview package:** `${{ needs.preview.outputs.preview-url }}`
110119
111120
Results will be posted here once testing is complete.
112121
113122
---
114-
<sub>Last updated: ${new Date().toISOString()}</sub>`;
115-
116-
try {
117-
// First, try to find an existing comment from this bot
118-
const { data: comments } = await github.rest.issues.listComments({
119-
owner: context.repo.owner,
120-
repo: context.repo.repo,
121-
issue_number: context.issue.number
122-
});
123-
124-
// Look for a comment with our identifier
125-
const botComment = comments.find(comment =>
126-
comment.body && comment.body.includes(commentIdentifier)
127-
);
128-
129-
if (botComment) {
130-
// Update existing comment
131-
await github.rest.issues.updateComment({
132-
owner: context.repo.owner,
133-
repo: context.repo.repo,
134-
comment_id: botComment.id,
135-
body: body
136-
});
137-
console.log('Successfully updated existing preview status comment');
138-
} else {
139-
// Create new comment if none exists
140-
await github.rest.issues.createComment({
141-
owner: context.repo.owner,
142-
repo: context.repo.repo,
143-
issue_number: context.issue.number,
144-
body: body
145-
});
146-
console.log('Successfully posted new preview status comment');
147-
}
148-
} catch (error) {
149-
console.log('Failed to post/update comment:', error.message);
150-
}
123+
<sub>Last updated: ${{ github.event.head_commit.timestamp }}</sub>
124+
edit-mode: replace

0 commit comments

Comments
 (0)