forked from mirrors/probot
Experiment with rules-based approach
This commit is contained in:
parent
5cc30e4f31
commit
79ee3fa028
|
@ -0,0 +1,24 @@
|
|||
let yaml = require('js-yaml');
|
||||
|
||||
module.exports = dispatch;
|
||||
|
||||
function dispatch(github, event) {
|
||||
if(event.payload.repository) {
|
||||
return loadConfig(github, event.payload.repository);
|
||||
} else {
|
||||
console.log("No repository for event", event);
|
||||
}
|
||||
}
|
||||
|
||||
function loadConfig(github, repository) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
github.repos.getContent({
|
||||
user: repository.owner.login,
|
||||
repo: repository.name,
|
||||
path: '.probot.yml'
|
||||
}).then(function (data) {
|
||||
var content = new Buffer(data.content, 'base64').toString();
|
||||
resolve(yaml.safeLoad(content));
|
||||
}).catch(reject);
|
||||
})
|
||||
}
|
10
package.json
10
package.json
|
@ -12,9 +12,10 @@
|
|||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"expect": "^1.20.2",
|
||||
"github": "^3.1.0",
|
||||
"github": "^4.0.0",
|
||||
"github-webhook-handler": "^0.6.0",
|
||||
"handlebars": "^4.0.5"
|
||||
"handlebars": "^4.0.5",
|
||||
"js-yaml": "^3.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^3.0.2",
|
||||
|
@ -24,7 +25,10 @@
|
|||
"space": true,
|
||||
"rules": {},
|
||||
"ignores": [],
|
||||
"envs": ["node", "mocha"]
|
||||
"envs": [
|
||||
"node",
|
||||
"mocha"
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"node": "6.6.0"
|
||||
|
|
|
@ -5,6 +5,7 @@ let GitHubApi = require('github');
|
|||
|
||||
let webhook = createHandler({path: '/', secret: process.env.WEBHOOK_SECRET || 'secret'});
|
||||
let github = new GitHubApi();
|
||||
let dispatch = require('./lib/dispatch');
|
||||
|
||||
let PORT = process.env.PORT || 3000;
|
||||
|
||||
|
@ -34,4 +35,8 @@ function register(behavior) {
|
|||
});
|
||||
}
|
||||
|
||||
webhook.on('*', function (event) {
|
||||
dispatch(github, event);
|
||||
});
|
||||
|
||||
register(require('./behaviors/autoresponder.js'));
|
||||
|
|
Loading…
Reference in New Issue