Stop PR in case of forbidden label (#8508)

* stop PR in case of forbidden label

* sync PR

* add tmp workflow

* add tmp workflow

* add tmp workflow

* checkout repo
This commit is contained in:
Maurizio Vitale
2023-04-24 16:10:11 +01:00
committed by GitHub
parent 40db12fd3c
commit 17631d0b48
2 changed files with 40 additions and 0 deletions

View File

@@ -449,6 +449,32 @@ jobs:
apa-proxy: ${{ matrix.e2e-test.apa-proxy }} apa-proxy: ${{ matrix.e2e-test.apa-proxy }}
deps: ${{ matrix.e2e-test.deps }} deps: ${{ matrix.e2e-test.deps }}
PR-forbidden-labels:
runs-on: ubuntu-latest
steps:
- id: checkoutRepo
name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: PR contains forbidden labels
id: pr-forbidden
uses: actions/github-script@v6
with:
script: |
const issueHasLabels = require('./scripts/github/update/check-issue-has-label.js');
const checkLabels = ['next version ➡️', 'do not merge🙅🏻'];
const hasLabel = await issueHasLabels({github, context, checkLabels})
if(hasLabel) {
core.setFailed('The PR contains a forbidden label! You are not allowed to merge until the label is there.');
}
- name: Check value after
run: |
echo "result ${{ toJson(steps.pr-forbidden.*.result) }}" && echo "result ${{ steps.pr-forbidden.*.result }}"
echo "result ${{ contains(toJson(steps.pr-forbidden.*.result), 'failure') }}"
finalize: finalize:
if: ${{ always() }} if: ${{ always() }}
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@@ -0,0 +1,14 @@
module.exports = async ({ github, context, checkLabels }) => {
const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const labels = issue.labels?.map(item => item.name);
if (checkLabels.some(i => labels.includes(i))) {
return true;
}
return false;
}