forked from mirrors/probot
Merge pull request #79 from migarjo/decouple-config-from-repo
Add routing plugin
This commit is contained in:
commit
f68ae7875e
|
@ -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);
|
||||
});
|
||||
}
|
||||
};
|
19
lib/robot.js
19
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();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue