Skip to content

Instantly share code, notes, and snippets.

@ErikGMatos
Last active April 6, 2025 16:39
Show Gist options
  • Save ErikGMatos/18a3ce6aaf1c046b68f225a6e15f4227 to your computer and use it in GitHub Desktop.
Save ErikGMatos/18a3ce6aaf1c046b68f225a6e15f4227 to your computer and use it in GitHub Desktop.
name: Auto-fill PR with Jira info
on:
pull_request:
branches: [ master ]
types: [ opened ]
permissions:
pull-requests: write
contents: read
jobs:
fill-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract Jira issue key from branch
id: extract-key
run: |
ISSUE_KEY=$(echo "${{ github.head_ref }}" | grep -oiE '[a-z]+-[0-9]+' | head -1)
echo "JIRA_KEY=${ISSUE_KEY^^}" >> $GITHUB_OUTPUT
- name: Get Jira issue details
id: jira
if: steps.extract-key.outputs.JIRA_KEY
env:
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }}
JIRA_BASE_URL: "https://your-jira-instance.atlassian.net"
run: |
RESPONSE=$(curl -s -u "$JIRA_EMAIL:$JIRA_API_TOKEN" \
"$JIRA_BASE_URL/rest/api/3/issue/${{ steps.extract-key.outputs.JIRA_KEY }}?fields=summary,description,subtasks")
TITLE=$(echo "$RESPONSE" | jq -r '.fields.summary // "No title"')
echo "JIRA_TITLE=$TITLE" >> $GITHUB_OUTPUT
echo "JIRA_URL=$JIRA_BASE_URL/browse/${{ steps.extract-key.outputs.JIRA_KEY }}" >> $GITHUB_OUTPUT
- name: Update PR description
uses: actions/github-script@v6
if: steps.jira.outputs.JIRA_TITLE
with:
script: |
const prNumber = context.payload.pull_request.number;
const title = `[${{ steps.extract-key.outputs.JIRA_KEY }}] ${{ steps.jira.outputs.JIRA_TITLE }}`;
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
title
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment