Add routing plugin

This commit is contained in:
Michael Johnson 2017-01-24 10:43:14 -07:00
parent 3d123908ba
commit ee6e77c2f9
3 changed files with 32 additions and 8 deletions

17
lib/plugins/routing.js Normal file
View File

@ -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);
});
}
}

View File

@ -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();
});
});
}
}

View File

@ -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 {