Last active
October 16, 2023 13:00
-
-
Save tiriana/0006b114f5c64ddc9d21595af5fad20c to your computer and use it in GitHub Desktop.
Github workflow to parse JIRA ticket key from branch name and add link to JIRA ticket in PR comment
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
# set JIRA_BASE_URL in env section | |
# put this file in .github/workflow | |
# done. | |
name: Add JIRA Link to PR | |
on: | |
pull_request: | |
types: | |
- opened | |
env: | |
JIRA_BASE_URL: LINK_TO_YOUR_JIRA # probably something like: https://<YOUR_COMPANY>.atlassian.net/ | |
PR_BRANCH: ${{ github.event.pull_request.head.ref }} | |
jobs: | |
add-jira-link: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Extract JIRA Key | |
id: extract-jira-key | |
run: | | |
echo "PR_BRANCH: $PR_BRANCH" | |
JIRA_KEY=$(echo $PR_BRANCH | grep -Eo '[A-Z]+-[0-9]+') | |
echo "::set-output name=jira_key::$JIRA_KEY" | |
- name: Add JIRA Link to PR | |
if: steps.extract-jira-key.outputs.jira_key != '' | |
run: | | |
JIRA_KEY="${{ steps.extract-jira-key.outputs.jira_key }}" | |
JIRA_LINK="$JIRA_BASE_URL/browse/$JIRA_KEY" | |
gh pr comment ${{ github.event.pull_request.number }} -b "🔗 Link to JIRA: [$JIRA_KEY]($JIRA_LINK)" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment