Skip to content

Commit

Permalink
Modify PR template body and create github action to add Jira issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Janell-Huyck committed Oct 16, 2024
1 parent 18ccb29 commit aa37d8c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
23 changes: 4 additions & 19 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
Fixes #issuenumber ; refs #issuenumber
### Link to Jira Issue
[Link will be automatically added here. Do not remove.]

Present short summary (50 characters or less)

More detailed description, if necessary. Try to be as descriptive as you can: even if you think that the PR content is obvious, it may not be obvious to others. Include tracebacks if helpful, and be sure to call out any bits of the PR that may be work-in-progress.

Description can have multiple paragraphs and you can use code examples inside:

``` ruby
class PostsController
def index
respond_with Post.limit(10)
end
end
```

Changes proposed in this pull request:
*
*
*
### Description
<!-- Provide a description of what was changed and why -->
38 changes: 38 additions & 0 deletions .github/workflows/update-pr-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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)"}'

0 comments on commit aa37d8c

Please sign in to comment.