-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
59 lines (53 loc) · 1.83 KB
/
Copy pathprs-check-label-title-sync.yml
File metadata and controls
59 lines (53 loc) · 1.83 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
57
58
59
name: Check PR labels and title sync
on:
pull_request:
types: [opened, reopened, labeled, unlabeled, edited, synchronize]
permissions: {}
jobs:
check_label_title_sync:
runs-on: ubuntu-latest
name: Check label and title sync
steps:
- name: Check label matches title
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const pr = context.payload.pull_request;
const title = pr.title.toLowerCase();
const existingLabels =
pr.labels?.map((label) => label.name.toLowerCase()) || [];
const titleLabels = Array.from(
title.matchAll(/(?:\[([^\]]+)\])/g),
(match) => match[1]
);
const expectedLabelsFromTitle = titleLabels
.map((label) => {
if (label.endsWith("-pro")) {
return "plan: Pro";
}
if (label.endsWith("-premium")) {
return "plan: Premium";
}
if (label === "docs") {
return "docs";
}
return null;
})
.filter(Boolean);
if (expectedLabelsFromTitle.length === 0) {
return;
}
const missingLabels = expectedLabelsFromTitle.filter(
(label) => !existingLabels.includes(label.toLowerCase())
);
if (
missingLabels.length > 0
) {
core.setFailed(
`Title indicates labels that are missing: [${missingLabels.join(
", "
)}]. Please add them to the PR labels.`
);
} else {
core.info('No missing labels detected based on title.');
}