Skip to content

Commit 74242fc

Browse files
[ci] build
1 parent 450a448 commit 74242fc

7 files changed

Lines changed: 107 additions & 0 deletions

File tree

dist/discord.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import process from "node:process";
2+
//#region src/discord.ts
3+
const { GITHUB_ACTION, GITHUB_EVENT_NAME, GITHUB_EVENT_PATH, DISCORD_WEBHOOK, DISCORD_MESSAGE, DISCORD_USERNAME, DISCORD_AVATAR } = process.env;
4+
if (!GITHUB_ACTION || !DISCORD_WEBHOOK) throw new Error(`Missing input.\nRequired environment variables: GITHUB_ACTION, GITHUB_EVENT_NAME, DISCORD_WEBHOOK\n\nAvailable environment variables: ${Object.keys(process.env).join(", ")}\n`);
5+
const body = {
6+
content: DISCORD_MESSAGE,
7+
username: DISCORD_USERNAME,
8+
avatar_url: DISCORD_AVATAR
9+
};
10+
const headers = {
11+
"Content-Type": "application/json",
12+
"X-GitHub-Event": GITHUB_EVENT_NAME
13+
};
14+
await fetch(`${DISCORD_WEBHOOK}?wait=true`, {
15+
body: JSON.stringify(body),
16+
headers
17+
});
18+
//#endregion
19+
export {};
20+
21+
//# sourceMappingURL=discord.mjs.map

dist/discord.mjs.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mergebot.mjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { t as setOutput } from "./utils-DQae65qb.mjs";
2+
//#region src/mergebot.ts
3+
const { COMMIT_AUTHOR, COMMIT_ID, COMMIT_MESSAGE, GITHUB_REPO } = process.env;
4+
if (!COMMIT_AUTHOR || !COMMIT_ID || !COMMIT_MESSAGE || !GITHUB_REPO) throw new Error(`Missing input.\nRequired environment variables: COMMIT_AUTHOR, COMMIT_ID, COMMIT_MESSAGE, GITHUB_REPO\n\nAvailable environment variables: ${Object.keys(process.env).join(", ")}\n`);
5+
setDiscordMessage(COMMIT_AUTHOR, COMMIT_ID, COMMIT_MESSAGE, GITHUB_REPO);
6+
function setDiscordMessage(author, id, commitMsg, repo) {
7+
const commitMessage = commitMsg.split("\n")[0].replaceAll("`", "").replaceAll("-", "–");
8+
const coAuthors = commitMsg.split("\n").slice(2).filter((line) => line.match(/Co-authored-by: (.+) <.+>/i)).map((line) => line.match(/Co-authored-by: (.+) <.+>/i)[1]).filter((name) => name !== "github-actions[bot]");
9+
let coAuthorThanks = "";
10+
if (coAuthors.length > 0) coAuthorThanks = `\n${getCoAuthorsMessage(formatAsCommaSeparatedList([...new Set(coAuthors)]))}`;
11+
const defaultEmoji = [
12+
"🎉",
13+
"🎊",
14+
"🧑‍🚀",
15+
"🥳",
16+
"🙌",
17+
"🚀"
18+
];
19+
const userEmoji = process.env.EMOJIS?.split(",");
20+
setOutput("DISCORD_MESSAGE", `${pick(userEmoji && userEmoji.length > 0 ? userEmoji : defaultEmoji)} **Merged!** ${author}: [\`${commitMessage}\`](<https://github.com/${repo}/commit/${id}>)${coAuthorThanks}`);
21+
}
22+
function formatAsCommaSeparatedList(list) {
23+
if (list.length === 1) return list[0];
24+
return `${list.slice(0, -1).join(", ")} & ${list.at(-1)}`;
25+
}
26+
function pick(items) {
27+
return items[Math.floor(Math.random() * items.length)];
28+
}
29+
function getCoAuthorsMessage(names) {
30+
let messages = [];
31+
try {
32+
messages = JSON.parse(process.env.COAUTHOR_TEMPLATES || "[]");
33+
} catch (err) {
34+
console.error("Failed to parse `COAUTHOR_TEMPLATES` as JSON. Falling back to default templates.\n ", err);
35+
}
36+
if (!messages || messages.length === 0) messages = [
37+
"Thanks <names> for helping! ✨",
38+
"<names> stepped up to lend a hand — thank you! 🙌",
39+
"<names> with the assist! 💪",
40+
"Couldn't have done this without <names>! 💜",
41+
"Made even better by <names>! 🚀",
42+
"And the team effort award goes to… <names>! 🏆",
43+
"Featuring contributions by <names>! 🌟"
44+
];
45+
return `_${pick(messages).replace("<names>", names).trim()}_`;
46+
}
47+
//#endregion
48+
export {};
49+
50+
//# sourceMappingURL=mergebot.mjs.map

dist/mergebot.mjs.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/utils-DQae65qb.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as crypto from "node:crypto";
2+
import * as fs from "node:fs";
3+
import * as os from "node:os";
4+
//#region src/utils.ts
5+
/** Based on https://github.com/actions/toolkit/blob/4e3b068ce116d28cb840033c02f912100b4592b0/packages/core/src/file-command.ts */
6+
function setOutput(key, value) {
7+
if (process.env.GITHUB_OUTPUT || "") return issueFileCommand("OUTPUT", prepareKeyValueMessage(key, value));
8+
process.stdout.write(os.EOL);
9+
}
10+
function issueFileCommand(command, message) {
11+
const filePath = process.env[`GITHUB_${command}`];
12+
if (!filePath) throw new Error(`Unable to find environment variable for file command ${command}`);
13+
if (!fs.existsSync(filePath)) throw new Error(`Missing file at path: ${filePath}`);
14+
fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, { encoding: "utf8" });
15+
}
16+
function prepareKeyValueMessage(key, value) {
17+
const delimiter = `gh-delimiter-${crypto.randomUUID()}`;
18+
const convertedValue = toCommandValue(value);
19+
if (key.includes(delimiter)) throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
20+
if (convertedValue.includes(delimiter)) throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
21+
return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`;
22+
}
23+
function toCommandValue(input) {
24+
if (input === null || input === void 0) return "";
25+
if (typeof input === "string" || input instanceof String) return input;
26+
return JSON.stringify(input);
27+
}
28+
//#endregion
29+
export { setOutput as t };
30+
31+
//# sourceMappingURL=utils-DQae65qb.mjs.map

dist/utils-DQae65qb.mjs.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/utils.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { t as setOutput } from "./utils-DQae65qb.mjs";
2+
export { setOutput };

0 commit comments

Comments
 (0)