-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Label Configuration. (Workflow)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
16a3ee4
commit ff2a6d0
Showing
1 changed file
with
54 additions
and
42 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,78 +1,90 @@ | ||
name: Automated Label Issues and PRs | ||
name: CI / Automated Label | ||
|
||
on: | ||
schedule: | ||
- cron: '0 */1 * * *' | ||
issues: | ||
types: [opened, edited] | ||
pull_request: | ||
types: [opened, synchronize] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
label: | ||
label_issues: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
issues: write | ||
pull-requests: write | ||
|
||
steps: | ||
- name: Label PRs | ||
uses: actions/labeler@v4 | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Label Issues | ||
if: github.event_name == 'issues' | ||
uses: actions/github-script@v3 | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
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() : ''; | ||
// Match keywords to apply labels based on your labeler.yml configuration | ||
if (title.includes('algorithm') || body.includes('algorithm')) { | ||
labels.push('algorithm'); | ||
} | ||
if (title.includes('.asm') || body.includes('.asm')) { | ||
labels.push('asm'); | ||
} | ||
if (title.includes('.c') || body.includes('.c')) { | ||
labels.push('c'); | ||
} | ||
if (title.includes('.cpp') || title.includes('.c++') || title.includes('.cxx') || title.includes('.ixx') || | ||
body.includes('.cpp') || body.includes('.c++') || body.includes('.cxx') || body.includes('.ixx')) { | ||
labels.push('c++'); | ||
} | ||
if (title.includes('.yml') || body.includes('.yml')) { | ||
labels.push('ci/cd'); | ||
} | ||
if (title.includes('.md') || body.includes('.md')) { | ||
labels.push('documentation'); | ||
labels.push('docs'); | ||
} | ||
if (title.includes('.sh') || body.includes('.sh')) { | ||
labels.push('shell'); | ||
} | ||
if (title.includes('.py') || body.includes('.py') || | ||
title.includes('.toml') || body.includes('.toml') || | ||
title.includes('.php') || body.includes('.php') || | ||
title.includes('.js') || body.includes('.js') || | ||
title.includes('.ts') || body.includes('.ts') || | ||
title.includes('.rs') || body.includes('.rs')) { | ||
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: ['ci/cd', 'pipeline', 'workflow', '.yml', 'dockerfile', 'compose.yaml']}, | ||
{label: 'documentation', match: ['**/*.md', '.github/*.md']}, | ||
{label: 'pr_template', match: ['.github/pull-request-template.md', '.github/pr-bot-template.md']}, | ||
{label: 'dotfiles', match: ['.gitignore', '.gitattributes', 'license']}, | ||
{label: 'shell', match: ['**/*.sh', 'bash/*']}, | ||
{label: 'offensive-vk', match: ['offensive-vk', 'vedansh', 'admin', 'me', 'context', 'Classics']}, | ||
{label: 'unknown', match: ['**/*.py', '**/*.toml', '**/*.php', '**/*.js', '**/*.ts', '**/*.rs']} | ||
]; | ||
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'); | ||
} | ||
// Apply the labels to the issue | ||
if (labels.length > 0) { | ||
github.issues.addLabels({ | ||
await github.rest.issues.addLabels({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue.number, | ||
labels: labels | ||
}); | ||
} | ||
label_pull_requests: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Label Pull Requests | ||
if: github.event_name == 'pull_request' | ||
uses: actions/labeler@v4 | ||
with: | ||
repo-token: ${{ secrets.BOT_TOKEN }} | ||
|
||
finish_cleanup: | ||
runs-on: ubuntu-latest | ||
needs: [label_issues, label_pull_requests] | ||
steps: | ||
- name: Finish Off & Cleanup | ||
run: | | ||
echo "Sucessfully Labeled All of the Open Issues and Pull Requests." | ||
run: echo "Successfully labeled all of the open issues and pull requests." |