diff --git a/.github/workflows/pr-close.yml b/.github/workflows/pr-close.yml index 6a205cf..c720373 100644 --- a/.github/workflows/pr-close.yml +++ b/.github/workflows/pr-close.yml @@ -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 @@ -20,4 +25,30 @@ jobs: runs-on: ubuntu-latest steps: - run: | - echo PR #${{ github.event.number }} has been closed without being merged \ No newline at end of file + 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<> "${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} + diff --git a/README.md b/README.md index c6eba6b..81c228f 100644 --- a/README.md +++ b/README.md @@ -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)