diff --git a/.github/workflows/auto-label-conventional-commits.yaml b/.github/workflows/auto-label-conventional-commits.yaml index a2ac27452e..a1f7135fd7 100644 --- a/.github/workflows/auto-label-conventional-commits.yaml +++ b/.github/workflows/auto-label-conventional-commits.yaml @@ -1,9 +1,11 @@ name: "Auto Label Conventional Commits" on: issues: - types: [opened] + - reopened + - opened pull_request: - types: [opened] + - reopened + - opened jobs: label_issues: runs-on: ubuntu-latest @@ -11,36 +13,25 @@ jobs: issues: write pull-requests: write steps: - - uses: actions/github-script@v5 - with: - script: | - const github = require('@actions/github'); - const core = require('@actions/core'); - const token = core.getInput('github-token', { required: true }); - const octokit = github.getOctokit(token); - - const title = context.payload.issue ? context.payload.issue.title : context.payload.pull_request.title; - const labelMapping = { - 'feat:': 'type: feature request', - 'perf:': 'type: enhancement', - 'fix:': 'type: bug', - 'docs:': 'type: documentation', - 'ci:': 'type: ci', - 'build:': 'type: ci', - 'chore:': 'type: chore', - 'test:': 'type: chore', - 'style:': 'type: chore', - 'refactor:': 'type: chore', - }; - for (const [prefix, label] of Object.entries(labelMapping)) { - if (title.startsWith(prefix)) { - const issue_number = context.payload.issue ? context.issue.number : context.payload.pull_request.number; - octokit.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue_number, - labels: [label], - }); - break; - } - } + - name: Label issues + run: | + ISSUE_TITLE=$(gh issue view ${{ github.event.issue.number }} --json title -q ".title") + if [[ $ISSUE_TITLE == chore* ]]; then + gh issue edit ${{ github.event.issue.number }} --add-label "type: chore" + elif [[ $ISSUE_TITLE == feat* ]]; then + gh issue edit ${{ github.event.issue.number }} --add-label "type: feat" + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# const labelMapping = { +# 'feat:': 'type: feature request', +# 'perf:': 'type: enhancement', +# 'fix:': 'type: bug', +# 'docs:': 'type: documentation', +# 'ci:': 'type: ci', +# 'build:': 'type: ci', +# 'chore:': 'type: chore', +# 'test:': 'type: chore', +# 'style:': 'type: chore', +# 'refactor:': 'type: chore', +# };