Skip to content

Commit ff042fd

Browse files
committed
Fix enterprise API url
1 parent 9dbf9ce commit ff042fd

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

public/scripts/workflow.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ async function detectDefaultBranch(repoInfo) {
7676
if (repoInfo.hostname.replace(/^www\./, "") === "github.com") {
7777
apiUrl = `https://api.github.com/repos/${repoInfo.owner}/${repoInfo.repo}`;
7878
} else {
79-
apiUrl = `${origin}/api/v3/repos/${repoInfo.owner}/${repoInfo.repo}`;
79+
apiUrl = `${repoInfo.origin}/api/v3/repos/${repoInfo.owner}/${repoInfo.repo}`;
8080
}
8181

8282
try {
8383
const resp = await fetchWithTimeout(apiUrl, {
8484
headers: { Accept: "application/vnd.github+json" },
8585
});
86-
8786
if (!resp.ok) return null;
8887

8988
const data = await resp.json();

tests/workflow.test.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ describe("detectDefaultBranch", () => {
321321
test("detects default branch via GitHub API", async () => {
322322
global.fetch = jest.fn().mockResolvedValue({
323323
ok: true,
324-
json: () => Promise.resolve({ default_branch: "main" }),
324+
json: () => Promise.resolve({ default_branch: "dev" }),
325325
});
326326
const { detectDefaultBranch } = await import(
327327
"../public/scripts/workflow.js"
@@ -333,13 +333,35 @@ describe("detectDefaultBranch", () => {
333333
repo: "r",
334334
};
335335
const branch = await detectDefaultBranch(repoInfo);
336-
expect(branch).toBe("main");
336+
expect(branch).toBe("dev");
337337
expect(global.fetch).toHaveBeenCalledWith(
338338
"https://api.github.com/repos/o/r",
339339
expect.any(Object),
340340
);
341341
});
342342

343+
test("detects default branch via GitHub Enterprise API", async () => {
344+
global.fetch = jest.fn().mockResolvedValue({
345+
ok: true,
346+
json: () => Promise.resolve({ default_branch: "dev" }),
347+
});
348+
const { detectDefaultBranch } = await import(
349+
"../public/scripts/workflow.js"
350+
);
351+
const repoInfo = {
352+
origin: "https://mycompany.github.com",
353+
hostname: "mycompany.github.com",
354+
owner: "o",
355+
repo: "r",
356+
};
357+
const branch = await detectDefaultBranch(repoInfo);
358+
expect(branch).toBe("dev");
359+
expect(global.fetch).toHaveBeenCalledWith(
360+
"https://mycompany.github.com/api/v3/repos/o/r",
361+
expect.any(Object),
362+
);
363+
});
364+
343365
test("returns null if GitHub API response is not ok", async () => {
344366
global.fetch = jest.fn().mockResolvedValue({ ok: false });
345367
const { detectDefaultBranch } = await import(

0 commit comments

Comments
 (0)