GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(pull-requests): preserve source repository identity · RTVision/t3code@e638a7b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • pullRequest
      • AzureDevOpsPullRequestProvider.ts
      • GitHubPullRequestCli.test.ts
      • GitLabPullRequestCli.test.ts
      • GitLabPullRequestCli.ts
      • GitLabPullRequestProvider.test.ts
      • azureDevOpsPullRequestJson.test.ts
      • azureDevOpsPullRequestJson.ts
      • bitbucketPullRequestJson.test.ts
      • bitbucketPullRequestJson.ts
      • gitHubPullRequestJson.test.ts
      • gitHubPullRequestJson.ts
      • gitLabMergeRequestJson.test.ts
      • gitLabMergeRequestJson.ts
    • sourceControl
      • AzureDevOpsCli.test.ts
      • AzureDevOpsSourceControlProvider.test.ts
      • AzureDevOpsSourceControlProvider.ts
      • BitbucketApi.test.ts
      • GitLabCli.test.ts
      • GitLabCli.ts
      • GitLabSourceControlProvider.test.ts
      • GitLabSourceControlProvider.ts
      • azureDevOpsPullRequests.ts
      • bitbucketPullRequests.ts
      • gitLabMergeRequests.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/pullRequest/AzureDevOpsPullRequestProvider.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/AzureDevOpsPullRequestProvider.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function toChangeRequest(pullRequest: AzureDevOpsPullRequest): ProviderChangeReq
8181
url: pullRequest.url,
8282
author: pullRequest.author,
8383
headBranch: pullRequest.headBranch,
84+
headRepositoryNameWithOwner: pullRequest.headRepositoryNameWithOwner,
8485
baseBranch: pullRequest.baseBranch,
8586
state: pullRequest.state,
8687
isDraft: pullRequest.isDraft,
@@ -94,6 +95,9 @@ function toChangeRequest(pullRequest: AzureDevOpsPullRequest): ProviderChangeReq
9495
reviewRequestLogins: pullRequest.reviewRequestLogins,
9596
// Azure keeps labels on work items rather than on the pull request.
9697
labels: [],
98+
...(pullRequest.isCrossRepository === undefined
99+
? {}
100+
: { isCrossRepository: pullRequest.isCrossRepository }),
97101
};
98102
}
99103

Collapse file

‎apps/server/src/pullRequest/GitHubPullRequestCli.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/GitHubPullRequestCli.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2519,7 +2519,7 @@ layer("GitHubPullRequestCli.layer", (it) => {
25192519
expect(detail.body).toBe("Core body");
25202520
expect(activity.author?.login).toBe("octocat");
25212521
expect(callAt(0).args.at(-1)).toBe(
2522-
"number,title,url,author,headRefName,baseRefName,state,isDraft,mergeable,reviewDecision,additions,deletions,createdAt,updatedAt,mergedAt,reviewRequests,labels,statusCheckRollup,body,changedFiles,closedAt,isCrossRepository,headRepositoryOwner,headRefOid,autoMergeRequest",
2522+
"number,title,url,author,headRefName,baseRefName,isCrossRepository,headRepository,headRepositoryOwner,state,isDraft,mergeable,reviewDecision,additions,deletions,createdAt,updatedAt,mergedAt,reviewRequests,labels,statusCheckRollup,body,changedFiles,closedAt,headRefOid,autoMergeRequest",
25232523
);
25242524
expect(callAt(1).args.at(-1)).toBe("author,comments,reviews,commits");
25252525
}),
Collapse file

‎apps/server/src/pullRequest/GitLabPullRequestCli.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/GitLabPullRequestCli.test.ts
+63Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { afterEach, assert, expect, it, vi } from "@effect/vitest";
22
import * as Effect from "effect/Effect";
33
import * as Layer from "effect/Layer";
4+
import * as Schema from "effect/Schema";
45
import { ChildProcessSpawner } from "effect/unstable/process";
56

67
import * as GitLabCli from "../sourceControl/GitLabCli.ts";
@@ -126,6 +127,44 @@ layer("GitLabPullRequestCli.layer", (it) => {
126127
}),
127128
);
128129

130+
it.effect("uses the requested repository for a standard same-project REST row", () =>
131+
Effect.gen(function* () {
132+
// Standard GitLab REST rows commonly carry only the numeric project ids. Equal ids prove
133+
// this is the requested project; the request path supplies its qualified repository name.
134+
mockedExecute.mockReturnValueOnce(
135+
Effect.succeed(
136+
output(
137+
yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown))([
138+
{
139+
iid: 7,
140+
title: "Merge request 7",
141+
web_url: "https://gitlab.com/acme/web/-/merge_requests/7",
142+
source_branch: "feat/page",
143+
target_branch: "main",
144+
source_project_id: 100,
145+
target_project_id: 100,
146+
created_at: "2026-07-01T00:00:00Z",
147+
updated_at: "2026-07-02T00:00:00Z",
148+
},
149+
]),
150+
),
151+
),
152+
);
153+
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
154+
155+
const batch = yield* cli.listMergeRequests({
156+
cwd: "/w",
157+
repository: "acme/web",
158+
state: "open",
159+
involvement: "all",
160+
viewer: "bilal",
161+
limit: 10,
162+
});
163+
164+
expect(batch.items[0]?.headRepositoryNameWithOwner).toBe("acme/web");
165+
}),
166+
);
167+
129168
it.effect("walks pages at a fixed size, because GitLab pages by offset", () =>
130169
Effect.gen(function* () {
131170
mockedExecute
@@ -869,6 +908,30 @@ layer("GitLabPullRequestCli.layer", (it) => {
869908
}),
870909
);
871910

911+
it.effect("uses the requested repository for a standard same-project detail row", () =>
912+
Effect.gen(function* () {
913+
mockedExecute.mockReturnValueOnce(
914+
Effect.succeed(
915+
output(
916+
mergeRequestJson({
917+
source_project_id: 100,
918+
target_project_id: 100,
919+
}),
920+
),
921+
),
922+
);
923+
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
924+
925+
const detail = yield* cli.getMergeRequestDetail({
926+
cwd: "/w",
927+
repository: "acme/web",
928+
number: 7,
929+
});
930+
931+
expect(detail.headRepositoryNameWithOwner).toBe("acme/web");
932+
}),
933+
);
934+
872935
it.effect("fails the read when GitLab returns something unreadable", () =>
873936
Effect.gen(function* () {
874937
mockedExecute.mockReturnValueOnce(Effect.succeed(output('{"message":"404 Not Found"}')));
Collapse file

‎apps/server/src/pullRequest/GitLabPullRequestCli.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/GitLabPullRequestCli.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ export const make = Effect.gen(function* () {
596596
cursorAdvance: input.cursorAdvance,
597597
});
598598
}
599-
const decoded = decodeMergeRequestListJson(raw);
599+
const decoded = decodeMergeRequestListJson(raw, input.repository);
600600
if (!Result.isSuccess(decoded)) {
601601
return Effect.fail(
602602
new GitLabMergeRequestReadError({
@@ -914,7 +914,7 @@ export const make = Effect.gen(function* () {
914914
])}`,
915915
}).pipe(
916916
Effect.flatMap((result) => {
917-
const decoded = decodeMergeRequestDetailJson(result.stdout.trim());
917+
const decoded = decodeMergeRequestDetailJson(result.stdout.trim(), input.repository);
918918
return Result.isSuccess(decoded)
919919
? Effect.succeed(decoded.success)
920920
: Effect.fail(
Collapse file

‎apps/server/src/pullRequest/GitLabPullRequestProvider.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/GitLabPullRequestProvider.test.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe("getChangeRequest base freshness", () => {
6868
url: "https://gitlab.com/acme/web/-/merge_requests/7",
6969
author: null,
7070
headBranch: "feat/page",
71+
headRepositoryNameWithOwner: null,
7172
baseBranch: "main",
7273
state: "open" as const,
7374
isDraft: false,
Collapse file

‎apps/server/src/pullRequest/azureDevOpsPullRequestJson.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/azureDevOpsPullRequestJson.test.ts
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function pullRequest(overrides: Record<string, unknown> = {}): Record<string, un
2626
creationDate: "2026-07-01T00:00:00Z",
2727
url: REST_URL,
2828
repository: { name: "web", project: { name: "platform" } },
29+
// Azure's explicit null fork marker proves this source branch is in the target repository.
30+
forkSource: null,
2931
...overrides,
3032
};
3133
}
@@ -50,6 +52,7 @@ describe("decodePullRequestListJson", () => {
5052
author: { login: "[email protected]", name: "Bilal Hassan" },
5153
// Azure prefixes its refs, which no other host does.
5254
headBranch: "feat/page",
55+
headRepositoryNameWithOwner: "platform/web",
5356
baseBranch: "main",
5457
state: "open",
5558
isDraft: false,
@@ -144,6 +147,30 @@ describe("decodePullRequestJson", () => {
144147
]);
145148
});
146149

150+
it("uses Azure's fork source identity and leaves deleted sources unknown", () => {
151+
const fork = expectSuccess(
152+
decodePullRequestJson(
153+
asJson(
154+
pullRequest({
155+
forkSource: {
156+
repository: { name: "web", project: { name: "contributor" } },
157+
},
158+
}),
159+
),
160+
),
161+
);
162+
expect(fork).toMatchObject({
163+
headRepositoryNameWithOwner: "contributor/web",
164+
isCrossRepository: true,
165+
});
166+
167+
const deleted = expectSuccess(
168+
decodePullRequestJson(asJson(pullRequest({ forkSource: { repository: null } }))),
169+
);
170+
expect(deleted?.headRepositoryNameWithOwner).toBeNull();
171+
expect(deleted?.isCrossRepository).toBeUndefined();
172+
});
173+
147174
it("reads auto-complete from whoever armed it, and its absence as nobody", () => {
148175
const armed = expectSuccess(
149176
decodePullRequestJson(
Collapse file

‎apps/server/src/pullRequest/azureDevOpsPullRequestJson.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/azureDevOpsPullRequestJson.ts
+36-11Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { decodeJsonResult } from "@t3tools/shared/schemaJson";
1414

1515
import {
1616
azureDevOpsOrganizationBaseFromRestApiUrl,
17+
azureDevOpsHeadRepositoryNameWithOwner,
18+
azureDevOpsRepositoryNameWithOwner,
1719
azureDevOpsPullRequestWebUrl,
1820
} from "../sourceControl/azureDevOpsPullRequests.ts";
1921

@@ -30,6 +32,18 @@ const RawIdentitySchema = Schema.Struct({
3032
imageUrl: Schema.optional(Schema.NullOr(Schema.String)),
3133
});
3234

35+
const RawRepositorySchema = Schema.Struct({
36+
name: Schema.optional(Schema.NullOr(Schema.String)),
37+
webUrl: Schema.optional(Schema.NullOr(Schema.String)),
38+
project: Schema.optional(
39+
Schema.NullOr(Schema.Struct({ name: Schema.optional(Schema.NullOr(Schema.String)) })),
40+
),
41+
});
42+
43+
const RawForkSourceSchema = Schema.Struct({
44+
repository: Schema.optional(Schema.NullOr(RawRepositorySchema)),
45+
});
46+
3347
const RawPullRequestSchema = Schema.Struct({
3448
pullRequestId: Schema.Int,
3549
title: Schema.String,
@@ -61,17 +75,9 @@ const RawPullRequestSchema = Schema.Struct({
6175
creationDate: TrimmedNonEmptyString,
6276
closedDate: Schema.optional(Schema.NullOr(Schema.String)),
6377
url: Schema.optional(Schema.NullOr(Schema.String)),
64-
repository: Schema.optional(
65-
Schema.NullOr(
66-
Schema.Struct({
67-
name: Schema.optional(Schema.NullOr(Schema.String)),
68-
webUrl: Schema.optional(Schema.NullOr(Schema.String)),
69-
project: Schema.optional(
70-
Schema.NullOr(Schema.Struct({ name: Schema.optional(Schema.NullOr(Schema.String)) })),
71-
),
72-
}),
73-
),
74-
),
78+
repository: Schema.optional(Schema.NullOr(RawRepositorySchema)),
79+
/** Non-null only when Azure identifies a pull request source fork. */
80+
forkSource: Schema.optional(Schema.NullOr(RawForkSourceSchema)),
7581
_links: Schema.optional(
7682
Schema.NullOr(
7783
Schema.Struct({
@@ -123,6 +129,10 @@ export interface AzureDevOpsPullRequest {
123129
readonly url: string;
124130
readonly author: PullRequestActor | null;
125131
readonly headBranch: string;
132+
/** The qualified source repository, or null if Azure did not resolve it. */
133+
readonly headRepositoryNameWithOwner: string | null;
134+
/** Derived from the source and target repository identities when both are known. */
135+
readonly isCrossRepository?: boolean;
126136
readonly baseBranch: string;
127137
readonly state: PullRequestState;
128138
readonly isDraft: boolean;
@@ -154,6 +164,10 @@ function normalizeRefName(refName: string): string {
154164
return refName.trim().replace(/^refs\/heads\//, "");
155165
}
156166

167+
function normalizeRepositoryIdentity(value: string): string {
168+
return value.trim().toLowerCase();
169+
}
170+
157171
/** A login has to compare against `az account show`, which reports an email. */
158172
function toActor(raw: Schema.Schema.Type<typeof RawIdentitySchema> | null | undefined) {
159173
const login = trimmed(raw?.uniqueName) ?? trimmed(raw?.displayName);
@@ -224,6 +238,15 @@ function toAutoMergeMethod(
224238
function toPullRequest(
225239
raw: Schema.Schema.Type<typeof RawPullRequestSchema>,
226240
): AzureDevOpsPullRequest | null {
241+
const headRepositoryNameWithOwner = azureDevOpsHeadRepositoryNameWithOwner(raw);
242+
const targetRepositoryNameWithOwner = azureDevOpsRepositoryNameWithOwner(raw.repository);
243+
const isCrossRepository =
244+
headRepositoryNameWithOwner !== undefined &&
245+
headRepositoryNameWithOwner !== null &&
246+
targetRepositoryNameWithOwner !== null
247+
? normalizeRepositoryIdentity(headRepositoryNameWithOwner) !==
248+
normalizeRepositoryIdentity(targetRepositoryNameWithOwner)
249+
: undefined;
227250
const autoMergeMethod = toAutoMergeMethod(raw);
228251
const reviewers = (raw.reviewers ?? []).flatMap((reviewer) => {
229252
const actor = toActor(reviewer);
@@ -249,6 +272,8 @@ function toPullRequest(
249272
url,
250273
author: toActor(raw.createdBy),
251274
headBranch,
275+
headRepositoryNameWithOwner: headRepositoryNameWithOwner ?? null,
276+
...(typeof isCrossRepository === "boolean" ? { isCrossRepository } : {}),
252277
baseBranch,
253278
state: toState(raw),
254279
isDraft: raw.isDraft ?? false,
Collapse file

‎apps/server/src/pullRequest/bitbucketPullRequestJson.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/bitbucketPullRequestJson.test.ts
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,34 @@ describe("decodePullRequestPageJson", () => {
106106
});
107107

108108
describe("decodePullRequestJson", () => {
109+
it("keeps a deleted source repository unresolved on detail responses", () => {
110+
const decoded = expectSuccess(
111+
decodePullRequestJson(
112+
JSON.stringify(
113+
pullRequest({
114+
source: { branch: { name: "feat/deleted" }, repository: null },
115+
}),
116+
),
117+
),
118+
);
119+
120+
expect(decoded.headRepositoryNameWithOwner).toBeNull();
121+
});
122+
123+
it("does not treat a bare source repository name as a qualified identity", () => {
124+
const decoded = expectSuccess(
125+
decodePullRequestJson(
126+
JSON.stringify(
127+
pullRequest({
128+
source: { branch: { name: "feat/unqualified" }, repository: { full_name: "web" } },
129+
}),
130+
),
131+
),
132+
);
133+
134+
expect(decoded.headRepositoryNameWithOwner).toBeNull();
135+
});
136+
109137
it("reads reviewers as review requests", () => {
110138
const decoded = expectSuccess(
111139
decodePullRequestJson(
Collapse file

‎apps/server/src/pullRequest/bitbucketPullRequestJson.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/bitbucketPullRequestJson.ts
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ function trimmed(value: string | null | undefined): string | null {
203203
return text.length > 0 ? text : null;
204204
}
205205

206+
function qualifiedRepository(value: string | null | undefined): string | null {
207+
const repository = trimmed(value);
208+
return repository?.includes("/") ? repository : null;
209+
}
210+
206211
/**
207212
* Bitbucket stamps times as `+00:00` with microseconds. The page sorts change requests from
208213
* every host against each other as plain strings, so they are normalized to the same `Z` form
@@ -293,7 +298,7 @@ function toPullRequest(raw: Schema.Schema.Type<typeof RawPullRequestSchema>): Bi
293298
url: raw.links.html.href,
294299
author: toActor(raw.author),
295300
headBranch: raw.source.branch.name,
296-
headRepositoryNameWithOwner: raw.source.repository?.full_name ?? null,
301+
headRepositoryNameWithOwner: qualifiedRepository(raw.source.repository?.full_name),
297302
baseBranch: raw.destination.branch.name,
298303
state: toState(raw),
299304
isDraft: raw.draft ?? false,
@@ -328,10 +333,15 @@ export interface BitbucketPage<A> {
328333
readonly next: string | null;
329334
}
330335

336+
export interface BitbucketPullRequestPage extends BitbucketPage<BitbucketPullRequest> {
337+
/** Rows before decoding; a skipped row cannot silently certify a complete relationship read. */
338+
readonly rawCount: number;
339+
}
340+
331341
/** Malformed entries are skipped rather than failing the page, as on the other hosts. */
332342
export function decodePullRequestPageJson(
333343
raw: string,
334-
): Result.Result<BitbucketPage<BitbucketPullRequest>, DecodeFailure> {
344+
): Result.Result<BitbucketPullRequestPage, DecodeFailure> {
335345
const decoded = decodePage(raw);
336346
if (!Result.isSuccess(decoded)) {
337347
return Result.fail(decoded.failure);
@@ -343,7 +353,11 @@ export function decodePullRequestPageJson(
343353
items.push(toPullRequest(item.value));
344354
}
345355
}
346-
return Result.succeed({ items, next: trimmed(decoded.success.next) });
356+
return Result.succeed({
357+
items,
358+
next: trimmed(decoded.success.next),
359+
rawCount: decoded.success.values.length,
360+
});
347361
}
348362

349363
export function decodePullRequestJson(

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.