LIBAAEC-33 Modify PR template body and create github actions to add Jira issue #1
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
name: Update Pull Request with Jira Issue Link | |
on: | |
pull_request: | |
types: [opened, edited] | |
jobs: | |
update-pr: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Extract Jira Issue from branch name | |
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 | |
jira_link="https://ucdts.atlassian.net/browse/$branch_name" | |
placeholder_exists=$(echo "${{ github.event.pull_request.body }}" | grep -c '\[Link will be automatically added here. Do not remove.\]') | |
if [ "$placeholder_exists" -eq 1 ]; then | |
# If the placeholder exists, replace it with the Jira link | |
pr_body=$(echo "${{ github.event.pull_request.body }}" | sed "s|\[Link will be automatically added here. Do not remove.\]|[$branch_name]($jira_link)|") | |
else | |
# If the placeholder is missing, append the Jira link to the top of the PR description | |
pr_body="### Link to Jira Issue\n[$branch_name]($jira_link)\n\n${{ github.event.pull_request.body }}" | |
fi | |
echo "$pr_body" > pr_body.txt | |
- name: Update Pull Request Description | |
uses: peter-evans/repository-dispatch@v2 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
event-type: pull-request-edited | |
client-payload: '{"pull_request_number": ${{ github.event.pull_request.number }}, "pr_body": "$(cat pr_body.txt)"}' |