-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (31 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const core = require('@actions/core')
const github = require('@actions/github')
const crypto = require('crypto')
const fetch = require('node-fetch')
const makeMessage = require('./utils/makeMessage')
const calcHMACSHA1 = (message, secret) => crypto.createHmac('sha1', secret).update(message).digest('hex')
try {
const id = core.getInput('webhook-id')
const secret = core.getInput('webhook-secret', { required: false })
const channelId = core.getInput('channel-id', { required: false })
const messageInput = core.getInput('message', { required: false }).trim()
const context = github.context
const message = messageInput !== '' ? messageInput : makeMessage(core, context)
if (typeof message === 'string') {
const url = `https://q.trap.jp/api/v3/webhooks/${id}`
let headers = { 'Content-Type': 'text/plain' }
if (secret !== '-1') {
headers['X-TRAQ-Signature'] = calcHMACSHA1(message, secret)
}
if (channelId !== '-1') {
headers['X-TRAQ-Channel-Id'] = channelId
}
fetch(url, {
method: 'POST',
body: message,
headers
})
}
} catch (err) {
core.setFailed(err.message)
}