generated from actions/hello-world-javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotify.js
41 lines (37 loc) · 1.18 KB
/
notify.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
import core from "@actions/core";
import mime from "mime";
import { readFileSync } from "fs";
export const notify = async () => {
try {
const to = core.getInput("to");
const subject = core.getInput("subject");
const body = core.getInput("body");
const type = core.getInput("type");
const payload = { to, subject, body, type };
const attachmentPath = core.getInput("attachment");
if (attachmentPath) {
const file = readFileSync(attachmentPath);
const attachment = {
filename: attachmentPath,
type: mime.getType(attachmentPath),
content: file.toString("base64"),
};
payload.attachments = [attachment];
}
const response = await fetch("https://www.cinotify.cc/api/notify", {
body: JSON.stringify(payload),
headers: {
"Content-Type": "application/json",
"User-Agent": `@cinotify/github-action@${process.env["GITHUB_ACTION_REF"]}`,
},
method: "POST",
});
if (response.status >= 300) {
throw new Error(JSON.stringify(await response.json()));
}
core.setOutput("status", "ok");
return response;
} catch (error) {
core.setFailed(error.message);
}
};