Skip to content

pr-comment-handler

pr-comment-handler #7

name: pr-comment-handler
on:
issue_comment:
types: [created, edited]
permissions:
contents: write
pull-requests: write
actions: read
defaults:
run:
shell: bash
env:
GH_TOKEN: ${{ github.token }}
jobs:
handle-comment:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, 'recreate-me') }}
outputs:
pr-base: ${{ steps.pr-details.outputs.base }}
steps:
- uses: actions/checkout@v4
- name: Determine PR details
id: pr-details
run: |
details=$(gh pr view ${{ github.event.issue.number }} --json 'baseRefName,headRefName')
headRefName=$(printf '%s' "$details" | jq -rc '.headRefName')
baseRefName=$(printf '%s' "$details" | jq -rc '.baseRefName')
if [[ "$headRefName" = "null" ]] || [[ "$baseRefName" = "null" ]]; then
echo "::error::Failed to parse pr details"
echo "$details"
exit 1
fi
echo "head=$headRefName" | tee -a "$GITHUB_OUTPUT"
echo "base=$baseRefName" | tee -a "$GITHUB_OUTPUT"
- name: Comment on PR
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.issue.number }}
recreate: true
header: recreation
message: |
This pull request is being re-created by [${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
create-new:
needs: [handle-comment]
uses: ./.github/workflows/generate.yml
with:
pr-base: ${{ needs.handle-comment.outputs.pr-base }}
secrets: inherit
close-old:
needs: [handle-comment, create-new]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Comment on old PR
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.issue.number }}
recreate: true
header: recreation
message: |
Re-created as #${{ needs.create-new.outputs.pr-number }}
- name: Close old PR
run: |
gh pr close ${{ github.event.issue.number }} -d