diff --git a/pull_request_template.md b/.github/pull_request_template.md similarity index 73% rename from pull_request_template.md rename to .github/pull_request_template.md index 7c051c4..66226e7 100644 --- a/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,3 +1 @@ -> Always leave the code behind in a better state than you found it. - -Closes # \ No newline at end of file +> Always leave the code behind in a better state than you found it. \ No newline at end of file diff --git a/.github/workflow/link-pr-issue.yml b/.github/workflow/link-pr-issue.yml deleted file mode 100644 index d5fef65..0000000 --- a/.github/workflow/link-pr-issue.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Link PR to Issue - -on: - pull_request: - types: [opened, edited] - -jobs: - link-issue: - runs-on: ubuntu-latest - steps: - - name: Extract Issue ID from PR Title - id: extract - run: | - issue_id=$(echo ${{ github.event.pull_request.title }} | grep -oP '\(\K[0-9]+(?=\))') - echo "issue_id=$issue_id" >> $GITHUB_ENV - - - name: Check if Issue ID Exists - id: check - run: | - if [ -z "${{ env.issue_id }}" ]; then - echo "No issue ID found in PR title." - exit 1 - fi - - - name: Update PR Description - if: steps.check.outcome == 'success' - run: | - gh pr edit ${{ github.event.pull_request.number }} --body "${{ github.event.pull_request.body }}\nCloses #${{ env.issue_id }}" diff --git a/.github/workflows/link-pr-issue.yml b/.github/workflows/link-pr-issue.yml new file mode 100644 index 0000000..51b7f19 --- /dev/null +++ b/.github/workflows/link-pr-issue.yml @@ -0,0 +1,46 @@ +name: link pr to issue + +on: + pull_request: + types: [opened, edited, reopened] + branch_protection_rule: + types: [edited] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + link-issue: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Extract branch name + shell: bash + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + run: | + issue_id=$(echo ${{ env.BRANCH_NAME }} | grep -oE '[0-9]+$') + echo "issue_id=$issue_id" >> $GITHUB_ENV + + - name: Check if Issue ID Exists + id: check + run: | + if [ -z "${{ env.issue_id }}" ]; then + echo "No issue ID found in branch name." + exit 1 + fi + + - name: Update PR Description + if: steps.check.outcome == 'success' + env: + GH_TOKEN: ${{ github.token }} + run: | + gh pr edit ${{ github.event.pull_request.number }} --body "$(cat << EOF + > Always leave the code behind in a better state than you found it. + + Closes #${{ env.issue_id }} + EOF + )" diff --git a/tools/scripts/create-branch.sh b/tools/scripts/create-branch.sh index ffa24d0..a696b4a 100755 --- a/tools/scripts/create-branch.sh +++ b/tools/scripts/create-branch.sh @@ -15,6 +15,8 @@ read -p "Your choice: " choice read -p "Enter the branch name: " branch_name +read -p "Enter the issue id: " issue_id + case $choice in 1) prefix="feat" @@ -34,7 +36,9 @@ case $choice in ;; esac -full_branch_name="${prefix}/${branch_name}" +branch_name_with_hyphen=$(echo "$branch_name" | sed 's/ /-/g') + +full_branch_name="${prefix}/${branch_name_with_hyphen}-${issue_id}" git checkout -b "$full_branch_name"