From 2d78329860795c8a2a4f2cd4eb8cd09945a93294 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Feb 2017 00:12:49 +0900 Subject: [PATCH] #52 --- package.json | 1 + src/api/server.ts | 1 + src/api/service/github.ts | 18 ++++++++++++++++++ src/config.ts | 8 ++++++-- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/api/service/github.ts diff --git a/package.json b/package.json index cfa0afc32..be5eaaf01 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "file-type": "4.1.0", "fuckadblock": "3.2.1", "git-last-commit": "0.2.0", + "github-webhook-handler": "0.6.0", "glob": "7.1.1", "gm": "1.23.0", "gulp": "3.9.1", diff --git a/src/api/server.ts b/src/api/server.ts index 5f8de5719..e94a7797f 100644 --- a/src/api/server.ts +++ b/src/api/server.ts @@ -58,6 +58,7 @@ app.use((req, res, next) => { next(); }); +require('./service/github')(app); require('./service/twitter')(app); module.exports = app; diff --git a/src/api/service/github.ts b/src/api/service/github.ts new file mode 100644 index 000000000..680c02c47 --- /dev/null +++ b/src/api/service/github.ts @@ -0,0 +1,18 @@ +import * as express from 'express'; +const createHandler = require('github-webhook-handler'); +import config from '../../conf'; + +module.exports = (app: express.Application) => { + if (config.github_bot == null) return; + + const handler = createHandler({ + path: '/hooks/github', + secret: config.github_bot.hook_secret + }); + + app.post('/hooks/github', handler); + + handler.on('*', event => { + console.dir(event); + }); +}; diff --git a/src/config.ts b/src/config.ts index 2b61bb89a..e63e3c05a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -56,11 +56,15 @@ interface ISource { siteKey: string; secretKey: string; }; - accesslog: string; - twitter: { + accesslog?: string; + twitter?: { consumer_key: string; consumer_secret: string; }; + github_bot?: { + hook_secret: string; + bot_token: string; + }; } /**