@@ -10,23 +10,26 @@ const format = require('./format')
1010 * status check
1111 */
1212async function commitlint ( context ) {
13- const { github } = context
13+ // 1. Extract necessary info
1414 const pull = context . issue ( )
1515 const { sha } = context . payload . pull_request . head
1616 const repo = context . repo ( )
1717
18+ // GH API
19+ const { paginate, issues, repos, pullRequests } = context . github
20+
1821 // Hold this PR info
1922 const statusInfo = { ...repo , sha, context : 'commitlint' }
2023
2124 // Pending
22- await github . repos . createStatus ( {
25+ await repos . createStatus ( {
2326 ...statusInfo ,
2427 state : 'pending' ,
2528 description : 'Waiting for the status to be reported'
2629 } )
2730
2831 // Paginate all PR commits
29- github . paginate ( github . pullRequests . getCommits ( pull ) , async ( { data } ) => {
32+ return paginate ( pullRequests . getCommits ( pull ) , async ( { data } ) => {
3033 // empty summary
3134 const report = { valid : true , commits : { } }
3235 const { rules } = await load ( config )
@@ -46,15 +49,15 @@ async function commitlint(context) {
4649 const { summary, message } = format ( report )
4750
4851 // Final status
49- await github . repos . createStatus ( {
52+ await repos . createStatus ( {
5053 ...statusInfo ,
5154 state : report . valid ? 'success' : 'failure' ,
5255 description : summary
5356 } )
5457
5558 // 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 } )
5861 }
5962 } )
6063}
0 commit comments