send changes to git
This commit is contained in:
parent
4acbd7d2e2
commit
dacd524069
1 changed files with 24 additions and 1 deletions
25
index.ts
25
index.ts
|
|
@ -2,6 +2,7 @@ import { parseHTML } from "linkedom"
|
||||||
import { ndjsonToJson, prettyStringify, requireBasicAuth, tripleBool, type Change, type Entry } from "./lib";
|
import { ndjsonToJson, prettyStringify, requireBasicAuth, tripleBool, type Change, type Entry } from "./lib";
|
||||||
import * as fs from "fs/promises"
|
import * as fs from "fs/promises"
|
||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
|
import { $ } from "bun"
|
||||||
|
|
||||||
interface ChangeWithMessage {
|
interface ChangeWithMessage {
|
||||||
changes: Change[],
|
changes: Change[],
|
||||||
|
|
@ -279,10 +280,32 @@ Bun.serve({
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
delete changelist_ids[id];
|
delete changelist_ids[id];
|
||||||
await updateChangelistIds();
|
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.");
|
return new ClientResponse("Merged successfully.");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue