Skip to content

Github actions for more connectivity! #63

Github actions for more connectivity!

Github actions for more connectivity! #63

Workflow file for this run

name: Auto Labeler
on:
issues:
types: [opened, edited]
pull_request:
types: [opened, edited]
jobs:
labeler:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Label issues and PRs
id: add_labels
uses: actions/github-script@v6
with:
script: |
const issue = context.payload.issue || context.payload.pull_request;
if (!issue) {
console.log('No issue or pull request found.');
return;
}
console.log('Issue:', issue);
const labels = ['gssoc-ext', 'hacktoberfest', 'hacktoberfest-accepted', 'level?'];
// Define keywords and their associated labels
const labelMappings = {
'bug': 'bug',
'enhancement': 'enhancement',
'feature': 'feature',
'good first issue': 'good first issue',
'ui': 'ui',
'documentation': 'documentation',
'workflow': 'workflow',
'automation': 'automation',
// Add more mappings as needed
};
// Apply labels based on title or body content
for (const [keyword, label] of Object.entries(labelMappings)) {
if ((issue.title && issue.title.toLowerCase().includes(keyword)) ||
(issue.body && issue.body.toLowerCase().includes(keyword))) {
labels.push(label);
}
}
console.log('Labels to add:', labels);
if (labels.length > 0) {
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: labels
});
console.log('Labels added successfully.');
} catch (error) {
console.error('Error adding labels:', error);
throw error;
}
} else {
console.log('No labels to add.');
}
- name: Log output
run: echo ${{ steps.add_labels.outputs.output }}