forked from mirrors/probot
Create a separate robot for each plugin
This commit is contained in:
parent
d17d9b717b
commit
4961e0f692
23
index.js
23
index.js
|
@ -31,16 +31,9 @@ module.exports = (options = {}) => {
|
|||
debug: process.env.LOG_LEVEL === 'trace'
|
||||
});
|
||||
const server = createServer(webhook);
|
||||
const robot = createRobot({app, cache, logger, catchErrors: true});
|
||||
|
||||
// Connect the router from the robot to the server
|
||||
server.use(robot.router);
|
||||
|
||||
// Forward webhooks to robot
|
||||
webhook.on('*', event => {
|
||||
logger.trace(event, 'webhook received');
|
||||
robot.receive(event);
|
||||
});
|
||||
// Log all received webhooks
|
||||
webhook.on('*', event => logger.trace(event, 'webhook received'));
|
||||
|
||||
// Log all webhook errors
|
||||
webhook.on('error', logger.error.bind(logger));
|
||||
|
@ -60,7 +53,6 @@ module.exports = (options = {}) => {
|
|||
|
||||
return {
|
||||
server,
|
||||
robot,
|
||||
webhook,
|
||||
|
||||
start() {
|
||||
|
@ -69,7 +61,18 @@ module.exports = (options = {}) => {
|
|||
},
|
||||
|
||||
load(plugin) {
|
||||
const robot = createRobot({app, cache, logger, catchErrors: true});
|
||||
|
||||
// Connect the router from the robot to the server
|
||||
server.use(robot.router);
|
||||
|
||||
// Forward webhooks to robot
|
||||
webhook.on('*', event => robot.receive(event));
|
||||
|
||||
// Initialize the plugin
|
||||
plugin(robot);
|
||||
|
||||
return robot;
|
||||
},
|
||||
|
||||
receive(event) {
|
||||
|
|
|
@ -7,8 +7,6 @@ describe('Probot', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
probot = createProbot();
|
||||
// Mock out GitHub App authentication
|
||||
probot.robot.auth = () => Promise.resolve({});
|
||||
|
||||
event = {
|
||||
event: 'push',
|
||||
|
@ -18,9 +16,10 @@ describe('Probot', () => {
|
|||
|
||||
describe('webhook delivery', () => {
|
||||
it('forwards webhooks to the robot', async () => {
|
||||
probot.robot.receive = expect.createSpy();
|
||||
const robot = probot.load(robot => {});
|
||||
robot.receive = expect.createSpy();
|
||||
probot.webhook.emit('*', event);
|
||||
expect(probot.robot.receive).toHaveBeenCalledWith(event);
|
||||
expect(robot.receive).toHaveBeenCalledWith(event);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue