You've already forked devops-pipeline-template
first commit
This commit is contained in:
52
.gitea/workflows/issue-branch-management.yml
Normal file
52
.gitea/workflows/issue-branch-management.yml
Normal file
@@ -0,0 +1,52 @@
|
||||
name: Issue Branch Management (Template)
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
secrets:
|
||||
GITHUB_TOKEN:
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
manage-branch:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Create branch on issue open or reopen
|
||||
if: github.event.action == 'opened' || github.event.action == 'reopened'
|
||||
run: |
|
||||
ISSUE_NUMBER=${{ github.event.issue.number }}
|
||||
ISSUE_TITLE="${{ github.event.issue.title }}"
|
||||
|
||||
BRANCH_NAME="issue-${ISSUE_NUMBER}-$(echo "$ISSUE_TITLE" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr -cd '[:alnum:]-' | head -c 50)"
|
||||
|
||||
echo "Creating branch: $BRANCH_NAME"
|
||||
|
||||
git config user.name "gitea-actions[bot]"
|
||||
git config user.email "gitea-actions[bot]@gitea"
|
||||
|
||||
if git ls-remote --exit-code --heads origin "$BRANCH_NAME" > /dev/null 2>&1; then
|
||||
echo "Branch already exists: $BRANCH_NAME"
|
||||
else
|
||||
git checkout -b "$BRANCH_NAME"
|
||||
git push origin "$BRANCH_NAME"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user