Skip to content

chore: dont add label when commit is not a pull request #8

chore: dont add label when commit is not a pull request

chore: dont add label when commit is not a pull request #8

Workflow file for this run

name: Label PRs based on commit messages!
on:
push:
jobs:
labelPR:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install GitHub CLI
run: |
curl -OL https://github.com/cli/cli/releases/download/v2.4.0/gh_2.4.0_linux_amd64.deb
sudo dpkg -i gh_2.4.0_linux_amd64.deb
- name: Get PR number
id: pr_number
run: |
PR_NUMBER=$(gh pr list --json number,headRefName --jq ".[] | select(.headRefName == \"${{ github.ref }}\") | .number")
echo "::set-output name=number::$PR_NUMBER"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Add label
run: |
COMMIT_MSG=$(git log --format=%B -n 1 ${{ github.sha }})
if [[ "$COMMIT_MSG" == fix:* ]]; then
gh pr edit ${{ steps.pr_number.outputs.number }} --add-label "fix"
elif [[ "$COMMIT_MSG" == feature:* ]]; then
gh pr edit ${{ steps.pr_number.outputs.number }} --add-label "feature"
elif [[ "$COMMIT_MSG" == chore:* ]]; then
gh pr edit ${{ steps.pr_number.outputs.number }} --add-label "chore"
elif [[ "$COMMIT_MSG" == enhancement:* ]]; then
gh pr edit ${{ steps.pr_number.outputs.number }} --add-label "enhancement"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: steps.pr_number.outputs.number != ''