From d831dbc5b4adc7e4bf3d3ffa650f550d1cb56692 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 26 Mar 2025 00:54:23 +0100 Subject: [PATCH] Scripts: add automatic comment on pull requests --- .forgejo/workflows/deploy_hosted.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/.forgejo/workflows/deploy_hosted.yml b/.forgejo/workflows/deploy_hosted.yml index e11635f0f2..6e59a99250 100644 --- a/.forgejo/workflows/deploy_hosted.yml +++ b/.forgejo/workflows/deploy_hosted.yml @@ -66,16 +66,20 @@ jobs: - name: unzipping remote file run: ssh hetzner "cd /root/staging && rm -rf ${{ github.ref_name }} && unzip ${{ github.ref_name }}.zip && rm -rf /root/public/${{ github.ref_name }} && mv /root/staging/${{ github.ref_name }}/ /root/public/ && rm ${{ github.ref_name }}.zip" - - name: Extract PR number - run: echo "PR_NUMBER=$(echo $FORGEJO_REF_NAME | cut -d'/' -f3)" >> $FORGEJO_ENV - - - name: add comment to PR - if: env.PR_NUMBER != '' + - name: Comment on the PR run: | - curl -X POST "https://source.mapcomplete.org/api/v1/repos/${FORGEJO_REPOSITORY}/issues/${PR_NUMBER}/comments" \ + PR_NUMBER=$(echo ${{ github.event.pull_request.number || github.event.issue.number }}) + if [[ -n "$PR_NUMBER" ]] + then + echo "Found a pull request or issue number, will post to $PR_NUMBER ..." + MSG=$(echo "Congratulations! This PR been successfully built and has been deployed. It is (temporarily) available on https://builds.mapcomplete.org/${PR_NUMBER}") + BODY="{\"body\": \"$MSG\"}" + # Token must have following permissions: issue > read and write + curl -X POST "https://source.mapcomplete.org/api/v1/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \ -H "Content-Type: application/json" \ -H "Authorization: token $FORGEJO_TOKEN" \ - -d '{"body": "This PR has been deployed and is (temporarily) available on https://builds.mapcomplete.org/${PR_NUMBER}"}' + -d "$BODY" + fi env: FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}