diff --git a/.gitea/workflows/issue-branch-management.yml b/.gitea/workflows/issue-branch-management.yml index 9d2e0d5..98c8839 100644 --- a/.gitea/workflows/issue-branch-management.yml +++ b/.gitea/workflows/issue-branch-management.yml @@ -38,15 +38,3 @@ jobs: echo "Branch created: $BRANCH_NAME" fi - - name: Delete branch on issue close - if: github.event.action == 'closed' - run: | - ISSUE_NUMBER=${{ github.event.issue.number }} - - echo "Searching branches for issue-${ISSUE_NUMBER}-*" - - for branch in $(git ls-remote --heads origin | grep "refs/heads/issue-${ISSUE_NUMBER}-" | awk '{print $2}' | sed 's|refs/heads/||'); do - echo "Deleting branch: $branch" - git push origin --delete "$branch" || echo "Failed to delete $branch" - done - diff --git a/.gitea/workflows/pr-close-issue.yml b/.gitea/workflows/pr-close-issue.yml new file mode 100644 index 0000000..723b4a3 --- /dev/null +++ b/.gitea/workflows/pr-close-issue.yml @@ -0,0 +1,35 @@ +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: + GH_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 + gh issue close "$ISSUE_NUMBER" --comment "Automatically closed by PR #${{ github.event.pull_request.number }}" + echo "Issue #$ISSUE_NUMBER has been closed" + else + echo "Branch name does not match expected format (issue-NUMBER-title)" + fi diff --git a/.gitea/workflows/pr-delete-branch.yml b/.gitea/workflows/pr-delete-branch.yml new file mode 100644 index 0000000..8570c6f --- /dev/null +++ b/.gitea/workflows/pr-delete-branch.yml @@ -0,0 +1,30 @@ +name: PR Delete Branch (Template) + +on: + workflow_call: + secrets: + GITHUB_TOKEN: + required: true + +jobs: + delete-branch: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Delete merged branch + run: | + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" + echo "Deleting branch: $BRANCH_NAME" + + git config user.name "gitea-actions[bot]" + git config user.email "gitea-actions[bot]@gitea" + + git push origin --delete "$BRANCH_NAME" || echo "Failed to delete branch $BRANCH_NAME" + echo "Branch $BRANCH_NAME has been deleted"