Skip to content

Commit 0381295

Browse files
authored
Update validate-pr-title script (#66)
Signed-off-by: Gray Campbell <[email protected]>
1 parent d243d13 commit 0381295

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

.github/scripts/validate-pr-title.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const nlp = require('compromise')
2-
const title = process.env.PR_TITLE || ''
1+
const nlp = require('compromise');
2+
const title = process.env.PR_TITLE || '';
33

4-
let isValidTitle = true
4+
let isValidTitle = true;
55

66
function logSuccess(message) {
7-
console.log(`✅ ${message}`)
7+
console.log(`✅ ${message}`);
88
}
99

1010
function logFailure(message) {
11-
isValidTitle = false
12-
console.error(`❌ ${message}`)
11+
isValidTitle = false;
12+
console.error(`❌ ${message}`);
1313
}
1414

1515
function capitalized(string) {
@@ -19,48 +19,48 @@ function capitalized(string) {
1919

2020
// Rule 1: PR title must not be empty
2121
if (title) {
22-
logSuccess(`PR title is not empty`)
22+
logSuccess(`PR title is not empty`);
2323
} else {
24-
logFailure(`PR title must not be empty`)
24+
logFailure(`PR title must not be empty`);
2525
}
2626

2727
// Rule 2: PR title must be 72 characters or less
2828
if (title.length <= 72) {
29-
logSuccess(`PR title is ${title.length} characters`)
29+
logSuccess(`PR title is ${title.length} characters`);
3030
} else {
31-
logFailure(`PR title must be 72 characters or less (currently ${title.length} characters)`)
31+
logFailure(`PR title must be 72 characters or less (currently ${title.length} characters)`);
3232
}
3333

3434
// Rule 3: PR title must begin with a capital letter
3535
if (/^[A-Z]/.test(title)) {
36-
logSuccess(`PR title begins with a capital letter`)
36+
logSuccess(`PR title begins with a capital letter`);
3737
} else {
38-
logFailure('PR title must begin with a capital letter')
38+
logFailure('PR title must begin with a capital letter');
3939
}
4040

4141
// Rule 4: PR title must end with a letter or number
4242
if (/[A-Za-z0-9]$/.test(title)) {
43-
logSuccess(`PR title ends with a letter or number`)
43+
logSuccess(`PR title ends with a letter or number`);
4444
} else {
45-
logFailure('PR title must end with a letter or number')
45+
logFailure('PR title must end with a letter or number');
4646
}
4747

4848
// Rule 5: PR title must be written in the imperative
49-
const firstWord = title.split(' ')[0]
50-
const firstWordLowercased = firstWord.toLowerCase()
51-
const firstWordCapitalized = capitalized(firstWord)
52-
const firstWordAsImperativeVerb = nlp(firstWord).verbs().toInfinitive().out('text')
53-
const firstWordAsImperativeVerbLowercased = firstWordAsImperativeVerb.toLowerCase()
54-
const firstWordAsImperativeVerbCapitalized = capitalized(firstWordAsImperativeVerb)
49+
const firstWord = title.split(' ')[0];
50+
const firstWordLowercased = firstWord.toLowerCase();
51+
const firstWordCapitalized = capitalized(firstWord);
52+
const firstWordAsImperativeVerb = nlp(firstWord).verbs().toInfinitive().out('text');
53+
const firstWordAsImperativeVerbLowercased = firstWordAsImperativeVerb.toLowerCase();
54+
const firstWordAsImperativeVerbCapitalized = capitalized(firstWordAsImperativeVerb);
5555

5656
if (firstWordLowercased === firstWordAsImperativeVerbLowercased) {
57-
logSuccess(`PR title is written in the imperative`)
57+
logSuccess(`PR title is written in the imperative`);
5858
} else if (firstWordAsImperativeVerb) {
59-
logFailure(`PR title must be written in the imperative ("${firstWordAsImperativeVerbCapitalized}" instead of "${firstWordCapitalized}")`)
59+
logFailure(`PR title must be written in the imperative ("${firstWordAsImperativeVerbCapitalized}" instead of "${firstWordCapitalized}")`);
6060
} else {
61-
logFailure(`PR title must begin with a verb and be written in the imperative`)
61+
logFailure(`PR title must begin with a verb and be written in the imperative`);
6262
}
6363

6464
if (!isValidTitle) {
65-
process.exit(1)
65+
process.exit(1);
6666
}

0 commit comments

Comments
 (0)