Skip to content

Commit

Permalink
Modify Labeler.
Browse files Browse the repository at this point in the history
  • Loading branch information
offensive-vk authored Aug 31, 2024
1 parent 4da35a6 commit 8f9f6d8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 52 deletions.
21 changes: 11 additions & 10 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,33 @@ algorithm:
asm:
- '**/*.asm'

c:
- C/*
- '**/*.c'

c++:
c/c++:
- C++/*
- '**/*.cpp'
- '**/*.hpp'
- '**/*.c++'
- '**/*.cxx'
- '**/*.ixx'
- C/*
- '**/*.c'
- '**/*.h'

ci/cd:
- '*.yml'
- '*.yaml'
- .github/workflows/*.yml

documentation:
- '**/*.md'
- .github/*

docs:
- '**/*.md'
- .github/*.md

shell:
- '**/*.sh'
- Bash/*

pr_template:
- .github/PULL_REQUEST_TEMPLATE.md
- .github/pr-bot-template.md
- .github/PR_BOT_TEMPLATE.md

unknown:
- '**/*.py'
Expand All @@ -41,6 +39,9 @@ unknown:
- '**/*.js'
- '**/*.ts'
- '**/*.rs'

dotfiles:
- 'CODEOWNERS'
- '.gitignore'
- '.gitattributes'
- 'LICENSE'
96 changes: 54 additions & 42 deletions .github/workflows/label.yml
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."

0 comments on commit 8f9f6d8

Please sign in to comment.