Skip to content

Commit 914b5d8

Browse files
authored
Update PR comments in place (#4620)
* Update PR comments in place Currently, we post a new comment for each change, which is just spam for PRs with many iterations. * Pin actions by hash
1 parent d2baac0 commit 914b5d8

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

.github/validate-pr/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,10 @@ async function run() {
141141
}
142142
comment += `\nYou can validate ${table.length === 1 ? 'this' : 'these'} API${table.length === 1 ? '' : 's'} yourself by using the ${tick}make validate${tick} target.\n`
143143

144-
await octokit.rest.issues.createComment({
145-
owner: 'elastic',
146-
repo: 'elasticsearch-specification',
147-
issue_number: context.payload.pull_request.number,
148-
body: comment
149-
})
144+
core.setOutput('has_results', 'true')
145+
core.setOutput('comment_body', comment)
146+
} else {
147+
core.setOutput('has_results', 'false')
150148
}
151149

152150
core.info('Done!')

.github/workflows/validate-pr.yml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,25 @@ jobs:
6363
env:
6464
GCS_CREDENTIALS: ${{ secrets.GCS_CREDENTIALS }}
6565

66-
- name: Remove previous comment
67-
uses: maheshrayas/action-pr-comment-delete@v1
68-
with:
69-
github_token: ${{ secrets.GITHUB_TOKEN }}
70-
org: elastic
71-
repo: elasticsearch-specification
72-
user: github-actions[bot]
73-
issue: ${{ github.event.number }}
74-
7566
- name: Run validation
67+
id: validation
7668
working-directory: ./elasticsearch-specification
7769
run: node .github/validate-pr --token ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Find existing comment
72+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
73+
id: find-comment
74+
with:
75+
issue-number: ${{ github.event.pull_request.number }}
76+
comment-author: 'github-actions[bot]'
77+
body-includes: 'Following you can find the validation results'
78+
79+
- name: Create or update comment
80+
if: steps.validation.outputs.has_results == 'true'
81+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
82+
with:
83+
token: ${{ secrets.GITHUB_TOKEN }}
84+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
85+
issue-number: ${{ github.event.pull_request.number }}
86+
body: ${{ steps.validation.outputs.comment_body }}
87+
edit-mode: replace

0 commit comments

Comments
 (0)