Files
JeremiahandRoxy a5a4b83a25 Sets prettier to run on the repo (#91379)
Prettier (an auto formatter) is set to only run within the tgui folder
currently. This removes that limitation, allowing it to automatically
format all supported files in the repo (.js, .html, .yml
[etc](https://prettier.io/docs/))

I made a few exceptions for bundled and generated files
I'm of the opinion that code should look uniform and am lazy enough to
want CTRL-S to format files without having to think beyond that
2025-06-05 19:13:02 -04:00

78 lines
1.8 KiB
JavaScript

const FIND_EXISTING_ENTRIES = /### (.+)\n((?:- .+\n)*)/g;
const ENTRY_PATTERN =
/- \[(?<round_id>[0-9]+) @ (?<datetime>.+?)\]\((?<url>.+)\)/;
export const createComment = (servers, existingComment) => {
if (existingComment) {
for (const [, serverName, entries] of existingComment.matchAll(
FIND_EXISTING_ENTRIES,
)) {
let server = servers[serverName];
if (!server) {
server = [];
servers[serverName] = server;
}
for (const line of entries.split("\n")) {
const match = line.match(ENTRY_PATTERN);
if (!match) {
continue;
}
const { round_id: roundIdString, datetime, url } = match.groups;
const round_id = parseInt(roundIdString, 10);
if (server.find((round) => round.round_id === round_id)) {
continue;
}
server.push({
round_id,
datetime,
url,
});
}
}
}
const roundIds = Object.values(servers)
.flat()
.map(({ round_id }) => round_id)
.sort()
.join(", ");
const newHeader = `<!-- test_merge_bot: ${roundIds} -->`;
if (existingComment?.startsWith(newHeader)) {
return null;
}
let totalRounds = 0;
let listOfRounds = "";
for (const [server, rounds] of Object.entries(servers).sort(
([a], [b]) => b - a,
)) {
totalRounds += rounds.length;
listOfRounds += `${"\n"}### ${server}`;
for (const { datetime, round_id, url } of rounds.sort(
(a, b) => b.round_id - a.round_id,
)) {
listOfRounds += `${"\n"}- [${round_id} @ ${datetime}](${url})`;
}
listOfRounds += "\n";
}
return (
newHeader +
`\nThis pull request was test merged in ${totalRounds} round(s).` +
"\n" +
"<details><summary>Round list</summary>\n\n" +
listOfRounds +
"\n</details>\n"
);
};