-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
937db43
commit f32e867
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Archive Branch on PR Merge | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
|
||
jobs: | ||
archive_branch: | ||
if: github.event.pull_request.merged == true | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Rename Branch | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
ORIGINAL_BRANCH: ${{ github.event.pull_request.head.ref }} | ||
run: | | ||
# Replace 'x/' with 'z/merged/' in the branch name | ||
if [[ "$ORIGINAL_BRANCH" == x/* ]]; then | ||
ARCHIVED_BRANCH="${ORIGINAL_BRANCH/x\//z\/merged/}" | ||
else | ||
ARCHIVED_BRANCH="z/archived/${ORIGINAL_BRANCH}" | ||
fi | ||
# Rename the branch using the GitHub API | ||
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
https://api.github.com/repos/${{ github.repository }}/git/refs/heads/${ORIGINAL_BRANCH}/rename \ | ||
-d "{\"new_name\": \"${ARCHIVED_BRANCH}\"}" | ||
- name: Comment on PR | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR_NUMBER: ${{ github.event.pull_request.number }} | ||
ARCHIVED_BRANCH: ${{ steps.rename.outputs.ARCHIVED_BRANCH }} | ||
run: | | ||
# Add a comment on the PR with the new branch name | ||
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments \ | ||
-d "{\"body\": \"Branch archived as ${ARCHIVED_BRANCH}\"}" |