Skip to content

Commit b2ad52f

Browse files
nickboldtrhdh-botthemr0c
authored
chore(pr comments): reuse pr comments so we don't have dozens of identical links (#502)
Co-authored-by: rhdh-bot service account <[email protected]> Co-authored-by: Fabrice Flore-Thébault <[email protected]>
1 parent f917a5f commit b2ad52f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

.github/workflows/pr.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ jobs:
9191
keep_files: true
9292
publish_dir: ./titles-generated
9393

94-
- name: PR comment with doc preview
95-
uses: actions/github-script@v7
96-
with:
97-
github-token: ${{ secrets.RHDH_BOT_TOKEN }}
98-
script: |
99-
github.rest.issues.createComment({
100-
issue_number: context.issue.number,
101-
owner: context.repo.owner,
102-
repo: context.repo.repo,
103-
body: 'PR Preview: https://redhat-developer.github.io/red-hat-developers-documentation-rhdh/pr-${{ github.event.number }}/'
104-
});
94+
- name: PR comment with doc preview, replacing existing comments with a new one each time
95+
shell: bash
96+
run: |
97+
PR_NUM="${{ github.event.number }}"
98+
# for a given PR, check for existing comments from rhdh-bot; select the last one (if more than one)
99+
if [[ $(gh api repos/{owner}/{repo}/issues/${PR_NUM}/comments | jq '.[]|select(.user.login=="rhdh-bot")|.id' | tail -1) ]]; then
100+
# edit that comment:
101+
gh pr comment ${PR_NUM} --edit-last --body "Updated preview: https://redhat-developer.github.io/red-hat-developers-documentation-rhdh/pr-${PR_NUM}/ @ $(date "+%x %X")"
102+
else
103+
# or create a new one:
104+
gh pr comment ${PR_NUM} --body "Preview: https://redhat-developer.github.io/red-hat-developers-documentation-rhdh/pr-${PR_NUM}/"
105+
fi

0 commit comments

Comments
 (0)