mirror of
https://github.com/zhigang1992/probot.git
synced 2026-06-16 19:51:43 +08:00
Add Context.halt() function to make halting a rule simple
This commit is contained in:
@@ -5,6 +5,10 @@ module.exports = class Context {
|
||||
this.payload = event.payload;
|
||||
}
|
||||
|
||||
halt() {
|
||||
return Promise.reject(new Error('halted'));
|
||||
}
|
||||
|
||||
toRepo(object) {
|
||||
const repo = this.payload.repository;
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
const Plugin = require('../plugin');
|
||||
|
||||
function halt() {
|
||||
return Promise.reject(new Error('halted'));
|
||||
}
|
||||
|
||||
module.exports = class Filter extends Plugin {
|
||||
filter(context, fn) {
|
||||
const result = fn(context.event, context);
|
||||
return result === false ? halt() : result;
|
||||
return result === false ? context.halt() : result;
|
||||
}
|
||||
|
||||
then(context, fn) {
|
||||
@@ -21,6 +17,6 @@ module.exports = class Filter extends Plugin {
|
||||
return name === event.event && (!action || action === event.payload.action);
|
||||
});
|
||||
|
||||
return res ? Promise.resolve(res) : halt();
|
||||
return res ? Promise.resolve(res) : context.halt();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,7 +5,10 @@ const createSpy = expect.createSpy;
|
||||
|
||||
describe('filter plugin', () => {
|
||||
const event = {};
|
||||
const context = {event};
|
||||
const context = {
|
||||
event,
|
||||
halt: createSpy().andReturn(Promise.reject(new Error('halted')))
|
||||
};
|
||||
|
||||
let filter;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user