Skip to content

Automated Label

Automated Label #1024

Workflow file for this run

name: Automated Label
on:
schedule:
- cron: '0 */1 * * *'
issues:
types: [opened, edited]
pull_request:
types: [opened, synchronize]
workflow_dispatch:
jobs:
label_pull_requests:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.state == 'open' && github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' }}
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Label Pull Requests
if: github.event_name == 'pull_request'
uses: actions/labeler@v5
with:
repo-token: ${{ secrets.BOT_TOKEN }}
label_issues:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Label Issues
if: github.event_name == 'issues'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.BOT_TOKEN }}
script: |
const issue = context.payload.issue;
const labels = [];
const title = issue.title.toLowerCase();
const body = issue.body ? issue.body.toLowerCase() : '';
const labelMapping = [
{label: 'algorithm', match: ['Algorithm/*']},
{label: 'asm', match: ['**/*.asm']},
{label: 'c/c++', match: ['C++/*', '**/*.cpp', '**/*.hpp', '**/*.c++', '**/*.cxx', '**/*.ixx', 'C/*', '**/*.c', '**/*.h']},
{label: 'ci/cd', match: ['*.yml', '*.yaml', '.github/workflows/*.yml']},
{label: 'documentation', match: ['**/*.md', '.github/*.md']},
{label: 'shell', match: ['**/*.sh', 'Bash/*']},
{label: 'pr_template', match: ['.github/PULL_REQUEST_TEMPLATE.md', '.github/PR_BOT_TEMPLATE.md']},
{label: 'unknown', match: ['**/*.py', '**/*.toml', '**/*.php', '**/*.js', '**/*.ts', '**/*.rs']},
{label: 'dotfiles', match: ['CODEOWNERS', '.gitignore', '.gitattributes', 'LICENSE']},
{label: 'issue', match: ['issue', 'bug']},
{label: 'feature', match: ['feature', 'request', 'required', 'enhance', 'improve']}
];
let matched = false;
labelMapping.forEach(({label, match}) => {
if (match.some(keyword => title.includes(keyword) || body.includes(keyword))) {
labels.push(label);
matched = true;
}
});
if (!matched) {
labels.push('unknown');
}
if (labels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: labels
});
}
finish_cleanup:
runs-on: ubuntu-latest
needs: [label_pull_requests, label_issues]
steps:
- name: Finish Off & Cleanup
run: echo "Successfully labeled all of the open issues and pull requests."