chore(ci): auto label #2
Workflow file for this run
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
name: Label Issues | |
on: | |
issues: | |
types: | |
- opened | |
- reopened | |
- edited | |
pull_request: | |
types: | |
- opened | |
- reopened | |
- edited | |
jobs: | |
label_issue: | |
runs-on: ubuntu-latest | |
permissions: | |
issues: write | |
steps: | |
- name: Label issues and pull requests based on title | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const payload = context.payload; | |
const isIssue = !!payload.issue; | |
const title = isIssue ? payload.issue.title : payload.pull_request.title; | |
const number = isIssue ? payload.issue.number : payload.pull_request.number; | |
const labels = []; | |
// 获取仓库中的所有标签 | |
const repoLabels = await github.paginate(github.issues.listLabelsForRepo, { | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
// 遍历仓库中的标签,根据标题添加标签 | |
for (const label of repoLabels) { | |
if (title.toLowerCase().includes(label.name.toLowerCase())) { | |
labels.push(label.name); | |
} | |
} | |
if (labels.length > 0) { | |
await github.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: number, | |
labels: labels | |
}); | |
} |