Skip to content

Commit

Permalink
try gh
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSage committed Dec 1, 2023
1 parent 34d3846 commit 0b5fd34
Showing 1 changed file with 26 additions and 35 deletions.
61 changes: 26 additions & 35 deletions .github/workflows/auto-label-conventional-commits.yaml
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',
# };

0 comments on commit 0b5fd34

Please sign in to comment.