@@ -10,23 +10,26 @@ const format = require('./format')
10
10
* status check
11
11
*/
12
12
async function commitlint ( context ) {
13
- const { github } = context
13
+ // 1. Extract necessary info
14
14
const pull = context . issue ( )
15
15
const { sha } = context . payload . pull_request . head
16
16
const repo = context . repo ( )
17
17
18
+ // GH API
19
+ const { paginate, issues, repos, pullRequests } = context . github
20
+
18
21
// Hold this PR info
19
22
const statusInfo = { ...repo , sha, context : 'commitlint' }
20
23
21
24
// Pending
22
- await github . repos . createStatus ( {
25
+ await repos . createStatus ( {
23
26
...statusInfo ,
24
27
state : 'pending' ,
25
28
description : 'Waiting for the status to be reported'
26
29
} )
27
30
28
31
// Paginate all PR commits
29
- github . paginate ( github . pullRequests . getCommits ( pull ) , async ( { data } ) => {
32
+ return paginate ( pullRequests . getCommits ( pull ) , async ( { data } ) => {
30
33
// empty summary
31
34
const report = { valid : true , commits : { } }
32
35
const { rules } = await load ( config )
@@ -46,15 +49,15 @@ async function commitlint(context) {
46
49
const { summary, message } = format ( report )
47
50
48
51
// Final status
49
- await github . repos . createStatus ( {
52
+ await repos . createStatus ( {
50
53
...statusInfo ,
51
54
state : report . valid ? 'success' : 'failure' ,
52
55
description : summary
53
56
} )
54
57
55
58
// Write a comment with the details (if any)
56
- if ( message !== '' ) {
57
- await github . issues . createComment ( { ...pull , body : message } )
59
+ if ( message ) {
60
+ await issues . createComment ( { ...pull , body : message } )
58
61
}
59
62
} )
60
63
}
0 commit comments