1
- const nlp = require ( 'compromise' )
2
- const title = process . env . PR_TITLE || ''
1
+ const nlp = require ( 'compromise' ) ;
2
+ const title = process . env . PR_TITLE || '' ;
3
3
4
- let isValidTitle = true
4
+ let isValidTitle = true ;
5
5
6
6
function logSuccess ( message ) {
7
- console . log ( `✅ ${ message } ` )
7
+ console . log ( `✅ ${ message } ` ) ;
8
8
}
9
9
10
10
function logFailure ( message ) {
11
- isValidTitle = false
12
- console . error ( `❌ ${ message } ` )
11
+ isValidTitle = false ;
12
+ console . error ( `❌ ${ message } ` ) ;
13
13
}
14
14
15
15
function capitalized ( string ) {
@@ -19,48 +19,48 @@ function capitalized(string) {
19
19
20
20
// Rule 1: PR title must not be empty
21
21
if ( title ) {
22
- logSuccess ( `PR title is not empty` )
22
+ logSuccess ( `PR title is not empty` ) ;
23
23
} else {
24
- logFailure ( `PR title must not be empty` )
24
+ logFailure ( `PR title must not be empty` ) ;
25
25
}
26
26
27
27
// Rule 2: PR title must be 72 characters or less
28
28
if ( title . length <= 72 ) {
29
- logSuccess ( `PR title is ${ title . length } characters` )
29
+ logSuccess ( `PR title is ${ title . length } characters` ) ;
30
30
} 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)` ) ;
32
32
}
33
33
34
34
// Rule 3: PR title must begin with a capital letter
35
35
if ( / ^ [ A - Z ] / . test ( title ) ) {
36
- logSuccess ( `PR title begins with a capital letter` )
36
+ logSuccess ( `PR title begins with a capital letter` ) ;
37
37
} else {
38
- logFailure ( 'PR title must begin with a capital letter' )
38
+ logFailure ( 'PR title must begin with a capital letter' ) ;
39
39
}
40
40
41
41
// Rule 4: PR title must end with a letter or number
42
42
if ( / [ A - Z a - z 0 - 9 ] $ / . test ( title ) ) {
43
- logSuccess ( `PR title ends with a letter or number` )
43
+ logSuccess ( `PR title ends with a letter or number` ) ;
44
44
} else {
45
- logFailure ( 'PR title must end with a letter or number' )
45
+ logFailure ( 'PR title must end with a letter or number' ) ;
46
46
}
47
47
48
48
// 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 ) ;
55
55
56
56
if ( firstWordLowercased === firstWordAsImperativeVerbLowercased ) {
57
- logSuccess ( `PR title is written in the imperative` )
57
+ logSuccess ( `PR title is written in the imperative` ) ;
58
58
} 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 } ")` ) ;
60
60
} 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` ) ;
62
62
}
63
63
64
64
if ( ! isValidTitle ) {
65
- process . exit ( 1 )
65
+ process . exit ( 1 ) ;
66
66
}
0 commit comments