detect real remote in build step

This commit is contained in:
Vap0r1ze 2024-08-25 19:40:44 -04:00
parent 561cdb26b4
commit 90a60632c6

View file

@ -193,7 +193,13 @@ export const gitRemotePlugin = {
build.onLoad({ filter, namespace: "git-remote" }, async () => { build.onLoad({ filter, namespace: "git-remote" }, async () => {
let remote = process.env.VENCORD_REMOTE; let remote = process.env.VENCORD_REMOTE;
if (!remote) { if (!remote) {
const res = await promisify(exec)("git remote get-url origin", { encoding: "utf-8" }); const headRefRes = await promisify(exec)("git symbolic-ref -q HEAD", { encoding: "utf-8" }).catch(() => ({ stdout: "" }));
const headRef = headRefRes.stdout.trim();
const upstreamRes = await promisify(exec)(`git for-each-ref --format=%(upstream:short) "${headRef}"`, { encoding: "utf-8" })
.catch(() => ({ stdout: "" }));
const remoteName = upstreamRes.stdout.trim().split("/")[0] || "origin";
const res = await promisify(exec)(`git remote get-url ${remoteName}`, { encoding: "utf-8" });
remote = res.stdout.trim() remote = res.stdout.trim()
.replace("https://github.com/", "") .replace("https://github.com/", "")
.replace("git@github.com:", "") .replace("git@github.com:", "")