@@ -13,8 +13,7 @@ const projectOrg = "deislabs";
13
13
14
14
events . on ( "check_suite:requested" , runSuite ) ;
15
15
events . on ( "check_suite:rerequested" , runSuite ) ;
16
- // TODO: we should determine which check run is being requested and *only* run this
17
- events . on ( "check_run:rerequested" , runSuite ) ;
16
+ events . on ( "check_run:rerequested" , runCheck ) ;
18
17
19
18
events . on ( "exec" , ( e , p ) => {
20
19
Group . runAll ( [
@@ -131,20 +130,51 @@ function publish(e, p) {
131
130
return goPublish ;
132
131
}
133
132
133
+ // These represent the standard checks that run for PRs (see runSuite below)
134
+ //
135
+ // They are encapsulated in an object such that individual checks may be run
136
+ // using data supplied by a corresponding GitHub webhook, say, on a
137
+ // check_run:rerequested event (see runCheck below)
138
+ checks = {
139
+ "verify" : { runFunc : verify , description : "Verify" } ,
140
+ "build" : { runFunc : build , description : "Build" } ,
141
+ "crossplatformbuild" : { runFunc : xbuild , description : "Cross-Platform Build" } ,
142
+ "test" : { runFunc : test , description : "Test" } ,
143
+ "integrationtest" : { runFunc : testIntegration , description : "Integration Test" }
144
+ } ;
145
+
146
+ // runCheck can be invoked to (re-)run an individual GitHub Check Run, as opposed to a full suite
147
+ function runCheck ( e , p ) {
148
+ payload = JSON . parse ( e . payload ) ;
149
+
150
+ name = payload . body . check_run . name ;
151
+ check = checks [ name ] ;
152
+
153
+ if ( typeof check !== 'undefined' ) {
154
+ checkRun ( e , p , check . runFunc , check . description )
155
+ . catch ( e => { console . error ( e . toString ( ) ) } ) ;
156
+ } else {
157
+ err = new Error ( `No check found with name: ${ name } ` ) ;
158
+ // TODO: remove this console.error statement once Brigade logs err.message when thrown
159
+ // https://github.com/brigadecore/brigade-github-app/pull/43
160
+ console . error ( err . message ) ;
161
+ throw err ;
162
+ }
163
+ }
164
+
134
165
// Here we add GitHub Check Runs, which will run in parallel and report their results independently to GitHub
135
166
function runSuite ( e , p ) {
136
- if ( e . revision . ref . includes ( "refs/heads/ master") ) {
167
+ if ( e . revision . ref == " master" ) {
137
168
Group . runEach ( [
138
169
checkRun ( e , p , test , "Test" ) ,
139
170
checkRun ( e , p , testIntegration , "Integration Test" ) ,
140
171
checkRun ( e , p , publish , "Publish" )
141
172
] )
142
173
} else {
143
- checkRun ( e , p , verify , "Verify" ) . catch ( e => { console . error ( e . toString ( ) ) } ) ;
144
- checkRun ( e , p , build , "Build" ) . catch ( e => { console . error ( e . toString ( ) ) } ) ;
145
- checkRun ( e , p , xbuild , "Cross-Platform Build" ) . catch ( e => { console . error ( e . toString ( ) ) } ) ;
146
- checkRun ( e , p , test , "Test" ) . catch ( e => { console . error ( e . toString ( ) ) } ) ;
147
- checkRun ( e , p , testIntegration , "Integration Test" ) . catch ( e => { console . error ( e . toString ( ) ) } ) ;
174
+ for ( check of Object . values ( checks ) ) {
175
+ checkRun ( e , p , check . runFunc , check . description )
176
+ . catch ( e => { console . error ( e . toString ( ) ) } ) ;
177
+ }
148
178
}
149
179
}
150
180
0 commit comments