Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test branch closed #14

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ jobs:
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

Expand All @@ -20,4 +25,30 @@ jobs:
runs-on: ubuntu-latest
steps:
- run: |
echo PR #${{ github.event.number }} has been closed without being merged
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 -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 -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 -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 -L -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/${PR_BRANCH}

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

This repo showcases how to trigger an Github Actions workflow when a PR has been closed. Additionally it shows how you can distinguish whether the PR has been merged or not.

Test modif

[Additional information](https://brennerm.github.io/posts/trigger-github-actions-on-pr-close.html)
Loading