@@ -160,6 +160,42 @@ jobs:
160160 done >> summary.md
161161
162162 - name : PR comment with file
163- uses : thollander/ actions-comment-pull-request@v2
163+ uses : actions/github-script@v6
164164 with :
165- filePath : breakage/summary.md
165+ github-token : ${{ secrets.GITHUB_TOKEN }}
166+ script : |
167+ // Import file content from summary.md
168+ const fs = require('fs')
169+ const filePath = 'breakage/summary.md'
170+ const msg = fs.readFileSync(filePath, 'utf8')
171+
172+ // Get the current PR number from context
173+ const prNumber = context.payload.pull_request.number
174+
175+ // Fetch existing comments on the PR
176+ const { data: comments } = await github.rest.issues.listComments({
177+ owner: context.repo.owner,
178+ repo: context.repo.repo,
179+ issue_number: prNumber
180+ })
181+
182+ // Find a previous comment by the bot to update
183+ const botComment = comments.find(comment => comment.user.id === 41898282)
184+
185+ if (botComment) {
186+ // Update the existing comment
187+ await github.rest.issues.updateComment({
188+ owner: context.repo.owner,
189+ repo: context.repo.repo,
190+ comment_id: botComment.id,
191+ body: msg
192+ })
193+ } else {
194+ // Create a new comment
195+ await github.rest.issues.createComment({
196+ owner: context.repo.owner,
197+ repo: context.repo.repo,
198+ issue_number: prNumber,
199+ body: msg
200+ })
201+ }
0 commit comments