-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* multiple tests * update * logging * more logging * remove logging * update README
- Loading branch information
1 parent
574e3d1
commit e2639a0
Showing
4 changed files
with
93 additions
and
30 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,19 +1,36 @@ | ||
# pr-has-one-of-labels | ||
Github Action to check if a PR has at least one of the provided labels | ||
# PR Labels Checker | ||
Github Action to check if a PR's labels pass the specified rules | ||
|
||
Example workflow file: | ||
## Input | ||
- `hasSome`: Comma separated list of labels, PR needs at least of them | ||
- `hasAll`: Comma separated list of labels, PR needs all of them | ||
- `hasNone`: Comma separated list of labels, PR must not have any of them | ||
- `hasNotAll`: Comma separated list of labels, PR must not have all of them | ||
|
||
## Output | ||
- `passed`: boolean | ||
|
||
## Example workflow file | ||
```yml | ||
name: QA Labels Check | ||
name: Labels Check | ||
on: | ||
pull_request: | ||
types: [opened, edited, labeled, unlabeled, synchronize] | ||
jobs: | ||
QA-check: | ||
if: github.base_ref == 'develop' | ||
if: github.base_ref == 'master' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: danielchabr/pr-has-one-of-labels@master | ||
id: checkLabel | ||
with: | ||
hasSome: QA:tested,QA:skipped | ||
Do_not_merge-check: | ||
if: github.base_ref == 'master' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: danielchabr/pr-has-one-of-labels@master | ||
id: checkLabel | ||
with: | ||
labels: QA:tested,QA:skipped | ||
hasNone: do not merge,blocked | ||
``` |
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
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,24 +1,61 @@ | ||
const core = require('@actions/core') | ||
const github = require('@actions/github') | ||
|
||
const labelsInput = core.getInput('labels') | ||
const hasSomeInput = core.getInput('hasSome') | ||
const hasAllInput = core.getInput('hasAll') | ||
const hasNoneInput = core.getInput('hasNone') | ||
const hasNotAllInput = core.getInput('hasNotAll') | ||
|
||
const labels = labelsInput.split(',') | ||
const hasSomeLabels = hasSomeInput.split(',') | ||
const hasAllLabels = hasAllInput.split(',') | ||
const hasNoneLabels = hasNoneInput.split(',') | ||
const hasNotAllLabels = hasNotAllInput.split(',') | ||
|
||
const hasLabel = github.context.payload.pull_request.labels.some((item) => | ||
labels.includes(item.name) | ||
const failMessages = [] | ||
const prLabels = github.context.payload.pull_request.labels.map(item => item.name) | ||
|
||
const hasSomeResult = !hasSomeInput || hasSomeLabels.some((label) => | ||
prLabels.includes(label) | ||
) | ||
|
||
if (!hasLabel) { | ||
core.setFailed( | ||
`The PR needs to have one of the following labels to pass this check: ${labels.join( | ||
', ' | ||
)}` | ||
) | ||
} | ||
const hasAllResult = !hasAllInput || hasAllLabels.every((label) => | ||
prLabels.includes(label) | ||
) | ||
|
||
core.setOutput('hasLabel', hasLabel) | ||
const hasNoneResult = !hasNoneInput || hasNoneLabels.every((label) => | ||
!prLabels.includes(label) | ||
) | ||
|
||
console.log( | ||
`Does PR have one of '${labels.join(', ')}' labels?: ${hasLabel}` | ||
const hasNotAllResult = !hasNotAllInput || hasNotAllLabels.some((label) => | ||
!prLabels.includes(label) | ||
) | ||
|
||
if (!hasSomeResult) { | ||
failMessages.push(`The PR needs to have at least one of the following labels to pass this check: ${hasSomeLabels.join( | ||
', ' | ||
)}`) | ||
} | ||
|
||
if (!hasAllResult) { | ||
failMessages.push(`The PR needs to have all of the following labels to pass this check: ${hasAllLabels.join( | ||
', ' | ||
)}`) | ||
} | ||
|
||
if (!hasNoneResult) { | ||
failMessages.push(`The PR needs to have none of the following labels to pass this check: ${hasNoneLabels.join( | ||
', ' | ||
)}`) | ||
} | ||
|
||
if (!hasNotAllResult) { | ||
failMessages.push(`The PR needs to not have at least one of the following labels to pass this check: ${hasNotAllLabels.join( | ||
', ' | ||
)}`) | ||
} | ||
|
||
if (failMessages.length) { | ||
core.setFailed(failMessages.join('. ')) | ||
} | ||
|
||
core.setOutput('passed', failMessages.length === 0) |
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