diff --git a/craft-functions/github-to-talk-notification/README.md b/craft-functions/github-to-talk-notification/README.md index 4bea7c4..dac2f2a 100644 --- a/craft-functions/github-to-talk-notification/README.md +++ b/craft-functions/github-to-talk-notification/README.md @@ -13,4 +13,8 @@ KARTE Talkのトーク画面URLをトップコメントに貼ったGitHub Issue ## category -GitHub,Craft Functions,Talk,CRAFT_ENDPOINT \ No newline at end of file +GitHub,Craft Functions,Talk,CRAFT_ENDPOINT + +## functionType + +http \ No newline at end of file diff --git a/craft-functions/github-to-talk-notification/index.js b/craft-functions/github-to-talk-notification/index.js index 1cfbccc..e73557d 100644 --- a/craft-functions/github-to-talk-notification/index.js +++ b/craft-functions/github-to-talk-notification/index.js @@ -95,17 +95,29 @@ async function sendNotes({ noteMessages, karteAppToken, logger }) { } export default async function (data, { MODULES }) { + const { req, res } = data; const { secret, initLogger } = MODULES; const logger = initLogger({ logLevel: LOG_LEVEL }); - const { body } = data.jsonPayload.data.hook_data; + res.setHeader('Access-Control-Allow-Origin', '*'); + res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); + res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization'); + + if (req.method === 'OPTIONS') { + res.status(204).end(); + return; + } + + const { body } = req; if (!body) { - return logger.error('[error] request has no body'); + res.status(400).json({ message: '[error] request has no body' }); + return; } const { issue, action } = body; if (!issue || !issue.body) { - return logger.error('[error] request has no issue.body'); + res.status(400).json({ message: '[error] request has no issue.body' }); + return; } const actionText = mapActionType(action); if (!actionText) return; @@ -114,7 +126,7 @@ export default async function (data, { MODULES }) { const targets = extractTargets(issueBody, { logger }); if (targets.length === 0) return; - const githubUserName = body.sender.login; + const githubUserName = body.jsoner.login; const commonHeader = makeCommonHeader(issue, githubUserName, actionText); const noteMessages = makeNoteMessages(targets, commonHeader); @@ -122,4 +134,6 @@ export default async function (data, { MODULES }) { const secrets = await secret.get({ keys: [KARTE_APP_TOKEN_SECRET] }); const karteAppToken = secrets[KARTE_APP_TOKEN_SECRET]; await sendNotes({ noteMessages, commonHeader, karteAppToken, logger }); -} + + res.status(200).json({ message: 'Success' }); +} \ No newline at end of file