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

125 lines
3.0 KiB
JavaScript

import fetch from "node-fetch";
import { createComment } from "./comment.js";
const TEST_MERGE_COMMENT_HEADER = "<!-- test_merge_bot:";
const { GET_TEST_MERGES_URL } = process.env;
if (!GET_TEST_MERGES_URL) {
console.error("GET_TEST_MERGES_URL was not set.");
process.exit(1);
}
export async function processTestMerges({ github, context }) {
const rounds = await fetch(GET_TEST_MERGES_URL)
.then(async (response) => {
if (response.status !== 200) {
return Promise.reject(
`Failed to fetch test merges: ${
response.status
} ${await response.text()}`,
);
}
return response;
})
.then((response) => response.json())
.catch((error) => {
console.error(error);
process.exit(1);
});
// PR # -> server name -> test merge struct
const testMergesPerPr = {};
for (const round of rounds) {
const { server, test_merges } = round;
for (const testMerge of test_merges) {
if (!testMergesPerPr[testMerge]) {
testMergesPerPr[testMerge] = {};
}
if (!testMergesPerPr[testMerge][server]) {
testMergesPerPr[testMerge][server] = [];
}
testMergesPerPr[testMerge][server].push(round);
}
}
for (const [prNumber, servers] of Object.entries(testMergesPerPr)) {
const comments = await github.graphql(
`
query($owner:String!, $repo:String!, $prNumber:Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $prNumber) {
comments(last: 100) {
nodes {
body
databaseId
author {
login
}
}
}
}
}
}`,
{
owner: context.repo.owner,
repo: context.repo.repo,
prNumber: parseInt(prNumber, 10),
},
);
const existingComment = comments.repository.pullRequest.comments.nodes.find(
(comment) =>
comment.author?.login === "github-actions" &&
comment.body.startsWith(TEST_MERGE_COMMENT_HEADER),
);
const newBody = createComment(servers, existingComment?.body);
if (!newBody) {
console.log(`No changes for PR #${prNumber}`);
continue;
}
if (existingComment === undefined) {
try {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: newBody,
});
} catch (error) {
if (error.status) {
console.error(`Failed to create comment for #{prNumber}`);
console.error(error);
continue;
} else {
throw error;
}
}
} else {
try {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.databaseId,
body: newBody,
});
} catch (error) {
if (error.status) {
console.error(`Failed to update comment for #{prNumber}`);
console.error(error);
continue;
} else {
throw error;
}
}
}
}
}