Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #251 from vdice/ci/handlers
Browse files Browse the repository at this point in the history
feat(brigade.js): add issue comment and check run event handlers
  • Loading branch information
vdice authored Jun 11, 2019
2 parents 55d95d1 + b91b0f7 commit e2eb930
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions brigade.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const { events, Job, Group } = require("brigadier");

const projectName = "kashti";
const projectOrg = "brigadecore";

const img = "deis/node-chrome:node8";

const releaseTagRegex = /^refs\/tags\/(v[0-9]+(?:\.[0-9]+)*(?:\-.+)?)$/;
Expand Down Expand Up @@ -94,14 +91,56 @@ function runTests(e, p, jobFunc) {
return notificationWrap(job, note);
}

// runCheck is the default function invoked on a check_run:* event
//
// It determines which check is being requested (from the payload body)
// and runs this particular check, or else throws an error if the check
// is not found
function runCheck(e, p) {
payload = JSON.parse(e.payload);

// Extract the check name
name = payload.body.check_run.name;

// Determine which check to run
switch (name) {
case "tests":
return runTests(e, p, tests);
case "e2e":
return runTests(e, p, e2e);
default:
throw new Error(`No check found with name: ${name}`);
}
}

// handleIssueComment handles an issue_comment event, parsing the comment text
// and determining whether or not to trigger an action
function handleIssueComment(e, p) {
console.log("handling issue comment....")
payload = JSON.parse(e.payload);

// Extract the comment body and trim whitespace
comment = payload.body.comment.body.trim();

// Here we determine if a comment should provoke an action
switch (comment) {
// Currently, the do-all '/brig run' comment is supported,
// for (re-)triggering the default Checks suite
case "/brig run":
return runSuite(e, p);
default:
console.log(`No applicable action found for comment: ${comment}`);
}
}

// A GitHub Check Suite notification
class Notification {
constructor(name, e, p) {
this.proj = p;
this.payload = e.payload;
this.name = name;
this.externalID = e.buildID;
this.detailsURL = `https://brigadecore.github.io/kashti/builds/${e.buildID}`;
this.detailsURL = `https://brigadecore.github.io/kashti/builds/${e.buildID}`;
this.title = "running check";
this.text = "";
this.summary = "";
Expand Down Expand Up @@ -189,4 +228,6 @@ events.on("push", (e, p) => {

events.on("check_suite:requested", runSuite);
events.on("check_suite:rerequested", runSuite);
events.on("check_run:rerequested", runSuite);
events.on("check_run:rerequested", runCheck);
events.on("issue_comment:created", handleIssueComment);
events.on("issue_comment:edited", handleIssueComment);

0 comments on commit e2eb930

Please sign in to comment.