From 6a39b7bffdda460577ed9699f1e5c1049d5371db Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Tue, 25 Feb 2025 15:42:46 +0200 Subject: [PATCH] Change review apps PR workflow to leave only one comment --- .github/workflows/review_apps_on_pr_change.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/review_apps_on_pr_change.yml b/.github/workflows/review_apps_on_pr_change.yml index adad43d7d..0224031fd 100644 --- a/.github/workflows/review_apps_on_pr_change.yml +++ b/.github/workflows/review_apps_on_pr_change.yml @@ -76,9 +76,9 @@ jobs: - name: Comment on PR env: + COMMENT_MARKER: GH_TOKEN: ${{ github.token }} run: | - cat < "${{runner.temp}}/pr-comment.md" :tada: A review copy of this PR has been deployed! You can reach it at ${{steps.deploy.outputs.REVIEW_APP_URL}}. @@ -87,6 +87,13 @@ jobs: to debug, or otherwise ask an infrastructure person. For more details please see the [review app wiki page](https://github.com/alphagov/forms-team/wiki/Review-apps) + + $COMMENT_MARKER EOF + old_comment_ids=$(gh api "repos/{owner}/{repo}/issues/${{github.event.pull_request.number}}/comments" --jq 'map(select((.user.login == "github-actions[bot]") and (.body | endswith($ENV.COMMENT_MARKER + "\n")))) | .[].id') + for comment_id in $old_comment_ids; do + gh api -X DELETE "repos/{owner}/{repo}/issues/comments/${comment_id}" + done + gh pr comment "${{github.event.pull_request.html_url}}" --body-file "${{runner.temp}}/pr-comment.md"