This commit is contained in:
0xSage 2023-12-01 14:15:54 +08:00
parent 34d3846e06
commit 0b5fd34137

View File

@ -1,9 +1,11 @@
name: "Auto Label Conventional Commits" name: "Auto Label Conventional Commits"
on: on:
issues: issues:
types: [opened] - reopened
- opened
pull_request: pull_request:
types: [opened] - reopened
- opened
jobs: jobs:
label_issues: label_issues:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -11,36 +13,25 @@ jobs:
issues: write issues: write
pull-requests: write pull-requests: write
steps: steps:
- uses: actions/github-script@v5 - name: Label issues
with: run: |
script: | ISSUE_TITLE=$(gh issue view ${{ github.event.issue.number }} --json title -q ".title")
const github = require('@actions/github'); if [[ $ISSUE_TITLE == chore* ]]; then
const core = require('@actions/core'); gh issue edit ${{ github.event.issue.number }} --add-label "type: chore"
const token = core.getInput('github-token', { required: true }); elif [[ $ISSUE_TITLE == feat* ]]; then
const octokit = github.getOctokit(token); gh issue edit ${{ github.event.issue.number }} --add-label "type: feat"
fi
const title = context.payload.issue ? context.payload.issue.title : context.payload.pull_request.title; env:
const labelMapping = { GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
'feat:': 'type: feature request', # const labelMapping = {
'perf:': 'type: enhancement', # 'feat:': 'type: feature request',
'fix:': 'type: bug', # 'perf:': 'type: enhancement',
'docs:': 'type: documentation', # 'fix:': 'type: bug',
'ci:': 'type: ci', # 'docs:': 'type: documentation',
'build:': 'type: ci', # 'ci:': 'type: ci',
'chore:': 'type: chore', # 'build:': 'type: ci',
'test:': 'type: chore', # 'chore:': 'type: chore',
'style:': 'type: chore', # 'test:': 'type: chore',
'refactor:': '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;
}
}