From 9228e8eab992c071279ee5592e29b44b7936e847 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Feb 2017 04:25:02 +0900 Subject: [PATCH] [Server] Improve github notification --- src/api/service/github.ts | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/api/service/github.ts b/src/api/service/github.ts index c23a229a18..31ca2b2786 100644 --- a/src/api/service/github.ts +++ b/src/api/service/github.ts @@ -24,8 +24,12 @@ module.exports = async (app: express.Application) => { app.post('/hooks/github', handler); - handler.on('*', event => { - console.dir(event); + handler.on('push', event => { + const ref = event.payload.ref; + if (ref != 'refs/heads/master') return; + const pusher = event.payload.pusher; + const compare = event.payload.compare; + post(`Pushed! (Pusher: ${pusher.name})\nCompare changes: ${compare}`); }); handler.on('issues', event => { @@ -33,11 +37,45 @@ module.exports = async (app: express.Application) => { const action = event.payload.action; let title: string; switch (action) { - case 'opened': title = 'Issueが立ちました'; break; - case 'closed': title = 'Issueが閉じられました'; break; - case 'reopened': title = 'Issueが開きました'; break; + case 'opened': title = 'New Issue'; break; + case 'closed': title = 'Issue Closed'; break; + case 'reopened': title = 'Issue Reopened'; break; default: return; } post(`${title}: ${issue.number}「${issue.title}」\n${issue.html_url}`); }); + + handler.on('issue_comment', event => { + const issue = event.payload.issue; + const comment = event.payload.comment; + const action = event.payload.action; + let text: string; + switch (action) { + case 'created': text = `Comment to「${issue.title}」:${comment.user.login}「${comment.body}」\n${comment.html_url}`; break; + default: return; + } + post(text); + }); + + handler.on('fork', event => { + const repo = event.payload.forkee; + post(`Forked:\n${repo.html_url}`); + }); + + handler.on('pull_request', event => { + const pr = event.payload.pull_request; + const action = event.payload.action; + let text: string; + switch (action) { + case 'opened': text = `New Pull Request:「${pr.title}」\n${pr.html_url}`; break; + case 'reopened': text = `Pull Request Reopened:「${pr.title}」\n${pr.html_url}`; break; + case 'closed': + text = pr.merged + ? `Pull Request Merged!:「${pr.title}」\n${pr.html_url}` + : `Pull Request Closed:「${pr.title}」\n${pr.html_url}`; + break; + default: return; + } + post(text); + }); };