fix(gitea): PRs from a deleted fork are still cross repo

the API drops head.repo once the fork is gone, we read that as a same
repo PR and fetched refs/heads/<name> from origin
This commit is contained in:
Alexander Adam
2026-10-13 22:23:24 +02:00
committed by paseo-bot[bot]
parent ef6a024513
commit c958166402
2 changed files with 21 additions and 1 deletions
@@ -2340,6 +2340,22 @@ describe("createGiteaService", () => {
expect(calls).toContainEqual(["api", "repos/example-user/sample-repo/pulls/5"]);
});
it("keeps a pull request from a deleted fork cross-repository", async () => {
const { service } = makeService((args) =>
args[0] === "api"
? ok(JSON.stringify({ head: { repo: null }, base: { repo: { id: 1 } } }))
: ok(JSON.stringify(STATUS_PR_VIEW)),
);
const target = await service.getPullRequestCheckoutTarget({ cwd: "/repo", number: 5 });
expect(target).toMatchObject({
checkoutRefs: [{ remoteName: "origin", remoteRef: "refs/pull/5/head" }],
headOwnerLogin: null,
isCrossRepository: true,
});
});
it("prefixes the local branch name with the fork owner for a cross-repository checkout", () => {
const { service } = makeService(() => ok(""));
@@ -1465,9 +1465,13 @@ export function createGiteaService(options: CreateGiteaServiceOptions = {}): For
);
const headRepo = pr.head?.repo ?? null;
const baseRepo = pr.base?.repo ?? null;
if (headRepo?.id == null || baseRepo?.id == null || headRepo.id === baseRepo.id) {
if (baseRepo?.id == null || headRepo?.id === baseRepo.id) {
return sameRepo;
}
if (headRepo?.id == null) {
// fork was deleted
return { ...sameRepo, isCrossRepository: true };
}
return {
isCrossRepository: true,
headOwnerLogin: headRepo.owner?.login ?? null,