mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-16 04:34:21 +00:00
## About The Pull Request the guide comment remover no longer steals your edits made between the job being created and being run ## Why It's Good For The Game evil techno goblins stealing my edits fixes #89970 ## Changelog no player facing changes --------- Co-authored-by: harryob <55142896+harryob@users.noreply.github.com>
44 lines
1008 B
JavaScript
44 lines
1008 B
JavaScript
import fs from "fs";
|
|
|
|
const REGEX_COMMENT = /<!--.+?-->/g;
|
|
|
|
// Make sure we only remove default comments
|
|
const comments = [];
|
|
|
|
for (const match of fs
|
|
.readFileSync(".github/PULL_REQUEST_TEMPLATE.md", { encoding: "utf8" })
|
|
.matchAll(REGEX_COMMENT)) {
|
|
comments.push(match[0]);
|
|
}
|
|
|
|
function escapeRegex(string) {
|
|
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
}
|
|
|
|
export async function removeGuideComments({ github, context }) {
|
|
const originalBody = (await github.rest.pulls.get(context.issue)).body;
|
|
|
|
if (!originalBody) {
|
|
console.log("PR body is empty, skipping...");
|
|
return;
|
|
}
|
|
|
|
let newBody = originalBody;
|
|
|
|
for (const comment of comments) {
|
|
newBody = newBody.replace(
|
|
new RegExp(`^\\s*${escapeRegex(comment)}\\s*`, "gm"),
|
|
"\n"
|
|
);
|
|
}
|
|
|
|
if (newBody !== originalBody) {
|
|
await github.rest.pulls.update({
|
|
pull_number: context.payload.pull_request.number,
|
|
repo: context.repo.repo,
|
|
owner: context.repo.owner,
|
|
body: newBody,
|
|
});
|
|
}
|
|
}
|