-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpost-to-smee.js
48 lines (44 loc) · 1.26 KB
/
post-to-smee.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
36
37
38
39
40
41
42
43
44
45
46
47
48
const core = require('@actions/core')
const { context } = require('@actions/github')
const fetch = require('node-fetch')
module.exports = async function postToSmee () {
// Serialize payload object
const payload = {
...context.payload,
'smee-action': {
action: context.action,
actor: context.actor,
event: process.env.GITHUB_EVENT_NAME,
sha: context.sha,
ref: context.ref,
workflow: context.workflow,
run_id: process.env.GITHUB_RUN_ID
}
}
// Serialize headers
const headers = {
'X-GitHub-Event': process.env.GITHUB_EVENT_NAME,
// Used to prevent duplication
'X-GitHub-Delivery': process.env.GITHUB_RUN_ID
}
// Get the channel id
const channel = (
// Use the provided `channel` input
core.getInput('channel') ||
// Default to `owner-repo`
`${context.repo.owner}-${context.repo.repo}`
)
// Send the data to Smee
const url = `https://smee.io/${channel}`
await fetch(url, {
method: 'POST',
body: JSON.stringify(payload),
headers: {
...headers,
'Content-Type': 'application/json'
}
})
core.info(`Done! Check it out at ${url}.`)
core.info('Remember that Smee only shows payloads received while your browser tab is open!')
core.setOutput('url', url)
}