Skip to content

Commit dda54a0

Browse files
committed
fix(github): preserve repository viewers and LFS credential scope
Carry repository-specific viewers through the existing server result and web/mobile filters, preserving host and environment fallback. Keep Authored, grouping, me filters and mobile local search correct when organisations use different accounts. Parse the media-host path prefix before selecting a Git credential and test same-repository, rejected redirects and malformed paths. Independent review passes all 26 frozen source hashes and 429 focused tests, with one existing Bun GC exclusion. Server/web types and focused lint/formatting pass; full mobile typechecking remains blocked by absent Expo dependencies.
1 parent f5e0f3c commit dda54a0

9 files changed

Lines changed: 436 additions & 4 deletions

File tree

‎apps/mobile/src/features/pull-requests/pullRequestList.test.ts‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,103 @@ describe("all-environment PR list", () => {
240240
[1, mbp],
241241
]);
242242
});
243+
244+
it("keeps repository viewers through head pages and filters each environment before deduplication", () => {
245+
const rows = [
246+
entry(1, {
247+
repository: "OwnerA/Repo",
248+
author: { login: "Alice", name: null, avatarUrl: null },
249+
}),
250+
entry(2, {
251+
repository: "OwnerB/Repo",
252+
author: { login: "Bob", name: null, avatarUrl: null },
253+
}),
254+
];
255+
const merged = mergeEnvironmentPullRequestPages([
256+
{
257+
environmentId: cups,
258+
pages: pullRequestListHead(null, {
259+
...page(rows),
260+
viewers: {
261+
"github.com": "Alice",
262+
"github.com ownera/repo": "Other",
263+
"github.com ownerb/repo": "Other",
264+
},
265+
}),
266+
},
267+
{
268+
environmentId: mbp,
269+
pages: pullRequestListHead(null, {
270+
...page(rows),
271+
viewers: {
272+
"github.com": "Other",
273+
"github.com ownera/repo": "Alice",
274+
"github.com ownerb/repo": "Bob",
275+
},
276+
}),
277+
},
278+
]);
279+
expect(merged.viewers[`${mbp} github.com ownerb/repo`]).toBe("Bob");
280+
for (const [controls, query] of [
281+
[{ ...DEFAULT_PR_LIST_CONTROLS, involvement: "authored" as const }, ""],
282+
[{ ...DEFAULT_PR_LIST_CONTROLS, filters: { author: "me" } }, ""],
283+
[DEFAULT_PR_LIST_CONTROLS, "author:@me"],
284+
] as const) {
285+
expect(
286+
filterPullRequestList(
287+
merged.entries,
288+
controls,
289+
merged.viewers,
290+
query,
291+
merged.localSearchHosts,
292+
).map((row) => [row.environmentId, row.number]),
293+
).toEqual([
294+
[mbp, 2],
295+
[mbp, 1],
296+
]);
297+
}
298+
});
299+
300+
it("keeps local full-text searches keyed by host with repository viewers", () => {
301+
const rows = [
302+
entry(1, { title: "Needle", repository: "OwnerA/Repo" }),
303+
entry(2, { title: "Other", repository: "OwnerB/Repo" }),
304+
];
305+
const merged = mergeEnvironmentPullRequestPages([
306+
{
307+
environmentId: cups,
308+
pages: pullRequestListHead(null, {
309+
...page(rows),
310+
viewers: {
311+
"github.com": "Other",
312+
"github.com ownera/repo": "octocat",
313+
"github.com ownerb/repo": "octocat",
314+
},
315+
providers: [
316+
{
317+
host: "github.com",
318+
kind: SourceControlProviderKind.make("github"),
319+
searchesOnHost: false,
320+
projectCount: 2,
321+
configured: true,
322+
detail: null,
323+
},
324+
],
325+
}),
326+
},
327+
]);
328+
expect([...merged.localSearchHosts]).toEqual([`${cups} github.com`]);
329+
expect(
330+
filterPullRequestList(
331+
merged.entries,
332+
{ ...DEFAULT_PR_LIST_CONTROLS, involvement: "authored" },
333+
merged.viewers,
334+
"needle",
335+
merged.localSearchHosts,
336+
).map((row) => row.number),
337+
).toEqual([1]);
338+
});
339+
243340
it("scopes a project to its owning environment even if another has the same project id", () => {
244341
const merged = mergeEnvironmentPullRequestPages([
245342
{ environmentId: cups, pages: pullRequestListHead(null, page([entry(1)])) },
@@ -299,6 +396,32 @@ describe("mobile PR scan and filters", () => {
299396
),
300397
).toEqual([1]);
301398
});
399+
400+
it("prefers repository viewers for unscoped entries and retains the host fallback", () => {
401+
const rows = [
402+
entry(1, { repository: "OwnerA/Repo" }),
403+
entry(2, {
404+
repository: "OwnerB/Repo",
405+
author: { login: "Bob", name: null, avatarUrl: null },
406+
}),
407+
entry(3, { repository: "legacy/repo" }),
408+
];
409+
const viewers = {
410+
"github.com": "octocat",
411+
"github.com ownera/repo": "octocat",
412+
"github.com ownerb/repo": "Bob",
413+
};
414+
expect(
415+
filterPullRequestList(
416+
rows,
417+
{ ...DEFAULT_PR_LIST_CONTROLS, involvement: "authored" },
418+
viewers,
419+
"",
420+
new Set(),
421+
).map((row) => row.number),
422+
).toEqual([3, 2, 1]);
423+
});
424+
302425
it("combines label groups, exclusions, draft and review filters", () => {
303426
const rows = [
304427
entry(1, {

‎apps/mobile/src/features/pull-requests/pullRequestList.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export function filterPullRequestList<
215215
if (controls.projectEnvironmentId && entry.environmentId !== controls.projectEnvironmentId)
216216
return false;
217217
const viewerKey = entry.environmentId ? `${entry.environmentId} ${entry.host}` : entry.host;
218-
const viewer = viewers[viewerKey];
218+
const viewer = viewers[`${viewerKey} ${entry.repository.toLowerCase()}`] ?? viewers[viewerKey];
219219
if (controls.involvement === "reviewing" && !entry.viewerReviewRequested) return false;
220220
if (
221221
controls.involvement === "authored" &&

‎apps/server/src/assets/GitHubMediaFetch.test.ts‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,120 @@ const asset = (url: string) => ({
1414
});
1515

1616
describe("repository GitHub media credentials", () => {
17+
it.effect.each([
18+
{ fallback: false, enabled: true, unsupportedPrefix: false },
19+
{ fallback: true, enabled: true, unsupportedPrefix: false },
20+
{ fallback: true, enabled: false, unsupportedPrefix: false },
21+
{ fallback: true, enabled: true, unsupportedPrefix: true },
22+
])(
23+
"uses LFS repository context through redirects: fallback $fallback, opt-in $enabled, unsupported prefix $unsupportedPrefix",
24+
({ fallback, enabled, unsupportedPrefix }) => {
25+
const scopes: Array<string | undefined> = [];
26+
const authorizations: Array<string | undefined> = [];
27+
const redirects = [
28+
"https://raw.githubusercontent.com/OwnerA/Repo/main/image.png",
29+
"https://media.githubusercontent.com/media/ownera/repo/main/image.png",
30+
unsupportedPrefix
31+
? "https://media.githubusercontent.com/OwnerA/Repo/main/image.png"
32+
: "https://media.githubusercontent.com/media/OwnerB/Repo/main/image.png",
33+
];
34+
return Effect.gen(function* () {
35+
const response = yield* githubMediaResponse(
36+
asset("https://media.githubusercontent.com/media/OwnerA/Repo/main/image.png"),
37+
{},
38+
);
39+
expect(response.status).toBe(200);
40+
expect(scopes).toEqual(["OwnerA/Repo"]);
41+
expect(authorizations).toEqual([
42+
"Bearer fake-owner-a",
43+
"Bearer fake-owner-a",
44+
"Bearer fake-owner-a",
45+
enabled ? undefined : "Bearer fake-owner-a",
46+
]);
47+
}).pipe(
48+
Effect.provide(
49+
Layer.mock(GitHubCredentials.GitHubCredentials)({
50+
get: (host, repository) => {
51+
scopes.push(repository);
52+
return Effect.succeed({
53+
host,
54+
...(fallback ? {} : { repository: "ownera/repo" }),
55+
source: fallback ? "settings" : "git",
56+
fingerprint: "fake-a",
57+
token: Redacted.make("fake-owner-a"),
58+
});
59+
},
60+
}),
61+
),
62+
Effect.provideService(
63+
HttpClient.HttpClient,
64+
HttpClient.make((request) => {
65+
const location = redirects[authorizations.length];
66+
authorizations.push(request.headers.authorization);
67+
return Effect.succeed(
68+
HttpClientResponse.fromWeb(
69+
request,
70+
new Response(null, {
71+
status: location === undefined ? 200 : 302,
72+
headers: location === undefined ? { "content-type": "image/png" } : { location },
73+
}),
74+
),
75+
);
76+
}),
77+
),
78+
Effect.provideService(HostProcess.Environment, {
79+
T3CODE_GITHUB_USE_GIT_CREDENTIALS: enabled ? "1" : "0",
80+
}),
81+
Effect.scoped,
82+
);
83+
},
84+
);
85+
86+
it.effect.each([
87+
{ path: "raw.githubusercontent.com/media/Repo/main/image.png", repository: "media/Repo" },
88+
{ path: "media.githubusercontent.com/OwnerA/Repo/main/image.png", repository: undefined },
89+
{ path: "media.githubusercontent.com/Media/OwnerA/Repo/main/image.png", repository: undefined },
90+
{ path: "media.githubusercontent.com/media/OwnerA/Repo", repository: undefined },
91+
{ path: "media.githubusercontent.com/media//Repo/main/image.png", repository: undefined },
92+
{
93+
path: "media.githubusercontent.com/media/Owner%2FA/Repo/main/image.png",
94+
repository: undefined,
95+
},
96+
{
97+
path: "media.githubusercontent.com/media/OwnerA/-Repo/main/image.png",
98+
repository: undefined,
99+
},
100+
])("requires the LFS prefix only on its own host: $path", ({ path, repository }) =>
101+
Effect.gen(function* () {
102+
yield* githubMediaResponse(asset(`https://${path}`), {});
103+
}).pipe(
104+
Effect.provide(
105+
Layer.mock(GitHubCredentials.GitHubCredentials)({
106+
get: (host, selected) => {
107+
expect(selected).toBe(repository);
108+
return Effect.succeed({
109+
host,
110+
source: "settings",
111+
fingerprint: "default",
112+
token: Redacted.make("fake-default"),
113+
});
114+
},
115+
}),
116+
),
117+
Effect.provideService(
118+
HttpClient.HttpClient,
119+
HttpClient.make((request) => {
120+
expect(request.headers.authorization).toBe("Bearer fake-default");
121+
return Effect.succeed(
122+
HttpClientResponse.fromWeb(request, new Response(null, { status: 404 })),
123+
);
124+
}),
125+
),
126+
Effect.provideService(HostProcess.Environment, { T3CODE_GITHUB_USE_GIT_CREDENTIALS: "1" }),
127+
Effect.scoped,
128+
),
129+
);
130+
17131
it.effect.each([true, false])(
18132
"keeps legacy fallback redirect behavior only with opt-in disabled: %s",
19133
(enabled) => {

‎apps/server/src/assets/GitHubMediaFetch.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const SVG_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inlin
5454
const repositoryOf = (source: string) => {
5555
const url = new URL(source);
5656
const parts = url.pathname.split("/");
57+
if (url.hostname.toLowerCase() === "media.githubusercontent.com") {
58+
if (parts[1] !== "media") return null;
59+
parts.splice(1, 1);
60+
}
5761
const repository = `${parts[1]}/${parts[2]}`;
5862
return isCredentialedHost(source) &&
5963
parts.length > 3 &&

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,11 +1665,78 @@ it.effect("keeps opted-in repository viewers and list searches separate for one
16651665
["OwnerB/Repo"],
16661666
);
16671667
assert.strictEqual(next.errors.length, 1);
1668+
assert.deepStrictEqual(next.viewers, {
1669+
"github.com": "Chinoman10",
1670+
"github.com ownerb/repo": "Chinoman10",
1671+
});
16681672
}).pipe(
16691673
Effect.provideService(HostProcess.Environment, { T3CODE_GITHUB_USE_GIT_CREDENTIALS: "1" }),
16701674
),
16711675
);
16721676

1677+
it.effect.each([true, false])(
1678+
"returns repository viewer keys only with Git credentials enabled: %s",
1679+
(enabled) =>
1680+
Effect.gen(function* () {
1681+
let hostLookups = 0;
1682+
const service = yield* makeService({
1683+
projects: [
1684+
project({ id: "p1", title: "A", workspaceRoot: "/a", repository: "OwnerA/Repo" }),
1685+
project({ id: "p2", title: "B", workspaceRoot: "/b", repository: "OwnerB/Repo" }),
1686+
],
1687+
providers: [
1688+
fakeProvider(SourceControlProviderKind.make("github"), {
1689+
getViewer: () =>
1690+
Effect.sync(() => {
1691+
hostLookups++;
1692+
return "host-default";
1693+
}),
1694+
withVerifiedCredential: (input, use) =>
1695+
use({
1696+
accountId: input.repository === "OwnerA/Repo" ? "1" : "2",
1697+
viewer: input.repository === "OwnerA/Repo" ? "Alice" : "Bob",
1698+
credentialFingerprint: `pat:${input.repository}`,
1699+
}),
1700+
listChangeRequests: (input) =>
1701+
Effect.sync(() => {
1702+
assert.strictEqual(
1703+
input.viewer,
1704+
enabled ? (input.repository === "OwnerA/Repo" ? "Alice" : "Bob") : "host-default",
1705+
);
1706+
return {
1707+
items: [
1708+
{
1709+
...changeRequest(1, "2026-07-02T00:00:00Z"),
1710+
author: { login: input.viewer, name: null, avatarUrl: null },
1711+
},
1712+
],
1713+
truncated: false,
1714+
continues: true,
1715+
};
1716+
}),
1717+
}),
1718+
],
1719+
});
1720+
const result = yield* service.list({ state: "open", involvement: "authored" });
1721+
assert.strictEqual(result.entries.length, 2);
1722+
assert.deepStrictEqual(
1723+
result.viewers,
1724+
enabled
1725+
? {
1726+
"github.com": "Alice",
1727+
"github.com ownera/repo": "Alice",
1728+
"github.com ownerb/repo": "Bob",
1729+
}
1730+
: { "github.com": "host-default" },
1731+
);
1732+
assert.strictEqual(hostLookups, enabled ? 0 : 1);
1733+
}).pipe(
1734+
Effect.provideService(HostProcess.Environment, {
1735+
T3CODE_GITHUB_USE_GIT_CREDENTIALS: enabled ? "1" : "0",
1736+
}),
1737+
),
1738+
);
1739+
16731740
it.effect("namespaces ordinary detail caches by repository PAT without a routing RPC", () =>
16741741
Effect.gen(function* () {
16751742
for (const operation of ["summary", "detail"] as const) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,11 @@ export const make = Effect.gen(function* () {
11871187
const viewerResults = yield* resolveViewers(projects, viewerRoots);
11881188
const viewers: Record<string, string> = {};
11891189
for (const result of viewerResults) {
1190-
if (result.viewer !== null) viewers[result.host] = result.viewer;
1190+
if (result.viewer === null) continue;
1191+
if (result.repository !== undefined)
1192+
viewers[listCursorKey(result.host, result.repository)] = result.viewer;
1193+
if (result.repository === undefined || viewers[result.host] === undefined)
1194+
viewers[result.host] = result.viewer;
11911195
}
11921196

11931197
const providers: ReadonlyArray<PullRequestProviderSummary> = [

0 commit comments

Comments
 (0)