@@ -55,44 +55,44 @@ const checkers = [{
55
55
} ,
56
56
} ] ;
57
57
58
- async function readJsonFromStdin ( ) {
59
- const chunks = [ ] ;
60
- for await ( const chunk of process . stdin ) {
61
- chunks . push ( chunk ) ;
62
- }
63
-
64
- return Buffer . concat ( chunks ) . toString ( ) ;
65
- }
66
-
67
58
function runChecker ( { check, error } ) {
68
59
return check ( this . message ) ? [ ] : [ error ] ;
69
60
}
70
61
71
- async function main ( ) {
72
- const commits = JSON . parse ( await readJsonFromStdin ( ) ) ;
73
-
74
- let exitCode = 0 ;
62
+ function checkCommits ( commits ) {
63
+ let success = true ;
75
64
for ( const { commit, sha } of commits ) {
76
65
const errors = checkers . flatMap ( runChecker , commit ) ;
77
66
if ( errors . length === 0 ) {
78
67
continue ;
79
68
}
80
69
81
- if ( exitCode !== 0 ) {
70
+ if ( ! success ) {
82
71
console . log ( "" ) ;
83
72
}
84
- exitCode = 1 ;
73
+ success = false ;
85
74
86
75
console . log ( "Commit %s failed these checks:" , sha ) ;
87
76
for ( const error of errors ) {
88
77
console . log ( " %s" , error ) ;
89
78
}
90
79
}
91
80
92
- return exitCode ;
81
+ return success ;
82
+ }
83
+
84
+ async function main ( github , core , context ) {
85
+ const { repository, pull_request } = context . payload ;
86
+ const options = github . rest . pulls . listCommits . endpoint . merge ( {
87
+ owner : repository . owner . login ,
88
+ repo : repository . name ,
89
+ pull_number : pull_request . number ,
90
+ } ) ;
91
+ const commits = await github . paginate ( options ) ;
92
+ const isErrorFree = checkCommits ( commits ) ;
93
+ if ( ! isErrorFree ) {
94
+ core . setFailed ( "Please check the logs for errors in commit messages." ) ;
95
+ }
93
96
}
94
97
95
- main ( ) . catch ( ( error ) => {
96
- console . error ( error ) ;
97
- return 1 ;
98
- } ) . then ( ( code ) => { process . exitCode = code ; } ) ;
98
+ module . exports = { main } ;
0 commit comments