Experiment with rules-based approach

This commit is contained in:
Brandon Keepers 2016-10-09 00:29:05 -05:00
parent 5cc30e4f31
commit 79ee3fa028
No known key found for this signature in database
GPG Key ID: F9533396D5FACBF6
3 changed files with 36 additions and 3 deletions

24
lib/dispatch.js Normal file
View File

@ -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);
})
}

View File

@ -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"

View File

@ -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'));