Skip to content

Commit 83471fb

Browse files
Merge pull request #336 from vdice/ci/check-runs
feat(brigade.js): run specific check run on check_run:rerequested event
2 parents d74e7b5 + 0ec0969 commit 83471fb

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

brigade.js

+38-8
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ const projectOrg = "deislabs";
1313

1414
events.on("check_suite:requested", runSuite);
1515
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);
1817

1918
events.on("exec", (e, p) => {
2019
Group.runAll([
@@ -131,20 +130,51 @@ function publish(e, p) {
131130
return goPublish;
132131
}
133132

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+
134165
// Here we add GitHub Check Runs, which will run in parallel and report their results independently to GitHub
135166
function runSuite(e, p) {
136-
if (e.revision.ref.includes("refs/heads/master")) {
167+
if (e.revision.ref == "master" ) {
137168
Group.runEach([
138169
checkRun(e, p, test, "Test"),
139170
checkRun(e, p, testIntegration, "Integration Test"),
140171
checkRun(e, p, publish, "Publish")
141172
])
142173
} 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+
}
148178
}
149179
}
150180

0 commit comments

Comments
 (0)