1
- #!/usr/bin/env node
2
1
import execa from 'execa' ;
3
- import commitlint from '@commitlint/cli' ;
4
2
5
3
// Allow to override used bins for testing purposes
6
4
const GIT = process . env . TRAVIS_COMMITLINT_GIT_BIN || 'git' ;
7
- const COMMITLINT = process . env . TRAVIS_COMMITLINT_BIN ;
5
+ const COMMITLINT =
6
+ process . env . TRAVIS_COMMITLINT_BIN || require ( '@commitlint/cli' ) ;
8
7
9
8
const REQUIRED = [
10
9
'TRAVIS_COMMIT' ,
@@ -14,7 +13,7 @@ const REQUIRED = [
14
13
'TRAVIS_PULL_REQUEST_SLUG' ,
15
14
] ;
16
15
17
- const COMMIT = process . env . TRAVIS_COMMIT ;
16
+ const COMMIT = process . env . TRAVIS_COMMIT || '' ;
18
17
const REPO_SLUG = process . env . TRAVIS_REPO_SLUG ;
19
18
const PR_SLUG = process . env . TRAVIS_PULL_REQUEST_SLUG || REPO_SLUG ;
20
19
const RANGE = process . env . TRAVIS_COMMIT_RANGE ;
@@ -36,7 +35,7 @@ async function main() {
36
35
( ) => fetch ( { name : 'base' , url : `https://github.com/${ REPO_SLUG } .git` } ) ,
37
36
IS_PR
38
37
? ( ) => fetch ( { name : 'source' , url : `https://github.com/${ PR_SLUG } .git` } )
39
- : async ( ) => { } ,
38
+ : ( ) => Promise . resolve ( ) ,
40
39
] ) ;
41
40
42
41
// Restore stashed changes if any
@@ -54,11 +53,14 @@ async function main() {
54
53
}
55
54
}
56
55
57
- async function git ( args , options ) {
58
- return execa ( GIT , args , Object . assign ( { } , { stdio : 'inherit' } , options ) ) ;
56
+ async function git ( args : string [ ] , options : execa . Options = { } ) {
57
+ return execa ( GIT , args , {
58
+ stdio : 'inherit' ,
59
+ ...options ,
60
+ } ) ;
59
61
}
60
62
61
- async function fetch ( { name, url} ) {
63
+ async function fetch ( { name, url} : { name : string ; url : string } ) {
62
64
await git ( [ 'remote' , 'add' , name , url ] ) ;
63
65
await git ( [ 'fetch' , name , '--quiet' ] ) ;
64
66
}
@@ -70,28 +72,23 @@ async function isClean() {
70
72
return ! ( result . stdout && result . stdout . trim ( ) ) ;
71
73
}
72
74
73
- async function lint ( args , options ) {
74
- return execa (
75
- COMMITLINT || commitlint ,
76
- args ,
77
- Object . assign ( { } , { stdio : [ 'pipe' , 'inherit' , 'inherit' ] } , options )
78
- ) ;
75
+ async function lint ( args : string [ ] , options : execa . Options = { } ) {
76
+ return execa ( COMMITLINT , args , {
77
+ stdio : [ 'pipe' , 'inherit' , 'inherit' ] ,
78
+ ...options ,
79
+ } ) ;
79
80
}
80
81
81
- async function log ( hash ) {
82
- const result = await execa ( GIT , [
83
- 'log' ,
84
- '-n' ,
85
- '1' ,
86
- '--pretty=format:%B' ,
87
- hash ,
88
- ] ) ;
82
+ async function log ( hash : string ) {
83
+ const result = await git ( [ 'log' , '-n' , '1' , '--pretty=format:%B' , hash ] , {
84
+ stdio : 'pipe' ,
85
+ } ) ;
89
86
return result . stdout ;
90
87
}
91
88
92
89
async function stash ( ) {
93
90
if ( await isClean ( ) ) {
94
- return async ( ) => { } ;
91
+ return ( ) => Promise . resolve ( ) ;
95
92
}
96
93
await git ( [ 'stash' , '-k' , '-u' , '--quiet' ] ) ;
97
94
return ( ) => git ( [ 'stash' , 'pop' , '--quiet' ] ) ;
0 commit comments