-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (34 loc) · 1.15 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
36
37
38
39
40
41
42
// I know that's weird to mix ESM and CJS but it works with ncc :)
const core = require('@actions/core')
import fetch from 'node-fetch'
async function main() {
const url = core.getInput('discord_webhook_url')
const title = core.getInput('title')
const message = core.getInput('message')
const description = `${message}
[View on GitHub](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID})
Generated by [notify-action](https://github.com/neolitec/notify-action)`
console.log({ title, message })
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
embeds: [{
color: 0x0099ff,
title,
description,
}],
})
})
if (response.status !== 204) {
throw new Error(`Discord responded with ${response.status}`)
}
}
main().then(() => {
console.log('Successfully called the webhook')
core.setOutput('result', 'success')
}).catch((err) => {
console.log('Error while calling the webhook', err)
core.setFailed(err.message)
core.setOutput('result', `error: ${err.message}`)
})