send changes to git

This commit is contained in:
Soph :3 2025-12-14 21:19:44 +02:00
parent 4acbd7d2e2
commit dacd524069

View file

@ -2,6 +2,7 @@ import { parseHTML } from "linkedom"
import { ndjsonToJson, prettyStringify, requireBasicAuth, tripleBool, type Change, type Entry } from "./lib";
import * as fs from "fs/promises"
import { existsSync } from "fs";
import { $ } from "bun"
interface ChangeWithMessage {
changes: Change[],
@ -279,10 +280,32 @@ Bun.serve({
})
});
delete changelist_ids[id];
await updateChangelistIds();
try {
await $`git add artists.ndjson`;
await $`git commit -m "Auto-merge."`;
const push = await $`git push origin main`.nothrow();
const out = `${push.stdout}${push.stderr}`;
if (out.includes("its remote counterpart")) {
await $`git pull --rebase`;
const retry = await $`git push origin main`.nothrow();
const retryOut = `${retry.stdout}${retry.stderr}`;
if (!retryOut.includes("main -> main")) {
throw new Error("Push failed after rebase");
}
} else if (!out.includes("main -> main")) {
throw new Error("Push failed");
}
} catch (err) {
console.error("Error:", err);
return new ClientResponse("Failed to automerge to git. Error: " + err, { status: 400 });
}
return new ClientResponse("Merged successfully.");
}
},