Skip to content

Test branch closed

Test branch closed #17

Workflow file for this run

name: Close Pull Request
# only trigger on pull request closed events
on:
pull_request:
types: [ closed ]
jobs:
merge_job:
# this job will only run if the PR has been merged
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Gets the target repository PR
env:
PR_BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
echo REP: $(curl -L -X GET -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.TARGET_REPO_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/nsarlin-zama/test-target-repo/pulls -d '{ "head": "nsarlin_zama:${PR_BRANCH}", "state": "open" }' | jq '.[0].url')
- run: |
echo PR #${{ github.event.number }} has been merged
close_job:
# this job will only run if the PR has been closed without being merged
if: github.event.pull_request.merged == false
runs-on: ubuntu-latest
steps:
- run: |
echo PR #${{ github.event.number }} has been closed without being merged
- name: Find corresponding Pull Request in the data repo
env:
PR_BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
{
echo 'DATA_REPO_PR<<EOF'
curl -f --no-progress-meter -L -X GET \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/nsarlin-zama/test-target-repo/pulls \
-d '{ "head": "nsarlin_zama:${PR_BRANCH}", "state": "open" }' | jq -e '.[0]'
echo EOF
} >> "${GITHUB_ENV}"
- name: Comment on the PR to indicate the reason of the close
run: |
curl -f --no-progress-meter -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TARGET_REPO_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ fromJson(env.DATA_REPO_PR).comments_url }} \
-d '{ "body": "PR closed because the corresponding PR in main repo was closed: ${{ github.repository }}#${{ github.event.number }}" }'
- name: Close the Pull Request in the data repo
run: |
curl -f --no-progress-meter -L -X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TARGET_REPO_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ fromJson(env.DATA_REPO_PR).url }} \
-d '{ "state": "closed" }'
- name: Delete the associated branch in the data repo
env:
PR_BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
curl -f --no-progress-meter -L -X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.TARGET_REPO_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/nsarlin-zama/test-target-repo/branches/${{ env.PR_BRANCH }}