@devries-cameron20 / t3code Mirror · read-only / commits / c79f618bf8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

feat(issues): a fork lists its upstream's issues and its own (#39159)

Bilal Bakr committed Nov 20, 2026 at 03:59 UTC c79f618bf8e1bb54db3be2c46d14d7809048e1d5
7 files changed +216 -93
apps/server/src/issue/IssueService.test.ts
+34
@@ -283,6 +283,40 @@ describe("IssueService", () => {
283 yield* enterprise.resolveUrl("https://code.acme.test/acme/web/issues/7"),
284 ).toMatchObject({ projectId: "ghes", host: "code.acme.test", key: "7", writable: true });
285
286 + // A fork lists its upstream's issues and its own, counted once, and may write to both.
287 + const fork = project({ id: "fork", repository: "acme/web" });
288 + const forked = yield* makeService({
289 + projects: [
290 + {
291 + ...fork,
292 + repositoryIdentity: {
293 + ...fork.repositoryIdentity!,
294 + origin: { canonicalKey: "github.com/me/web" },
295 + },
296 + },
297 + ],
298 + trackers: [
299 + fakeTracker({
300 + listIssues: (input) =>
301 + Effect.succeed({ items: [issue(input.scope)], nextCursor: null }),
302 + comment: (input) =>
303 + Effect.sync(() => {
304 + writes.push(`${input.scope}#${input.key}`);
305 + }),
306 + }),
307 + ],
308 + });
309 + const listed = yield* forked.list({ state: "open" });
310 + expect(listed.entries.map((entry) => entry.scope).sort()).toEqual(["acme/web", "me/web"]);
311 + expect(listed.trackers).toEqual([expect.objectContaining({ projectCount: 1 })]);
312 + yield* forked.comment({
313 + ...own,
314 + projectId: "fork" as ProjectId,
315 + scope: "me/web",
316 + body: "ok",
317 + });
318 + expect(writes).toEqual(["acme/web#1", "me/web#1"]);
319 +
320 // Another host is not reachable through this project's credentials at all.
321 const elsewhere = yield* Effect.flip(service.detail({ ...own, host: "ghe.example.test" }));
322 expect(elsewhere).toMatchObject({
apps/server/src/issue/IssueService.ts
+48 -37
@@ -1,5 +1,5 @@
1 // A project bound to a standalone tracker (Linear) in settings lists it beside its git host's.
2 -// References outside the project's canonical repository may be read on the same host,
2 +// References outside the project's own repositories (upstream and fork) may be read on the host,
3 // but every write must pass through requireWritable.
4 import * as Context from "effect/Context";
5 import * as Effect from "effect/Effect";
@@ -83,18 +83,14 @@ interface SupportedProject extends ProjectTrackerBinding {
83
84 /**
85 * The git-host path of resolution: the tracker is the host's own, named like the remote's
86 - * provider kind. Null for a project with no remote or a kind no tracker claims.
86 + * provider kind. A fork reads its upstream and its own repository.
87 */
88 -function resolveGitHostBinding(project: OrchestrationProjectShell): ProjectTrackerBinding | null {
89 - const identity = project.repositoryIdentity;
90 - const scope = sourceControlDefinitions.issueScope(identity);
91 - const kind = identity?.provider;
92 - if (!identity || kind === undefined || kind === "unknown" || scope === null) return null;
93 - return {
94 - tracker: IssueTrackerKind.make(kind),
95 - host: sourceControlDefinitions.changeRequestHost(identity, kind),
96 - scope,
97 - };
88 +function resolveGitHostBindings(
89 + project: OrchestrationProjectShell,
90 +): ReadonlyArray<ProjectTrackerBinding> {
91 + return sourceControlDefinitions
92 + .issueBindings(project.repositoryIdentity)
93 + .map((binding) => ({ ...binding, tracker: IssueTrackerKind.make(binding.tracker) }));
94 }
95
96 function findStandaloneIssueUrl(trackers: ReadonlyArray<StandaloneIssueTrackerApi>, value: string) {
@@ -209,12 +205,11 @@ const make = Effect.gen(function* () {
205 ? Effect.succeed(project.repositoryIdentity)
206 : repositoryIdentities.resolve(project.workspaceRoot)
207 ).pipe(
212 - Effect.map((repositoryIdentity) =>
213 - [
214 - resolveStandaloneBinding(binding),
215 - resolveGitHostBinding({ ...project, repositoryIdentity }),
216 - ].filter((candidate) => candidate !== null),
217 - ),
208 + Effect.map((repositoryIdentity) => {
209 + const standalone = resolveStandaloneBinding(binding);
210 + const gitHost = resolveGitHostBindings({ ...project, repositoryIdentity });
211 + return standalone === null ? gitHost : [standalone, ...gitHost];
212 + }),
213 );
214
215 const listProjects = (filter: {
@@ -271,7 +266,7 @@ const make = Effect.gen(function* () {
266 const supported: SupportedProject[] = [];
267 const unimplemented = new Map<
268 string,
274 - { tracker: IssueTrackerKind; projectCount: number }
269 + { tracker: IssueTrackerKind; projectIds: Set<ProjectId> }
270 >();
271 for (const candidate of bound.flat()) {
272 if (host !== undefined && candidate.host !== host && candidate.host !== filter.authority)
@@ -280,8 +275,11 @@ const make = Effect.gen(function* () {
275 if (api === null) {
276 const counted = unimplemented.get(candidate.host);
277 if (counted === undefined)
283 - unimplemented.set(candidate.host, { tracker: candidate.tracker, projectCount: 1 });
284 - else counted.projectCount += 1;
278 + unimplemented.set(candidate.host, {
279 + tracker: candidate.tracker,
280 + projectIds: new Set([candidate.project.id]),
281 + });
282 + else counted.projectIds.add(candidate.project.id);
283 continue;
284 }
285 supported.push({ ...candidate, api });
@@ -292,26 +290,29 @@ const make = Effect.gen(function* () {
290
291 /**
292 * The project whose checkout and credentials serve a reference, and whether the reference is
295 - * the project's own scope. A reference naming another scope on the same tracker and host is
296 - * served by the project but marked read-only. A project with two trackers serves the one the
297 - * reference names.
293 + * one of the project's own scopes. A reference naming another scope on the same tracker and
294 + * host is served by the project but marked read-only. A project with two trackers serves the
295 + * one the reference names.
296 */
297 const requireProject = (
298 ref: IssueScopeRef,
299 ): Effect.Effect<SupportedProject & { readonly writable: boolean }, IssueError> =>
300 listProjects({ projectId: ref.projectId }).pipe(
301 Effect.flatMap(({ supported }) => {
304 - const own = supported.find((candidate) => candidate.tracker === ref.tracker);
305 - if (own === undefined) {
306 - return Effect.fail(new IssueUnavailableError({ reason: "tracker-unsupported" }));
307 - }
308 - const host = ref.host?.trim().toLowerCase() ?? own.host;
309 - if (host !== own.host) {
302 + const host = ref.host?.trim().toLowerCase();
303 + const onHost = supported.filter(
304 + (candidate) =>
305 + candidate.tracker === ref.tracker && (host === undefined || candidate.host === host),
306 + );
307 + const scope = ref.scope.trim();
308 + const own = onHost.find(
309 + (candidate) => candidate.scope.toLowerCase() === scope.toLowerCase(),
310 + );
311 + const served = own ?? onHost[0];
312 + if (served === undefined) {
313 return Effect.fail(new IssueUnavailableError({ reason: "tracker-unsupported" }));
314 }
312 - const scope = ref.scope.trim();
313 - const writable = scope.toLowerCase() === own.scope.toLowerCase();
314 - return Effect.succeed({ ...own, scope, writable });
315 + return Effect.succeed({ ...served, scope, writable: own !== undefined });
316 }),
317 );
318
@@ -360,8 +361,12 @@ const make = Effect.gen(function* () {
361 viewerRequests.set(project.host, request);
362 }
363
363 - // Every project counts, including worktrees of a scope read once below.
364 + // Every project counts once, including worktrees of a scope read once below and forks.
365 + const counted = new Set<string>();
366 for (const project of supported) {
367 + const countKey = `${project.host} ${project.project.id}`;
368 + if (counted.has(countKey)) continue;
369 + counted.add(countKey);
370 const existing = trackers.get(project.host);
371 trackers.set(
372 project.host,
@@ -423,9 +428,15 @@ const make = Effect.gen(function* () {
428 if (page._tag === "Failure") {
429 if (cursor !== undefined) nextCursors[key] = cursor;
430 recordFailure(project, page.failure);
431 + // A fork reads two repositories, so its failure names the one that failed.
432 + const forked = supported.some(
433 + (other) => other.project.id === project.project.id && other.scope !== project.scope,
434 + );
435 errors.push({
436 projectId: project.project.id,
428 - projectTitle: project.project.title,
437 + projectTitle: forked
438 + ? `${project.project.title} (${project.scope})`
439 + : project.project.title,
440 message: trackerDetail(page.failure),
441 });
442 return;
@@ -445,11 +456,11 @@ const make = Effect.gen(function* () {
456 { concurrency: SCOPE_CONCURRENCY, discard: true },
457 );
458
448 - for (const [host, { tracker, projectCount }] of unimplemented) {
459 + for (const [host, { tracker, projectIds }] of unimplemented) {
460 trackers.set(host, {
461 tracker,
462 host,
452 - projectCount,
463 + projectCount: projectIds.size,
464 capabilities: null,
465 configured: false,
466 detail: "Issues cannot be browsed for this host yet.",
packages/client-runtime/src/issueLinks.test.ts
+10 -1
@@ -8,7 +8,7 @@ import { describe, expect, it } from "vite-plus/test";
8
9 import { resolveIssueLinkTarget } from "./issueLinks.ts";
10
11 -const project = (id: string, repository: string) =>
11 +const project = (id: string, repository: string, origin?: string) =>
12 ({
13 id: ProjectId.make(id),
14 environmentId: EnvironmentId.make("env"),
@@ -18,6 +18,7 @@ const project = (id: string, repository: string) =>
18 displayName: repository,
19 owner: repository.split("/")[0],
20 name: repository.split("/")[1],
21 + ...(origin ? { origin: { canonicalKey: `github.com/${origin}`, displayName: origin } } : {}),
22 },
23 }) as never;
24
@@ -40,6 +41,14 @@ describe("resolveIssueLinkTarget", () => {
41 expect(target?.ref).toMatchObject({ tracker: "github", host: "github.com", ...expected });
42 });
43
44 + it("reads a fork's own issue through the fork, not as a borrowed repository", () => {
45 + const target = resolveIssueLinkTarget({
46 + url: "https://github.com/me/web/issues/3",
47 + projects: [project("p1", "acme/api"), project("fork", "acme/web", "me/web")],
48 + });
49 + expect(target?.ref).toMatchObject({ projectId: "fork", scope: "me/web", key: "3" });
50 + });
51 +
52 it("prefers the project bound to the link's own port over one on the bare hostname", () => {
53 const enterprise = (id: string, host: string) =>
54 ({
packages/client-runtime/src/issueLinks.ts
+23 -27
@@ -1,4 +1,8 @@
1 -import type { IssueRef, IssueTrackerConnectionList } from "@t3tools/contracts";
1 +import {
2 + IssueTrackerKind,
3 + type IssueRef,
4 + type IssueTrackerConnectionList,
5 +} from "@t3tools/contracts";
6 import {
7 LINEAR_HOST,
8 LINEAR_KIND,
@@ -10,21 +14,11 @@ import type { EnvironmentProject } from "./state/shell.ts";
14
15 type LinkProject = Pick<EnvironmentProject, "id" | "environmentId" | "repositoryIdentity">;
16
13 -/** The host and scope a project's git-host tracker is bound to, the way the server resolves it. */
14 -function projectIssueBinding(project: LinkProject): {
15 - readonly tracker: string;
16 - readonly host: string;
17 - readonly scope: string;
18 -} | null {
19 - const identity = project.repositoryIdentity;
20 - const scope = sourceControlClients.issueScope(identity);
21 - const kind = identity?.provider;
22 - if (!identity || kind === undefined || kind === "unknown" || scope === null) return null;
23 - return {
24 - tracker: kind,
25 - host: sourceControlClients.changeRequestHost(identity, kind),
26 - scope: scope.toLowerCase(),
27 - };
17 +/** The hosts and scopes a project's git-host tracker is bound to, the way the server resolves them. */
18 +function projectIssueBindings(project: LinkProject) {
19 + return sourceControlClients
20 + .issueBindings(project.repositoryIdentity)
21 + .map((binding) => ({ ...binding, scope: binding.scope.toLowerCase() }));
22 }
23
24 function linkAuthority(url: string): string | null {
@@ -45,8 +39,9 @@ function parseIssueLink(
39 if (parsed !== null || authority === null) return parsed;
40 const hostname = new URL(url).hostname.toLowerCase();
41 for (const project of projects) {
48 - const binding = projectIssueBinding(project);
49 - if (binding === null || (binding.host !== hostname && binding.host !== authority)) continue;
42 + const bindings = projectIssueBindings(project);
43 + if (!bindings.some((binding) => binding.host === hostname || binding.host === authority))
44 + continue;
45 const known = sourceControlClients.parseIssueUrl(url, project.repositoryIdentity?.provider);
46 if (known !== null) return known;
47 }
@@ -140,14 +135,15 @@ export function resolveIssueLinkTarget<Project extends LinkProject>(input: {
135 input.preferredProjectId,
136 );
137 const { definition, link } = parsed;
143 - const onHost = input.projects.flatMap((project) => {
144 - const binding = projectIssueBinding(project);
145 - return binding === null ||
146 - binding.tracker !== definition.kind ||
147 - (binding.host !== link.host && binding.host !== authority)
148 - ? []
149 - : [{ project, binding }];
150 - });
138 + const onHost = input.projects.flatMap((project) =>
139 + projectIssueBindings(project)
140 + .filter(
141 + (binding) =>
142 + binding.tracker === definition.kind &&
143 + (binding.host === link.host || binding.host === authority),
144 + )
145 + .map((binding) => ({ project, binding })),
146 + );
147 const onAuthority = onHost.filter((candidate) => candidate.binding.host === authority);
148 const bound = onAuthority.length > 0 ? onAuthority : onHost;
149 const preferFirst = (candidates: typeof bound) =>
@@ -162,7 +158,7 @@ export function resolveIssueLinkTarget<Project extends LinkProject>(input: {
158 project: lender.project,
159 ref: {
160 projectId: lender.project.id,
165 - tracker: lender.binding.tracker as IssueRef["tracker"],
161 + tracker: IssueTrackerKind.make(lender.binding.tracker),
162 host: lender.binding.host,
163 scope: own === undefined ? link.scope : lender.binding.scope,
164 key: link.key,
packages/client-runtime/src/issueList.ts
+17 -18
@@ -173,25 +173,24 @@ export function issueFilterScopes(
173 for (const [environmentId, page] of held) {
174 for (const project of projects) {
175 if (project.environmentId !== environmentId) continue;
176 - const identity = project.repositoryIdentity;
177 - const kind = identity?.provider as SourceControlProviderKind | undefined;
178 - const scope = sourceControlClients.issueScope(identity);
179 - if (!identity || !kind || scope === null) continue;
180 - const host = sourceControlClients.changeRequestHost(identity, kind);
181 - const tracker = page.answer.trackers.find(
182 - (t) => String(t.tracker) === kind && t.host.toLowerCase() === host.toLowerCase(),
183 - );
184 - if (!tracker?.configured || tracker.capabilities === null) continue;
185 - if (
186 - scopes.some(
187 - (s) => s.input.scope.toLowerCase() === scope.toLowerCase() && s.input.host === host,
176 + for (const { tracker: kind, host, scope } of sourceControlClients.issueBindings(
177 + project.repositoryIdentity,
178 + )) {
179 + const tracker = page.answer.trackers.find(
180 + (t) => String(t.tracker) === kind && t.host.toLowerCase() === host.toLowerCase(),
181 + );
182 + if (!tracker?.configured || tracker.capabilities === null) continue;
183 + if (
184 + scopes.some(
185 + (s) => s.input.scope.toLowerCase() === scope.toLowerCase() && s.input.host === host,
186 + )
187 )
189 - )
190 - continue;
191 - scopes.push({
192 - environmentId,
193 - input: { projectId: project.id, tracker: tracker.tracker, host, scope },
194 - });
188 + continue;
189 + scopes.push({
190 + environmentId,
191 + input: { projectId: project.id, tracker: tracker.tracker, host, scope },
192 + });
193 + }
194 }
195 // A tracker bound in settings (a Linear team) is no repository's; the answer names its scope,
196 // matched or not. Older servers do not, so their rows stand in.
packages/client-runtime/src/sourceControlClients.test.ts
+23
@@ -376,6 +376,29 @@ describe("sourceControlClients project hosts", () => {
376 ).toBe("service");
377 expect(sourceControlClients.repositorySelector({ owner: "o", name: "r" })).toBe("o/r");
378 });
379 +
380 + it.each([
381 + ["https://github.com/acme/web.git", "https://github.com/me/web.git", true],
382 + ["git@github.com:acme/web.git", "https://github.com/me/web.git", true],
383 + ["https://github.com/acme/web.git", "https://gitlab.com/me/web.git", false],
384 + ["https://github.com/acme/web.git", "https://github.com:8443/me/web.git", false],
385 + ["git@github.com:acme/web.git", "https://github.com:8443/me/web.git", false],
386 + ["http://github.com/acme/web.git", "https://github.com/me/web.git", false],
387 + ] as const)(
388 + "reads a fork's issues beside upstream %s's only when origin %s is on its server",
389 + (remoteUrl, originUrl, both) => {
390 + const identity = {
391 + canonicalKey: "github.com/acme/web",
392 + locator: { source: "git-remote" as const, remoteName: "upstream", remoteUrl },
393 + provider: SourceControlProviderKind.make("github"),
394 + displayName: "acme/web",
395 + origin: { canonicalKey: `${new URL(originUrl).hostname}/me/web`, remoteUrl: originUrl },
396 + };
397 + expect(sourceControlClients.issueBindings(identity).map((binding) => binding.scope)).toEqual(
398 + both ? ["acme/web", "me/web"] : ["acme/web"],
399 + );
400 + },
401 + );
402 });
403
404 describe("sourceControlClients.findByPublicDomain", () => {
packages/source-control-core/src/shared/definition.ts
+61 -10
@@ -99,6 +99,13 @@ export type RepositorySelectorIdentity = Pick<
99 export type IssueScopeIdentity = RepositorySelectorIdentity &
100 Partial<Pick<RepositoryIdentity, "canonicalKey">>;
101
102 +/** A git-host tracker a project's issues are read from and filed in. */
103 +export interface IssueBinding {
104 + readonly tracker: SourceControlProviderKind;
105 + readonly host: string;
106 + readonly scope: string;
107 +}
108 +
109 /** A git remote's host, as `recognizeRemote` reads it. */
110 export interface GitRemoteHost {
111 /** Trimmed. */
@@ -705,6 +712,13 @@ export interface SourceControlDefinitionRegistry {
712 ) => string | null;
713 /** Where the project's issues live: the host's `issueScope`, else its repository. */
714 readonly issueScope: (identity: IssueScopeIdentity | null | undefined) => string | null;
715 + /**
716 + * Every repository whose issues are the project's own: its primary one, then the fork its
717 + * `origin` remote names when that is on the same host. Empty for a project with no host.
718 + */
719 + readonly issueBindings: (
720 + identity: RepositoryIdentity | null | undefined,
721 + ) => ReadonlyArray<IssueBinding>;
722 readonly changeRequestHost: <const Kind extends string | undefined>(
723 identity: ChangeRequestHostIdentity,
724 kind: Kind,
@@ -783,6 +797,50 @@ export function makeSourceControlDefinitionRegistry(
797 }
798 return null;
799 };
800 + const issueScope = (identity: IssueScopeIdentity | null | undefined) => {
801 + const scopeOf =
802 + identity?.provider === undefined ? undefined : byKind.get(identity.provider)?.issueScope;
803 + return scopeOf === undefined || identity == null
804 + ? repositorySelector(identity)
805 + : scopeOf(identity);
806 + };
807 + const changeRequestHost = <const Kind extends string | undefined>(
808 + identity: ChangeRequestHostIdentity,
809 + kind: Kind,
810 + ): string | Kind =>
811 + (kind === undefined ? undefined : byKind.get(kind)?.changeRequestHost?.(identity)) ??
812 + projectChangeRequestHost(identity, kind);
813 + const issueBindings = (identity: RepositoryIdentity | null | undefined) => {
814 + const tracker = identity?.provider;
815 + if (!identity || tracker === undefined || tracker === "unknown") return [];
816 + const scope = issueScope(identity);
817 + if (scope === null) return [];
818 + const host = changeRequestHost(identity, tracker);
819 + const primary = { tracker, host, scope };
820 + const origin = identity.origin;
821 + // The origin keeps no provider or web URL, so it is read only on the primary's server. Keys
822 + // drop schemes and ports, so an HTTP origin must match the primary's remote, its web address
823 + // when the remote is SSH, else the issue host.
824 + const originUrl = origin?.remoteUrl === undefined ? null : httpUrl(origin.remoteUrl);
825 + const primaryUrl =
826 + (identity.locator?.remoteUrl === undefined ? null : httpUrl(identity.locator.remoteUrl)) ??
827 + (identity.webUrl === undefined ? null : httpUrl(identity.webUrl));
828 + if (
829 + origin === undefined ||
830 + projectChangeRequestHost(origin, undefined) !==
831 + projectChangeRequestHost(identity, undefined) ||
832 + (originUrl !== null &&
833 + (primaryUrl === null ? originUrl.host !== host : originUrl.origin !== primaryUrl.origin))
834 + )
835 + return [primary];
836 + const originScope = issueScope({
837 + provider: tracker,
838 + canonicalKey: origin.canonicalKey,
839 + displayName: origin.displayName ?? origin.canonicalKey.split("/").slice(1).join("/"),
840 + });
841 + if (originScope === null || originScope.toLowerCase() === scope.toLowerCase()) return [primary];
842 + return [primary, { tracker, host, scope: originScope }];
843 + };
844 return {
845 definitions,
846 get: (kind) =>
@@ -885,16 +943,9 @@ export function makeSourceControlDefinitionRegistry(
943 canonicalRepositoryKey: (key) => repositoryKeyOwner(key)?.canonical ?? canonicalKeyPath(key),
944 findByRepositoryKey: (key) => repositoryKeyOwner(key)?.definition,
945 repositorySelector,
888 - issueScope: (identity) => {
889 - const issueScope =
890 - identity?.provider === undefined ? undefined : byKind.get(identity.provider)?.issueScope;
891 - return issueScope === undefined || identity == null
892 - ? repositorySelector(identity)
893 - : issueScope(identity);
894 - },
895 - changeRequestHost: (identity, kind) =>
896 - (kind === undefined ? undefined : byKind.get(kind)?.changeRequestHost?.(identity)) ??
897 - projectChangeRequestHost(identity, kind),
946 + issueScope,
947 + issueBindings,
948 + changeRequestHost,
949 mediaUrl: (value) => {
950 const url = httpUrl(value);
951 if (url === null) return null;