|
| 1 | +name: Update Pull Request Template |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [opened, edited] |
| 5 | + |
| 6 | +jobs: |
| 7 | + update-pr-template: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + permissions: |
| 10 | + pull-requests: write |
| 11 | + contents: read |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + ref: ${{ github.event.pull_request.head.sha }} |
| 18 | + |
| 19 | + - name: Extract commit parts |
| 20 | + id: extract_parts |
| 21 | + shell: bash |
| 22 | + run: | |
| 23 | + COMMIT_MESSAGE=$(git log -1 --pretty=%B) |
| 24 | + echo "Commit message: $COMMIT_MESSAGE" |
| 25 | + |
| 26 | + # Simpler regex pattern that's more forgiving |
| 27 | + if [[ "$COMMIT_MESSAGE" =~ ^([^(:]+)(\(([^)]*)\))?:[[:space:]]*([A-Z]+-[0-9]+)?[[:space:]]*(.+)$ ]]; then |
| 28 | + echo "type=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT |
| 29 | + echo "scope=${BASH_REMATCH[3]:-}" >> $GITHUB_OUTPUT |
| 30 | + echo "ticket=${BASH_REMATCH[4]:-}" >> $GITHUB_OUTPUT |
| 31 | + echo "subject=${BASH_REMATCH[5]}" >> $GITHUB_OUTPUT |
| 32 | + |
| 33 | + # Debug output |
| 34 | + echo "Extracted parts:" |
| 35 | + echo "Type: ${BASH_REMATCH[1]}" |
| 36 | + echo "Full scope: ${BASH_REMATCH[2]}" |
| 37 | + echo "Scope content: ${BASH_REMATCH[3]}" |
| 38 | + echo "Ticket: ${BASH_REMATCH[4]}" |
| 39 | + echo "Subject: ${BASH_REMATCH[5]}" |
| 40 | + else |
| 41 | + echo "Invalid commit message format. Expected: type(scope): TICKET-123 subject" |
| 42 | + echo "Received: $COMMIT_MESSAGE" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Generate PR body |
| 47 | + id: generate_body |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + TYPE="${{ steps.extract_parts.outputs.type }}" |
| 51 | + SCOPE="${{ steps.extract_parts.outputs.scope }}" |
| 52 | + TICKET="${{ steps.extract_parts.outputs.ticket }}" |
| 53 | + SUBJECT="${{ steps.extract_parts.outputs.subject }}" |
| 54 | + |
| 55 | + cat << EOF > pr_body.md |
| 56 | + # ${TYPE}${SCOPE:+($SCOPE)}: ${SUBJECT} |
| 57 | +
|
| 58 | + ${TICKET:+- Closes ${TICKET}} |
| 59 | +
|
| 60 | + ## Description |
| 61 | + <!-- Add a description of the changes proposed in the pull request --> |
| 62 | +
|
| 63 | + ## Acceptance Criterias |
| 64 | + <!-- List all acceptance criteria from the ticket --> |
| 65 | +
|
| 66 | + ## Links |
| 67 | + - [JIRA](https://ferlab-crsj.atlassian.net/browse/${TICKET}) |
| 68 | + - [Design](https://) |
| 69 | +
|
| 70 | + ## Extra Validation |
| 71 | + - [ ] Reviewer video or screenshots attached |
| 72 | + - [ ] QA Done |
| 73 | + - [ ] Design/UI Approved from design |
| 74 | +
|
| 75 | + ## Screenshot or Video |
| 76 | + ### Before |
| 77 | + <!-- Add screenshots/videos of the feature/bug before this PR --> |
| 78 | +
|
| 79 | + ### After |
| 80 | + <!-- Add screenshots/videos of the feature/bug after this PR --> |
| 81 | +
|
| 82 | + ## QA |
| 83 | + ### Steps to validate |
| 84 | + <!-- Add step by step instructions to test this PR --> |
| 85 | + 1. |
| 86 | + 2. |
| 87 | +
|
| 88 | + ## Mention |
| 89 | + <!-- @ mention any relevant teammates --> |
| 90 | + EOF |
| 91 | + |
| 92 | + PR_BODY=$(cat pr_body.md) |
| 93 | + echo "pr_body<<EOF" >> $GITHUB_OUTPUT |
| 94 | + echo "$PR_BODY" >> $GITHUB_OUTPUT |
| 95 | + echo "EOF" >> $GITHUB_OUTPUT |
| 96 | + |
| 97 | + - name: Update PR |
| 98 | + uses: actions/github-script@v7 |
| 99 | + with: |
| 100 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + script: | |
| 102 | + await github.rest.pulls.update({ |
| 103 | + owner: context.repo.owner, |
| 104 | + repo: context.repo.repo, |
| 105 | + pull_number: context.issue.number, |
| 106 | + body: `${{ steps.generate_body.outputs.pr_body }}` |
| 107 | + }); |
| 108 | +
|
0 commit comments