test #29
This file contains hidden or 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: PR Bot | |
| on: | |
| pull_request_target: | |
| types: [opened, edited] | |
| jobs: | |
| update-pr-body: | |
| runs-on: ubuntu-latest | |
| if: ${{ !contains(github.event.pull_request.body, 'mellea-pr-edited-marker') }} | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| steps: | |
| - name: Checkout code # Checks out the base branch, not PR branch. | |
| uses: actions/checkout@v4 | |
| - name: Detect PR type from checkboxes | |
| id: detect-type | |
| env: | |
| PR_BODY: ${{ github.event.pull_request.body }} | |
| run: | | |
| PR_TYPE="" | |
| # Check for checked boxes (supports [x] and [X]) | |
| if echo "$PR_BODY" | grep -qi '\[x\] Bug fix'; then | |
| PR_TYPE="bug" | |
| elif echo "$PR_BODY" | grep -qi '\[x\] Feature'; then | |
| PR_TYPE="feature" | |
| elif echo "$PR_BODY" | grep -qi '\[x\] Documentation'; then | |
| PR_TYPE="documentation" | |
| fi | |
| if [ -z "$PR_TYPE" ]; then | |
| echo "::error::No PR type selected. Please check one of: Bug fix, Feature, or Documentation." | |
| exit 1 | |
| fi | |
| echo "pr_type=$PR_TYPE" >> "$GITHUB_OUTPUT" | |
| echo "Detected PR type: $PR_TYPE" | |
| - name: Update PR body with checklist | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_BODY: ${{ github.event.pull_request.body }} | |
| PR_TYPE: ${{ steps.detect-type.outputs.pr_type }} | |
| run: | | |
| TEMPLATE_FILE=".github/PULL_REQUEST_TEMPLATE/${PR_TYPE}.md" | |
| if [ -f "$TEMPLATE_FILE" ]; then | |
| MARKER="<!-- mellea-pr-edited-marker: do not remove this marker -->" | |
| TEMPLATE_CONTENT=$(cat "$TEMPLATE_FILE") | |
| NEW_BODY="${MARKER} | |
| ${TEMPLATE_CONTENT}" | |
| gh pr edit ${{ github.event.pull_request.number }} --body "$NEW_BODY" | |
| echo "Updated PR body with ${PR_TYPE} checklist" | |
| else | |
| echo "Template file not found: $TEMPLATE_FILE" | |
| fi | |
| - name: Comment on PR | |
| uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc | |
| with: | |
| message: | | |
| The PR description has been updated with a checklist based on your selected PR type. | |
| Please fill out the checklist in the PR description above. | |
| # TODO: JAL. Need to add a misc / default category. | |
| # TODO: JAL. remove anything but the checkboxes and an explanation from the default template until so that people don't get mistaken. | |
| # TODO: JAL. add a new comment when the PR body is updated. | |
| # remove checklists from the templates and just have TODOs... |