Skip to content

LIBAAEC-33 Modify PR template body and create github actions to add Jira issue #4

LIBAAEC-33 Modify PR template body and create github actions to add Jira issue

LIBAAEC-33 Modify PR template body and create github actions to add Jira issue #4

Workflow file for this run

name: Update PR Title with Jira Issue
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
update-pr-title:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Extract Jira issue from branch name
id: extract_branch
run: |
branch_name=$(echo "${{ github.event.pull_request.head.ref }}" | grep -oE 'LIBAAEC-[0-9]+')
if [ -z "$branch_name" ]; then
echo "No Jira issue found in branch name."
exit 0
fi
echo "::set-output name=branch_name::$branch_name"
- name: Get current PR title
id: get_title
run: |
current_title="${{ github.event.pull_request.title }}"
echo "::set-output name=current_title::$current_title"
- name: Check if Jira issue is already in PR title
run: |
if [[ "${{ steps.get_title.outputs.current_title }}" == *"${{ steps.extract_branch.outputs.branch_name }}"* ]]; then
echo "PR title already contains the Jira issue."
exit 0
fi
- name: Prepend Jira issue to PR title
run: |
new_title="${{ steps.extract_branch.outputs.branch_name }} ${{ steps.get_title.outputs.current_title }}"
echo "::set-output name=new_title::$new_title"
- name: Update PR title with Jira issue
run: |
new_title="${{ steps.prepend_issue.outputs.new_title }}"
echo "Updating PR title to: $new_title"
curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d "{\"title\":\"$new_title\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}"