Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GitHub] Action to check labels #4079

Merged
merged 11 commits into from
Sep 3, 2023
42 changes: 42 additions & 0 deletions .github/workflows/label-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Label Checker
on:
pull_request:
types:
- opened
- synchronize
- reopened
- labeled
- unlabeled


jobs:

check_labels:
name: Check labels
runs-on: ubuntu-latest
steps:
- name: Check Labels and Add Comment
id: check_labels_and_comment
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get PR info: id and labels
const prNumber = context.payload.pull_request.number;
const labels = context.payload.pull_request.labels.map(label => label.name);

// If no descriptive label is set, add a comment in the PR and make the action check fail
if (!labels.includes('enhancement') && !labels.includes('deprecated') && !labels.includes('refactoring') && !labels.includes('pr: breaking') && !labels.includes('pr: clean') && !labels.includes('pr: fix') && !labels.includes('pr: new feature') && !labels.includes('pr: test')) {
hugtalbot marked this conversation as resolved.
Show resolved Hide resolved
const comment = ':warning: :warning: :warning:<br>@'+context.repo.owner+' your PR does not include any descriptive label :label:<br> Make sure to add an appropriate [PR label](https://github.com/sofa-framework/sofa/labels) before merge.<br>:warning: :warning: :warning:';
github.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
core.setFailed('Invalid PR label')
}

// Add all PR labels in log
console.log('Labels:', labels.join(', '));