GeezerVison is showing github.com — fix(pull-requests): preserve source repository identity · RTVision/t3code@e638a7b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/AzureDevOpsPullRequestProvider.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -81,6 +81,7 @@ function toChangeRequest(pullRequest: AzureDevOpsPullRequest): ProviderChangeReq | 81 | 81 | url: pullRequest.url, | 82 | 82 | author: pullRequest.author, | 83 | 83 | headBranch: pullRequest.headBranch, | | 84 | + headRepositoryNameWithOwner: pullRequest.headRepositoryNameWithOwner, | 84 | 85 | baseBranch: pullRequest.baseBranch, | 85 | 86 | state: pullRequest.state, | 86 | 87 | isDraft: pullRequest.isDraft, | @@ -94,6 +95,9 @@ function toChangeRequest(pullRequest: AzureDevOpsPullRequest): ProviderChangeReq | 94 | 95 | reviewRequestLogins: pullRequest.reviewRequestLogins, | 95 | 96 | // Azure keeps labels on work items rather than on the pull request. | 96 | 97 | labels: [], | | 98 | + ...(pullRequest.isCrossRepository === undefined | | 99 | + ? {} | | 100 | + : { isCrossRepository: pullRequest.isCrossRepository }), | 97 | 101 | }; | 98 | 102 | } | 99 | 103 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/GitHubPullRequestCli.test.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2519,7 +2519,7 @@ layer("GitHubPullRequestCli.layer", (it) => { | 2519 | 2519 | expect(detail.body).toBe("Core body"); | 2520 | 2520 | expect(activity.author?.login).toBe("octocat"); | 2521 | 2521 | 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", | 2523 | 2523 | ); | 2524 | 2524 | expect(callAt(1).args.at(-1)).toBe("author,comments,reviews,commits"); | 2525 | 2525 | }), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/GitLabPullRequestCli.test.ts +63Lines changed: 63 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { afterEach, assert, expect, it, vi } from "@effect/vitest"; | 2 | 2 | import * as Effect from "effect/Effect"; | 3 | 3 | import * as Layer from "effect/Layer"; | | 4 | +import * as Schema from "effect/Schema"; | 4 | 5 | import { ChildProcessSpawner } from "effect/unstable/process"; | 5 | 6 |
| 6 | 7 | import * as GitLabCli from "../sourceControl/GitLabCli.ts"; | @@ -126,6 +127,44 @@ layer("GitLabPullRequestCli.layer", (it) => { | 126 | 127 | }), | 127 | 128 | ); | 128 | 129 |
| | 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 | + | 129 | 168 | it.effect("walks pages at a fixed size, because GitLab pages by offset", () => | 130 | 169 | Effect.gen(function* () { | 131 | 170 | mockedExecute | @@ -869,6 +908,30 @@ layer("GitLabPullRequestCli.layer", (it) => { | 869 | 908 | }), | 870 | 909 | ); | 871 | 910 |
| | 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 | + | 872 | 935 | it.effect("fails the read when GitLab returns something unreadable", () => | 873 | 936 | Effect.gen(function* () { | 874 | 937 | mockedExecute.mockReturnValueOnce(Effect.succeed(output('{"message":"404 Not Found"}'))); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/GitLabPullRequestCli.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -596,7 +596,7 @@ export const make = Effect.gen(function* () { | 596 | 596 | cursorAdvance: input.cursorAdvance, | 597 | 597 | }); | 598 | 598 | } | 599 | | - const decoded = decodeMergeRequestListJson(raw); | | 599 | + const decoded = decodeMergeRequestListJson(raw, input.repository); | 600 | 600 | if (!Result.isSuccess(decoded)) { | 601 | 601 | return Effect.fail( | 602 | 602 | new GitLabMergeRequestReadError({ | @@ -914,7 +914,7 @@ export const make = Effect.gen(function* () { | 914 | 914 | ])}`, | 915 | 915 | }).pipe( | 916 | 916 | Effect.flatMap((result) => { | 917 | | - const decoded = decodeMergeRequestDetailJson(result.stdout.trim()); | | 917 | + const decoded = decodeMergeRequestDetailJson(result.stdout.trim(), input.repository); | 918 | 918 | return Result.isSuccess(decoded) | 919 | 919 | ? Effect.succeed(decoded.success) | 920 | 920 | : Effect.fail( | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/GitLabPullRequestProvider.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -68,6 +68,7 @@ describe("getChangeRequest base freshness", () => { | 68 | 68 | url: "https://gitlab.com/acme/web/-/merge_requests/7", | 69 | 69 | author: null, | 70 | 70 | headBranch: "feat/page", | | 71 | + headRepositoryNameWithOwner: null, | 71 | 72 | baseBranch: "main", | 72 | 73 | state: "open" as const, | 73 | 74 | isDraft: false, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/azureDevOpsPullRequestJson.test.ts +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,8 @@ function pullRequest(overrides: Record<string, unknown> = {}): Record<string, un | 26 | 26 | creationDate: "2026-07-01T00:00:00Z", | 27 | 27 | url: REST_URL, | 28 | 28 | 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, | 29 | 31 | ...overrides, | 30 | 32 | }; | 31 | 33 | } | @@ -50,6 +52,7 @@ describe("decodePullRequestListJson", () => { | 50 | 52 | | 51 | 53 | // Azure prefixes its refs, which no other host does. | 52 | 54 | headBranch: "feat/page", | | 55 | + headRepositoryNameWithOwner: "platform/web", | 53 | 56 | baseBranch: "main", | 54 | 57 | state: "open", | 55 | 58 | isDraft: false, | @@ -144,6 +147,30 @@ describe("decodePullRequestJson", () => { | 144 | 147 | ]); | 145 | 148 | }); | 146 | 149 |
| | 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 | + | 147 | 174 | it("reads auto-complete from whoever armed it, and its absence as nobody", () => { | 148 | 175 | const armed = expectSuccess( | 149 | 176 | decodePullRequestJson( | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/azureDevOpsPullRequestJson.ts +36-11Lines changed: 36 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,8 @@ import { decodeJsonResult } from "@t3tools/shared/schemaJson"; | 14 | 14 |
| 15 | 15 | import { | 16 | 16 | azureDevOpsOrganizationBaseFromRestApiUrl, | | 17 | + azureDevOpsHeadRepositoryNameWithOwner, | | 18 | + azureDevOpsRepositoryNameWithOwner, | 17 | 19 | azureDevOpsPullRequestWebUrl, | 18 | 20 | } from "../sourceControl/azureDevOpsPullRequests.ts"; | 19 | 21 |
| @@ -30,6 +32,18 @@ const RawIdentitySchema = Schema.Struct({ | 30 | 32 | imageUrl: Schema.optional(Schema.NullOr(Schema.String)), | 31 | 33 | }); | 32 | 34 |
| | 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 | + | 33 | 47 | const RawPullRequestSchema = Schema.Struct({ | 34 | 48 | pullRequestId: Schema.Int, | 35 | 49 | title: Schema.String, | @@ -61,17 +75,9 @@ const RawPullRequestSchema = Schema.Struct({ | 61 | 75 | creationDate: TrimmedNonEmptyString, | 62 | 76 | closedDate: Schema.optional(Schema.NullOr(Schema.String)), | 63 | 77 | 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)), | 75 | 81 | _links: Schema.optional( | 76 | 82 | Schema.NullOr( | 77 | 83 | Schema.Struct({ | @@ -123,6 +129,10 @@ export interface AzureDevOpsPullRequest { | 123 | 129 | readonly url: string; | 124 | 130 | readonly author: PullRequestActor | null; | 125 | 131 | 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; | 126 | 136 | readonly baseBranch: string; | 127 | 137 | readonly state: PullRequestState; | 128 | 138 | readonly isDraft: boolean; | @@ -154,6 +164,10 @@ function normalizeRefName(refName: string): string { | 154 | 164 | return refName.trim().replace(/^refs\/heads\//, ""); | 155 | 165 | } | 156 | 166 |
| | 167 | +function normalizeRepositoryIdentity(value: string): string { | | 168 | + return value.trim().toLowerCase(); | | 169 | +} | | 170 | + | 157 | 171 | /** A login has to compare against `az account show`, which reports an email. */ | 158 | 172 | function toActor(raw: Schema.Schema.Type<typeof RawIdentitySchema> | null | undefined) { | 159 | 173 | const login = trimmed(raw?.uniqueName) ?? trimmed(raw?.displayName); | @@ -224,6 +238,15 @@ function toAutoMergeMethod( | 224 | 238 | function toPullRequest( | 225 | 239 | raw: Schema.Schema.Type<typeof RawPullRequestSchema>, | 226 | 240 | ): 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; | 227 | 250 | const autoMergeMethod = toAutoMergeMethod(raw); | 228 | 251 | const reviewers = (raw.reviewers ?? []).flatMap((reviewer) => { | 229 | 252 | const actor = toActor(reviewer); | @@ -249,6 +272,8 @@ function toPullRequest( | 249 | 272 | url, | 250 | 273 | author: toActor(raw.createdBy), | 251 | 274 | headBranch, | | 275 | + headRepositoryNameWithOwner: headRepositoryNameWithOwner ?? null, | | 276 | + ...(typeof isCrossRepository === "boolean" ? { isCrossRepository } : {}), | 252 | 277 | baseBranch, | 253 | 278 | state: toState(raw), | 254 | 279 | isDraft: raw.isDraft ?? false, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/bitbucketPullRequestJson.test.ts +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -106,6 +106,34 @@ describe("decodePullRequestPageJson", () => { | 106 | 106 | }); | 107 | 107 |
| 108 | 108 | 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 | + | 109 | 137 | it("reads reviewers as review requests", () => { | 110 | 138 | const decoded = expectSuccess( | 111 | 139 | decodePullRequestJson( | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/bitbucketPullRequestJson.ts +17-3Lines changed: 17 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -203,6 +203,11 @@ function trimmed(value: string | null | undefined): string | null { | 203 | 203 | return text.length > 0 ? text : null; | 204 | 204 | } | 205 | 205 |
| | 206 | +function qualifiedRepository(value: string | null | undefined): string | null { | | 207 | + const repository = trimmed(value); | | 208 | + return repository?.includes("/") ? repository : null; | | 209 | +} | | 210 | + | 206 | 211 | /** | 207 | 212 | * Bitbucket stamps times as `+00:00` with microseconds. The page sorts change requests from | 208 | 213 | * 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 | 293 | 298 | url: raw.links.html.href, | 294 | 299 | author: toActor(raw.author), | 295 | 300 | headBranch: raw.source.branch.name, | 296 | | - headRepositoryNameWithOwner: raw.source.repository?.full_name ?? null, | | 301 | + headRepositoryNameWithOwner: qualifiedRepository(raw.source.repository?.full_name), | 297 | 302 | baseBranch: raw.destination.branch.name, | 298 | 303 | state: toState(raw), | 299 | 304 | isDraft: raw.draft ?? false, | @@ -328,10 +333,15 @@ export interface BitbucketPage<A> { | 328 | 333 | readonly next: string | null; | 329 | 334 | } | 330 | 335 |
| | 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 | + | 331 | 341 | /** Malformed entries are skipped rather than failing the page, as on the other hosts. */ | 332 | 342 | export function decodePullRequestPageJson( | 333 | 343 | raw: string, | 334 | | -): Result.Result<BitbucketPage<BitbucketPullRequest>, DecodeFailure> { | | 344 | +): Result.Result<BitbucketPullRequestPage, DecodeFailure> { | 335 | 345 | const decoded = decodePage(raw); | 336 | 346 | if (!Result.isSuccess(decoded)) { | 337 | 347 | return Result.fail(decoded.failure); | @@ -343,7 +353,11 @@ export function decodePullRequestPageJson( | 343 | 353 | items.push(toPullRequest(item.value)); | 344 | 354 | } | 345 | 355 | } | 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 | + }); | 347 | 361 | } | 348 | 362 |
| 349 | 363 | export function decodePullRequestJson( | |
|