name: PR Close Issue (Template) on: workflow_call: secrets: GITHUB_TOKEN: required: true jobs: close-issue: runs-on: ubuntu-latest if: github.event.pull_request.merged == true steps: - name: Checkout repository uses: actions/checkout@v4 - name: Extract issue number and close issue env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | BRANCH_NAME="${{ github.event.pull_request.head.ref }}" echo "Branch name: $BRANCH_NAME" # Extract issue number from branch name (format: issue-122-issue-title) if [[ $BRANCH_NAME =~ ^issue-([0-9]+)- ]]; then ISSUE_NUMBER="${BASH_REMATCH[1]}" echo "Found issue number: $ISSUE_NUMBER" # Close the issue using Gitea API curl -X PATCH \ -H "Authorization: token ${GITHUB_TOKEN}" \ -H "Content-Type: application/json" \ -d '{"state":"closed"}' \ "${{ github.api_url }}/repos/${{ github.repository }}/issues/${ISSUE_NUMBER}" # Add a comment curl -X POST \ -H "Authorization: token ${GITHUB_TOKEN}" \ -H "Content-Type: application/json" \ -d "{\"body\":\"Automatically closed by PR #${{ github.event.pull_request.number }}\"}" \ "${{ github.api_url }}/repos/${{ github.repository }}/issues/${ISSUE_NUMBER}/comments" echo "Issue #$ISSUE_NUMBER has been closed" else echo "Branch name does not match expected format (issue-NUMBER-title)" fi