Skip to content

deps: Merge #53 #54 PRs into pre-release-v3.8.2 #2

deps: Merge #53 #54 PRs into pre-release-v3.8.2

deps: Merge #53 #54 PRs into pre-release-v3.8.2 #2

name: Handle PR Branch Based on Title and Label
on:
pull_request:
types:
- closed # Trigger when PR is closed (merged or not)
jobs:
handle_pr:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check for 'milestone-merge' label or Title Pattern
id: check_conditions
run: |
# Get the PR title and labels
PR_TITLE="${{ github.event.pull_request.title }}"
PR_LABELS=$(echo "${{ github.event.pull_request.labels[*].name }}" | tr -d '[],"')
TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" # Get the target branch
echo "PR Title: $PR_TITLE"
echo "PR Labels: $PR_LABELS"
echo "Target branch: $TARGET_BRANCH"
# Check if title matches the dynamic pattern or has the 'milestone-merge' label
if echo "$PR_TITLE" | grep -qE "^deps: Merge #([0-9]+ )+# PRs into .+" || echo "$PR_LABELS" | grep -q "milestone-merge"; then
echo "proceed=true" >> $GITHUB_ENV # Write to environment file
else
echo "proceed=false" >> $GITHUB_ENV # Write to environment file
fi
- name: Delete branch after PR close
if: env.proceed == 'true'
run: |
BRANCH_NAME=$(echo "${{ github.event.pull_request.head.ref }}")
echo "Branch to delete: $BRANCH_NAME"
git push origin --delete $BRANCH_NAME
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Label PR if merged
if: env.proceed == 'true' && github.event.pull_request.merged == true
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
echo "PR #$PR_NUMBER was merged into $TARGET_BRANCH."
echo "Adding 'cherry-picked' label to merged PR."
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/issues/$PR_NUMBER/labels \
-d '{"labels":["cherry-picked"]}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}