-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0xSage
committed
Dec 1, 2023
1 parent
34d3846
commit 0b5fd34
Showing
1 changed file
with
26 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,37 @@ | ||
name: "Auto Label Conventional Commits" | ||
on: | ||
issues: | ||
types: [opened] | ||
- reopened | ||
- opened | ||
pull_request: | ||
types: [opened] | ||
- reopened | ||
- opened | ||
jobs: | ||
label_issues: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
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', | ||
# }; |