Merge pull request #79 from migarjo/decouple-config-from-repo

Add routing plugin
This commit is contained in:
Brandon Keepers 2017-01-25 22:45:17 -06:00 committed by GitHub
commit f68ae7875e
3 changed files with 33 additions and 14 deletions

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

@ -0,0 +1,14 @@
const Plugin = require('../plugin');
const Configuration = require('../configuration');
const url = require('../util/github-url');
module.exports = class Routing extends Plugin {
route(context, path) {
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,9 +1,3 @@
const Issues = require('./plugins/issues');
const plugins = [
new Issues()
];
module.exports = class Workflow {
constructor(events) {
this.stack = [];
@ -11,8 +5,14 @@ module.exports = class Workflow {
this.filterFn = () => true;
this.api = {};
const plugins = [
require('./plugins/issues'),
require('./plugins/routing')
];
// Define a new function in the API for each plugin method
for (const plugin of plugins) {
for (const Plugin of plugins) {
const plugin = new Plugin();
for (const method of plugin.api) {
this.api[method] = this.proxy(plugin[method]).bind(this);
}