@@ -15,27 +15,31 @@ jobs:
15
15
const { owner, repo, number: issue_number } = context.issue;
16
16
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number });
17
17
const title = pr.data.title;
18
- const labRegex = /\[LAB(\d+)\]/;
19
- const titleRegex = /^\[LAB\d+\] [\da-zA-Z]+$/;
20
18
21
- if (!titleRegex.test(title)) {
22
- core.setFailed('PR title does not match the required format. Please use the format [LAB#] student#.');
19
+ const titleRegex = /^\[LAB(\d+)\] [a-zA-Z]?\d+$/;
20
+ const match = title.match(titleRegex);
21
+
22
+ let labNumberStr = undefined;
23
+ if (match) {
24
+ labNumberStr = match[1];
25
+ } else {
26
+ core.setFailed('PR title does not match the required format. Please use the format: [LAB#] <studentId>.');
23
27
}
24
28
25
- if (pr.data.head.ref !== pr.data.base.ref) {
26
- core.setFailed('The source branch and target branch must be the same.');
29
+ const labelToAdd = `lab${labNumberStr}`;
30
+ if (labNumberStr) {
31
+ await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [labelToAdd] });
27
32
}
28
33
29
34
if (pr.data.base.ref === 'main') {
30
35
core.setFailed('The target branch cannot be main.');
31
36
}
32
37
33
- const match = title.match(labRegex);
34
- if (match) {
35
- const labelToAdd = 'lab' + match[1];
36
- await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [labelToAdd] });
37
- } else {
38
- core.setFailed('No match found in PR title. Please add a label in the format [LAB#] to the PR title.');
38
+ if (labNumberStr < 3 && pr.data.head.ref !== pr.data.base.ref) {
39
+ core.setFailed('The source branch and target branch must be the same.');
40
+ }
41
+ if (labNumberStr >= 3 && pr.data.head.ref !== labelToAdd) {
42
+ core.setFailed(`The source branch must be '${labelToAdd}'`);
39
43
}
40
44
checklist-check :
41
45
runs-on : ubuntu-latest
@@ -49,12 +53,12 @@ jobs:
49
53
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number });
50
54
const body = pr.data.body;
51
55
52
- const checkboxes = body.match(/\- \[[x ]\]/g );
56
+ const checkboxes = body.match(/^ ?(-|\*) \[[x ]\]/gmi );
53
57
if (!checkboxes || checkboxes.length !== 5) {
54
58
core.setFailed('The PR description must contain exactly 5 checkboxes.');
55
59
}
56
60
57
- const unchecked = body.match(/\- \[ \]/g );
61
+ const unchecked = body.match(/^ ?(-|\*) \[ \]/gm );
58
62
if (unchecked && unchecked.length > 0) {
59
- core.setFailed(`There are ${unchecked.length} unchecked items in the PR description.`);
63
+ core.setFailed(`There are ${unchecked.length} unchecked item(s) in the PR description.`);
60
64
}
0 commit comments