-
-
Notifications
You must be signed in to change notification settings - Fork 2
43 lines (37 loc) · 1.43 KB
/
add-invalid-label.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
name: Handle Low Quality Label
on:
issues:
types: [labeled]
pull_request:
types: [labeled]
jobs:
asign_invalid_label:
runs-on: ubuntu-latest
steps:
- name: Check and Handle Low Quality Label
if: ${{ github.event.label.name == 'low quality' }}
uses: actions/github-script@v6
with:
script: |
const labelToAdd = 'invalid';
const issue_number = context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number;
const existingLabels = context.payload.issue ? context.payload.issue.labels : context.payload.pull_request.labels;
const labelExists = existingLabels.some(label => label.name === labelToAdd);
if (!labelExists) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
labels: [labelToAdd]
});
console.log(`Label "${labelToAdd}" added to issue/pr #${issue_number}.`);
} else {
console.log(`Label "${labelToAdd}" already exists on issue/pr #${issue_number}. No action taken.`);
}
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
state: 'closed'
});
console.log(`Issue/PR #${issue_number} closed.`);