neovim/.github/workflows/labeler.yml
2022-02-09 10:47:14 +01:00

125 lines
3.5 KiB
YAML

name: "Pull Request Labeler"
on:
pull_request_target:
types: [opened]
jobs:
triage:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/labeler@main
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
type-scope:
runs-on: ubuntu-latest
needs: ["triage"]
permissions:
contents: write
pull-requests: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
steps:
- name: "Extract commit type and add as label"
continue-on-error: true
run: gh pr edit "$PR_NUMBER" --add-label "$(echo "$PR_TITLE" | sed -E 's|([[:alpha:]]+)(\(.*\))?!?:.*|\1|')"
- name: "Extract commit scope and add as label"
continue-on-error: true
run: gh pr edit "$PR_NUMBER" --add-label "$(echo "$PR_TITLE" | sed -E 's|[[:alpha:]]+\((.+)\)!?:.*|\1|')"
add-reviewer:
runs-on: ubuntu-latest
needs: ["triage", "type-scope"]
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v5
with:
script: |
const reviewers = []
const { data: { labels } } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
const label_names = labels.map(label => label.name)
if (label_names.includes('api')) {
reviewers.push("bfredl")
reviewers.push("gpanders")
reviewers.push("muniter")
}
if (label_names.includes('ci')) {
reviewers.push("jamessan")
}
if (label_names.includes('diagnostic')) {
reviewers.push("gpanders")
}
if (label_names.includes('distribution')) {
reviewers.push("jamessan")
}
if (label_names.includes('documentation')) {
reviewers.push("clason")
}
if (label_names.includes('extmarks')) {
reviewers.push("bfredl")
}
if (label_names.includes('filetype')) {
reviewers.push("clason")
reviewers.push("gpanders")
}
if (label_names.includes('gui')) {
reviewers.push("glacambre")
reviewers.push("smolck")
}
if (label_names.includes('lsp')) {
reviewers.push("mfussenegger")
reviewers.push("mjlbach")
}
if (label_names.includes('treesitter')) {
reviewers.push("bfredl")
reviewers.push("vigoux")
}
if (label_names.includes('typo')) {
reviewers.push("dundargoc")
}
if (label_names.includes('ui')) {
reviewers.push("bfredl")
}
if (label_names.includes('vim-patch')) {
reviewers.push("janlazo")
reviewers.push("seandewar")
reviewers.push("zeertzjq")
}
const index = reviewers.indexOf(context.actor);
if (index > -1) {
reviewers.splice(index, 1);
}
github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
reviewers: reviewers
});