add ci-cd.yml #42
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
name: Auto Labeler | |
on: | |
issues: | |
types: [opened, edited] | |
pull_request: | |
types: [opened, edited] | |
jobs: | |
labeler: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Git credentials | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-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); | |
try { | |
if (labels.length > 0) { | |
await github.rest.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue.number, | |
labels: labels | |
}); | |
console.log('Labels added successfully.'); | |
} else { | |
console.log('No labels to add.'); | |
} | |
} catch (error) { | |
console.error('Error adding labels:', error); | |
throw error; | |
} | |
- name: Log output | |
run: echo ${{ steps.add_labels.outputs.output }} |