forked from django/django
-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (52 loc) · 1.86 KB
/
labels.yml
File metadata and controls
56 lines (52 loc) · 1.86 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
name: Labels
on:
pull_request_target:
types: [ edited, opened, reopened, ready_for_review ]
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
pull-requests: write
jobs:
no_ticket:
# Only trigger on the main Django repository
if: github.repository == 'django/django'
name: "Flag if no Trac ticket is found in the title"
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: "Check title and manage labels"
uses: actions/github-script@v8
with:
script: |
const title = context.payload.pull_request.title;
const regex = /#[0-9]+[ ,:]?/gm;
const label = "no ticket";
const hasMatch = regex.test(title);
const labels = context.payload.pull_request.labels.map(l => l.name);
const owner = context.repo.owner;
const repo = context.repo.repo;
const pr_number = context.payload.pull_request.number;
console.log(`=> Pull Request Title: ${title}`);
console.log(`=> Labels on PR: [${labels}]`);
if (hasMatch && labels.includes(label)) {
console.log(`==> Removing label "${label}" from PR #${pr_number}`);
await github.rest.issues.removeLabel({
owner,
repo,
issue_number: pr_number,
name: label
});
} else if (!hasMatch && !labels.includes(label)) {
console.log(`==> Adding label "${label}" to PR #${pr_number}`);
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pr_number,
labels: [label]
});
} else {
console.log(`No action needed for PR #${pr_number}`);
}