generated from 2nthony/ts-lib-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify.mjs
47 lines (39 loc) · 944 Bytes
/
notify.mjs
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
import { execSync } from "node:child_process";
import axios from "redaxios";
import process from "node:process";
import pkg from "./package.json" assert { type: "json" };
const url = process.env.WEBHOOK_URL;
main();
function main() {
if (!url) {
return;
}
const msg = getLatestGitMsg();
// quick filter semantic release commit trigger condition
if (
msg.startsWith("feat:") ||
msg.startsWith("feat(") ||
msg.startsWith("fix:") ||
msg.startsWith("fix(") ||
msg.includes("BREAKING CHANGE: ")
) {
const data = {
msg_type: "text",
content: {
text: `@osn/common-ui@${pkg.version}\n\n${msg}`,
},
};
axios.post(url, data);
} else {
console.info("No need to notify");
}
}
function getLatestGitMsg() {
let msg = "";
try {
msg = execSync("git log -1 --pretty=format:%s").toString().trim();
} catch (error) {
console.error(error);
}
return msg;
}