Skip to content

Commit 1caf698

Browse files
authored
Update PR comments in place (#4620) (#4664)
* 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 (cherry picked from commit 914b5d8)
1 parent a5300a4 commit 1caf698

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
@@ -147,12 +147,10 @@ async function run() {
147147
}
148148
comment += `\nYou can validate ${changedApis.length === 1 ? 'this' : 'these'} API${changedApis.length === 1 ? '' : 's'} yourself by using the ${tick}make validate${tick} target.\n`
149149

150-
await octokit.rest.issues.createComment({
151-
owner: 'elastic',
152-
repo: 'elasticsearch-specification',
153-
issue_number: context.payload.pull_request.number,
154-
body: comment
155-
})
150+
core.setOutput('has_results', 'true')
151+
core.setOutput('comment_body', comment)
152+
} else {
153+
core.setOutput('has_results', 'false')
156154
}
157155

158156
core.info('Done!')

.github/workflows/validate-pr.yml

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

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

0 commit comments

Comments
 (0)