From 84d0ad12d145238370628d73dadb640c74f61637 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 10 Aug 2017 22:06:47 +0900 Subject: Fix typescript --- src/api/service/github.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/api/service/github.ts') diff --git a/src/api/service/github.ts b/src/api/service/github.ts index 0d6e663419..a631808ba5 100644 --- a/src/api/service/github.ts +++ b/src/api/service/github.ts @@ -22,8 +22,11 @@ module.exports = async (app: express.Application) => { const handler = new EventEmitter(); app.post('/hooks/github', (req, res, next) => { - if ((new Buffer(req.headers['x-hub-signature'])).equals(new Buffer(`sha1=${crypto.createHmac('sha1', config.github_bot.hook_secret).update(JSON.stringify(req.body)).digest('hex')}`))) { - handler.emit(req.headers['x-github-event'], req.body); + // req.headers['x-hub-signature'] および + // req.headers['x-github-event'] は常に string ですが、型定義の都合上 + // string | string[] になっているので string を明示しています + if ((new Buffer(req.headers['x-hub-signature'] as string)).equals(new Buffer(`sha1=${crypto.createHmac('sha1', config.github_bot.hook_secret).update(JSON.stringify(req.body)).digest('hex')}`))) { + handler.emit(req.headers['x-github-event'] as string, req.body); res.sendStatus(200); } else { res.sendStatus(400); -- cgit v1.2.3-freya