forked from mirrors/probot
Fix lint errors
This commit is contained in:
parent
f9db96b7fd
commit
1572100fff
|
@ -4,4 +4,4 @@ module.exports = class Behavior {
|
|||
this.conditions = conditions || [];
|
||||
this.then = actions;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,36 +1,7 @@
|
|||
var walk = require('tree-walk');
|
||||
|
||||
const walk = require('tree-walk');
|
||||
const Behavior = require('./behavior');
|
||||
const actions = require('./actions');
|
||||
|
||||
module.exports = class Transformer {
|
||||
constructor(tree) {
|
||||
this.behaviors = walk.filter(tree, walk.preorder, function(node) {
|
||||
return node.type === 'behavior';
|
||||
});
|
||||
}
|
||||
|
||||
transform() {
|
||||
return walk.reduce(this.behaviors, this.walk.bind(this));
|
||||
}
|
||||
|
||||
walk(result, node) {
|
||||
if(this[node.type]) {
|
||||
return this[node.type](result, node);
|
||||
} else {
|
||||
return result || node;
|
||||
}
|
||||
}
|
||||
|
||||
action(node, result) {
|
||||
return new Action(node.name, node.value);
|
||||
}
|
||||
|
||||
behavior(result, node) {
|
||||
return new Behavior(result.events, result.conditions, result.then);
|
||||
}
|
||||
}
|
||||
|
||||
class Action {
|
||||
constructor(name, value) {
|
||||
this.name = name;
|
||||
|
@ -41,3 +12,31 @@ class Action {
|
|||
actions[this.name](github, payload, this.value);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = class Transformer {
|
||||
constructor(tree) {
|
||||
this.behaviors = walk.filter(tree, walk.preorder, node => {
|
||||
return node.type === 'behavior';
|
||||
});
|
||||
}
|
||||
|
||||
transform() {
|
||||
return walk.reduce(this.behaviors, this.walk.bind(this));
|
||||
}
|
||||
|
||||
walk(result, node) {
|
||||
if (this[node.type]) {
|
||||
return this[node.type](result, node);
|
||||
} else {
|
||||
return result || node;
|
||||
}
|
||||
}
|
||||
|
||||
action(node) {
|
||||
return new Action(node.name, node.value);
|
||||
}
|
||||
|
||||
behavior(node) {
|
||||
return new Behavior(node.events, node.conditions, node.then);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -26,7 +26,9 @@
|
|||
"xo": {
|
||||
"esnext": true,
|
||||
"space": true,
|
||||
"rules": {},
|
||||
"rules": {
|
||||
"no-else-return": 0
|
||||
},
|
||||
"ignores": [],
|
||||
"envs": [
|
||||
"node",
|
||||
|
|
|
@ -42,9 +42,9 @@ describe('parser', () => {
|
|||
|
||||
it('parses an event and action', () => {
|
||||
expect(parser.parse('on issues.opened then close;')).toEqual([{
|
||||
type: 'behavior',
|
||||
events: [{type: 'event', name: 'issues', action: 'opened'}],
|
||||
then: [{type: 'action', name: 'close'}]
|
||||
type: 'behavior',
|
||||
events: [{type: 'event', name: 'issues', action: 'opened'}],
|
||||
then: [{type: 'action', name: 'close'}]
|
||||
}]);
|
||||
});
|
||||
|
||||
|
@ -143,9 +143,9 @@ describe('parser', () => {
|
|||
on issues # Ignore this
|
||||
then close;
|
||||
`)).toEqual([{
|
||||
type: 'behavior',
|
||||
events: [{type: 'event', name: 'issues'}],
|
||||
then: [{type: 'action', name: 'close'}]
|
||||
type: 'behavior',
|
||||
events: [{type: 'event', name: 'issues'}],
|
||||
then: [{type: 'action', name: 'close'}]
|
||||
}]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue