Skip to content

Commit 7bdba3f

Browse files
refactor(clients): pull request surfaces ask the forge instead of assuming GitHub
Web and mobile pull request screens still branched on `provider === "github"` and hostname literals: two different GitHub autolink grammars (one in shared, one in web), a mobile review guide that ran GitHub autolinking against every host, a GitHub-only checks link and diff-stats filter, GitHub-only list fallbacks, and link icons, search terms, error filters and clone shorthand hardcoded to GitHub. Each of those now asks the source control client definition: - `referenceAutolinks(text, repositoryUrl)` replaces `referenceAutolinkRepositoryUrl`. GitHub implements it (moved from `@t3tools/shared/githubMarkdownLinks`); web's remark plugin and mobile's markdown rewrite both call it through `changeRequestReferenceAutolinker`. Other hosts link nothing. - `changeRequestChecksUrl`, `changeRequestActionsWhenUnreported` and `changeRequestListScope` carry the GitHub-only checks route, old-server quick actions and host-wide list reads. - `findByPublicDomain` names the host of a link (subdomains included), used for link and theme-source icons on web and mobile. - Command palette terms, the tool-failure filter, the thread status provider name and the clone shorthand come from the definitions. Behaviour changes: the mobile review guide no longer GitHub-links GitLab/Forgejo text; web pull request markdown gains GitHub's full grammar (cross-repository references, short SHAs, mentions) and mobile shows full SHAs as seven characters; mobile asks every host for diff stats; gitlab.com/codeberg.org/bitbucket.org links show their host's mark; the bot filter trusts the server's `isBot`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0f2649c commit 7bdba3f

49 files changed

Lines changed: 578 additions & 354 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/projects/AddProjectScreen.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
getNewProjectPublishTarget,
2222
getNewProjectPublishTargets,
2323
getNewProjectRepository,
24+
defaultHostCloneUrl,
2425
normalizePastedCloneUrl,
2526
parseAddProjectRemoteSource,
2627
resolveAddProjectPath,
@@ -821,7 +822,7 @@ export function AddProjectRepositoryScreen(props: {
821822
autoCorrect={false}
822823
placeholder={
823824
source === "url"
824-
? "https://github.com/org/repo.git"
825+
? (defaultHostCloneUrl("org/repo") ?? "https://example.com/org/repo.git")
825826
: addProjectRemoteSourcePathHint(source)
826827
}
827828
returnKeyType="next"

‎apps/mobile/src/features/pull-requests/PullRequestDiscussionScreen.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
124124
const canReply = permissions.canReply && Boolean(thread);
125125
const resolveLabel = thread?.isResolved ? "Unresolve" : "Resolve";
126126
return (
127-
<PullRequestMarkdownRepository
128-
params={params}
129-
value={detail.data?.provider === "github" ? detail.data.url : null}
130-
>
127+
<PullRequestMarkdownRepository params={params} changeRequest={detail.data}>
131128
<KeyboardAvoidingView automaticOffset behavior="height" className="flex-1 bg-screen">
132129
<NativeStackScreenOptions
133130
options={{ title: "Discussion", unstable_headerSubtitle: `#${params.number}` }}

‎apps/mobile/src/features/pull-requests/PullRequestMarkdown.tsx‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {
1010
} from "./PullRequestMedia";
1111
import { videoMimeType } from "@t3tools/shared/video";
1212
import { createContext, useContext, useCallback, useMemo, useState } from "react";
13-
import { githubMarkdownLinks } from "@t3tools/shared/githubMarkdownLinks";
13+
import { changeRequestReferenceAutolinker } from "@t3tools/client-runtime/pull-request-markdown";
14+
import type { ReferenceAutolink } from "@t3tools/client-runtime/source-control-clients";
15+
import { linkReferenceAutolinks } from "./pullRequestAutolinks";
1416

1517
import { useOpenPullRequest } from "../../native/useOpenPullRequest";
1618
import { SelectableMarkdownText } from "../../native/SelectableMarkdownText";
@@ -26,13 +28,25 @@ import {
2628
import { ThreadMarkdownImageView } from "../threads/ThreadMarkdownImage";
2729
import type { MarkdownImageRenderer } from "../../native/SelectableMarkdownText";
2830

29-
const RepositoryContext = createContext<string | null>(null);
31+
const AutolinksContext = createContext<((text: string) => ReadonlyArray<ReferenceAutolink>) | null>(
32+
null,
33+
);
3034

3135
export function PullRequestMarkdownRepository(props: {
32-
readonly value: string | null;
36+
/** The change request the markdown belongs to, whose host decides what its text links. */
37+
readonly changeRequest: { readonly provider: string; readonly url: string } | null | undefined;
3338
readonly params: PullRequestParams;
3439
readonly children: ReactNode;
3540
}) {
41+
const provider = props.changeRequest?.provider;
42+
const url = props.changeRequest?.url;
43+
const autolinks = useMemo(
44+
() =>
45+
provider === undefined || url === undefined
46+
? null
47+
: changeRequestReferenceAutolinker({ provider, url }),
48+
[provider, url],
49+
);
3650
const target = pullRequestTarget(props.params);
3751
const project = useProject({
3852
environmentId: target.environmentId,
@@ -44,9 +58,9 @@ export function PullRequestMarkdownRepository(props: {
4458
[target.environmentId, cwd],
4559
);
4660
return (
47-
<RepositoryContext value={props.value}>
61+
<AutolinksContext value={autolinks}>
4862
<PullRequestMediaContext value={media}>{props.children}</PullRequestMediaContext>
49-
</RepositoryContext>
63+
</AutolinksContext>
5064
);
5165
}
5266

@@ -103,11 +117,11 @@ function PullRequestMarkdownContent(props: {
103117
readonly markdown: string;
104118
readonly imageGroupMarkdown?: string;
105119
}) {
106-
const repositoryUrl = useContext(RepositoryContext);
120+
const autolinks = useContext(AutolinksContext);
107121
const mediaContext = useContext(PullRequestMediaContext);
108122
const markdown = useMemo(
109-
() => githubMarkdownLinks(props.markdown, repositoryUrl),
110-
[props.markdown, repositoryUrl],
123+
() => linkReferenceAutolinks(props.markdown, autolinks),
124+
[props.markdown, autolinks],
111125
);
112126
const openPullRequest = useOpenPullRequest();
113127
const openLink = useCallback(

‎apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,7 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
385385
}
386386
};
387387
return (
388-
<PullRequestMarkdownRepository
389-
params={params}
390-
value={pr?.provider === "github" ? pr.url : null}
391-
>
388+
<PullRequestMarkdownRepository params={params} changeRequest={pr}>
392389
<View className={Platform.OS === "android" ? "flex-1 bg-header" : "flex-1 bg-screen"}>
393390
<NativeStackScreenOptions
394391
options={{

‎apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { usePullRequestConnected } from "./usePullRequestConnected";
22
import { useAtomValue } from "@effect/atom-react";
33
import { useNavigation } from "@react-navigation/native";
44
import type { PullRequestAction, PullRequestDetail } from "@t3tools/contracts";
5+
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
56
import Animated from "react-native-reanimated";
67
import { PR_ROW_LAYOUT, PR_DISCLOSURE_ENTER, PR_ROW_EXIT } from "./pullRequestAnimations";
78
import { useState } from "react";
@@ -162,7 +163,9 @@ export function PullRequestChecksRow(props: RowProps) {
162163
icon="arrow.up.right"
163164
onPress={() =>
164165
void Linking.openURL(
165-
props.pr.provider === "github" ? `${props.pr.url}/checks` : props.pr.url,
166+
sourceControlClients
167+
.get(props.pr.provider)
168+
.changeRequestChecksUrl?.(props.pr.url) ?? props.pr.url,
166169
)
167170
}
168171
/>

‎apps/mobile/src/features/pull-requests/guide/PullRequestGuideScreen.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
161161
</Toolbar.MenuAction>
162162
</Toolbar.Menu>
163163
</Toolbar>
164-
<PullRequestMarkdownRepository
165-
params={route.params}
166-
value={`https://${route.params.host ?? "github.com"}/${route.params.repository}`}
167-
>
164+
<PullRequestMarkdownRepository params={route.params} changeRequest={detail.data}>
168165
<ScreenScrollView
169166
contentInsetAdjustmentBehavior="automatic"
170167
contentContainerStyle={{ padding: 16, paddingBottom: insets.bottom + 24, gap: 20 }}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DEFAULT_ACTIVITY_FILTER, filterPullRequestActivity } from "./pullReques
44

55
const date = IsoDateTime.make("2026-10-11T00:00:00.000Z");
66
const human: PullRequestActor = { login: "reader", name: null, avatarUrl: null };
7-
const bot: PullRequestActor = { ...human, login: "reviewer[bot]" };
7+
const bot: PullRequestActor = { ...human, login: "reviewer[bot]", isBot: true };
88
const comment = (id: string, author = human, reviewState: string | null = null) => ({
99
id,
1010
author,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const DEFAULT_ACTIVITY_FILTER: ActivityFilter = {
1515
};
1616

1717
function isBot(actor: PullRequestActor | null) {
18-
return actor?.isBot === true || actor?.login.endsWith("[bot]") === true;
18+
return actor?.isBot === true;
1919
}
2020

2121
function eventCount(activity: PullRequestActivity) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { changeRequestReferenceAutolinker } from "@t3tools/client-runtime/pull-request-markdown";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import { linkReferenceAutolinks } from "./pullRequestAutolinks";
5+
6+
const github = changeRequestReferenceAutolinker({
7+
provider: "github",
8+
url: "https://github.com/team/repo/pull/8",
9+
});
10+
11+
describe("linkReferenceAutolinks", () => {
12+
it("links the host's references in prose", () => {
13+
expect(linkReferenceAutolinks("Closes #123, see @julius", github)).toBe(
14+
"Closes [#123](https://github.com/team/repo/issues/123), see [@julius](https://github.com/julius)",
15+
);
16+
});
17+
18+
it("leaves code, links, images, escapes and definitions alone", () => {
19+
const text =
20+
"`#123 @person abc1234`\n\n```\n#123\n```\n\n[#123](https://example.com) ![#123](image.png) https://example.com/#123 [email protected] \\#123 1234567\n\n[ref]: https://example.com/#123";
21+
expect(linkReferenceAutolinks(text, github)).toBe(text);
22+
});
23+
24+
it("does not nest links inside HTML anchors or code", () => {
25+
const text = 'See <a href="https://example.com">#12</a> and <code>#13</code>, then #14.';
26+
expect(linkReferenceAutolinks(text, github)).toBe(
27+
'See <a href="https://example.com">#12</a> and <code>#13</code>, then [#14](https://github.com/team/repo/issues/14).',
28+
);
29+
});
30+
31+
it("leaves markdown unchanged for a host that links nothing", () => {
32+
const gitlab = changeRequestReferenceAutolinker({
33+
provider: "gitlab",
34+
url: "https://gitlab.com/group/project/-/merge_requests/7",
35+
});
36+
expect(linkReferenceAutolinks("Closes #123", gitlab)).toBe("Closes #123");
37+
});
38+
});
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import type { ReferenceAutolink } from "@t3tools/client-runtime/source-control-clients";
2+
import remarkGfm from "remark-gfm";
3+
import remarkParse from "remark-parse";
4+
import { unified } from "unified";
5+
6+
type MarkdownNode = {
7+
readonly type: string;
8+
readonly position?:
9+
| {
10+
readonly start: { readonly offset?: number | undefined };
11+
readonly end: { readonly offset?: number | undefined };
12+
}
13+
| undefined;
14+
readonly children?: readonly MarkdownNode[] | undefined;
15+
};
16+
17+
const parser = unified().use(remarkParse).use(remarkGfm);
18+
const UNLINKED_TYPES = new Set([
19+
"link",
20+
"linkReference",
21+
"image",
22+
"imageReference",
23+
"code",
24+
"inlineCode",
25+
"html",
26+
"definition",
27+
]);
28+
29+
/**
30+
* Rewrites the references `autolinks` finds in the markdown's prose as markdown links, because the
31+
* native renderer takes markdown text. Text is searched as written, escapes included.
32+
*/
33+
export function linkReferenceAutolinks(
34+
markdown: string,
35+
autolinks: ((text: string) => ReadonlyArray<ReferenceAutolink>) | null,
36+
): string {
37+
if (autolinks === null) return markdown;
38+
const edits: { start: number; end: number; value: string }[] = [];
39+
const visit = (node: MarkdownNode) => {
40+
if (UNLINKED_TYPES.has(node.type)) return;
41+
if (node.type === "text") {
42+
const start = node.position?.start.offset;
43+
const end = node.position?.end.offset;
44+
if (start === undefined || end === undefined) return;
45+
for (const link of autolinks(markdown.slice(start, end))) {
46+
edits.push({
47+
start: start + link.index,
48+
end: start + link.index + link.text.length,
49+
value: `[${link.label}](${link.url})`,
50+
});
51+
}
52+
} else if (node.children !== undefined) {
53+
let protectedHtmlDepth = 0;
54+
for (const child of node.children) {
55+
if (child.type === "html") {
56+
const start = child.position?.start.offset;
57+
const end = child.position?.end.offset;
58+
const tag = start === undefined || end === undefined ? "" : markdown.slice(start, end);
59+
for (const match of tag.matchAll(/<(\/)?(?:a|code|pre|script|style)(?=[\s>])[^>]*>/giu)) {
60+
protectedHtmlDepth = Math.max(0, protectedHtmlDepth + (match[1] ? -1 : 1));
61+
}
62+
} else if (protectedHtmlDepth === 0) visit(child);
63+
}
64+
}
65+
};
66+
visit(parser.parse(markdown));
67+
let linked = markdown;
68+
for (let index = edits.length - 1; index >= 0; index--) {
69+
const edit = edits[index]!;
70+
linked = linked.slice(0, edit.start) + edit.value + linked.slice(edit.end);
71+
}
72+
return linked;
73+
}

0 commit comments

Comments
 (0)