From ee6e77c2f99d21130982ba8c966245aca3369924 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 24 Jan 2017 10:43:14 -0700 Subject: [PATCH] Add routing plugin --- lib/plugins/routing.js | 17 +++++++++++++++++ lib/robot.js | 19 ++++++++++++------- lib/workflow.js | 4 +++- 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 lib/plugins/routing.js diff --git a/lib/plugins/routing.js b/lib/plugins/routing.js new file mode 100644 index 00000000..6cb3d486 --- /dev/null +++ b/lib/plugins/routing.js @@ -0,0 +1,17 @@ +const Plugin = require('../plugin'); +const Configuration = require('../configuration'); +const url = require('../util/github-url'); + +console.log("WTF?", Configuration, Configuration.load); + +module.exports = class Routing extends Plugin { + route(context, path) { + console.log(Configuration, Configuration.load) + return Configuration.load(context, path).then(config => { + const parts = url(path); + context.event.payload.repository.name = parts.repo; + context.event.payload.repository.owner.login = parts.owner; + return config.execute(context); + }); + } +} diff --git a/lib/robot.js b/lib/robot.js index 497dd1f5..0734e52d 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -11,14 +11,19 @@ class Robot { receive(event) { log.trace('webhook', event); - if (event.payload.repository) { - installations.auth(event.payload.installation.id).then(github => { - const context = new Context(github, event); - Configuration.load(context, '.probot.js').then(config => { - return config.execute(); - }); - }); + if(!event.payload.repository) { + event.payload.repository = { + name: 'probot-scripts', + owner: event.payload.organization + } } + + installations.auth(event.payload.installation.id).then(github => { + const context = new Context(github, event); + Configuration.load(context, '.probot.js').then(config => { + return config.execute(); + }); + }); } } diff --git a/lib/workflow.js b/lib/workflow.js index 8e57cb68..dd4b6264 100644 --- a/lib/workflow.js +++ b/lib/workflow.js @@ -1,7 +1,9 @@ const Issues = require('./plugins/issues'); +const Routing = require('./plugins/routing'); const plugins = [ - new Issues() + new Issues(), + new Routing() ]; module.exports = class Workflow {