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, 09:45 UTC
fix(shared): open Forgejo and Gitea /pulls/ tab and commit links (#37703)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Arav Jain committed
Nov 16, 2026 at 12:08 UTC
b0f0c44d228552eb1ce3d43f21b0272ce5fc985f
2 files changed
+7
-3
packages/shared/src/pullRequestAnchor.test.ts
+3
@@ -9,6 +9,7 @@ import {
9
} from "./pullRequestAnchor.ts";
10
11
const gitlab = "https://gitlab.com/group/repo/-/merge_requests/7";
12
+const forgejo = "https://codeberg.org/owner/repo/pulls/7";
13
14
const url = "https://github.com/owner/repo/pull/7";
15
it.each(["discussion_r123", "r123", "discussion-diff-123R5-L9", "discussion-diff-123"])(
@@ -107,6 +108,7 @@ it("handles encoded hashes and rejects invalid line numbers and URLs", () => {
108
it("keeps the commit scope of a PR diff permalink", () => {
109
const sha = "a".repeat(40);
110
expect(pullRequestLinkCommit(`${url}/commits/${sha}#diff-abcR5`)).toBe(sha);
111
+ expect(pullRequestLinkCommit(`${forgejo}/commits/${sha}#diff-abcR5`)).toBe(sha);
112
expect(pullRequestLinkCommit(`${url}/files#diff-abcR5`)).toBeNull();
113
expect(pullRequestLinkCommit(`${gitlab}/diffs?commit_id=${sha}#${"b".repeat(40)}`)).toBe(sha);
114
expect(pullRequestLinkCommit(`${gitlab}/diffs?commit_id=main`)).toBeNull();
@@ -153,6 +155,7 @@ it.each([
155
[`${url}/commits/${"a".repeat(40)}`, "code"],
156
[`${url}/commits`, "commits"],
157
[`${url}/checks?check_run_id=1`, "checks"],
158
+ [`${forgejo}/files`, "code"],
159
[`${gitlab}/diffs`, "code"],
160
[`${gitlab}/commits`, "commits"],
161
[`${gitlab}/pipelines`, "checks"],
packages/shared/src/pullRequestAnchor.ts
+4
-3
@@ -39,9 +39,10 @@ function normalizePullRequestCommentAnchor(anchor: string): string {
39
);
40
}
41
42
-// GitHub pull request tabs and their GitLab merge request equivalents.
42
+// GitHub pull request tabs and their GitLab merge request equivalents. Forgejo and Gitea spell the
43
+// path `/pulls/`.
44
function pullRequestPathTab(pathname: string): PullRequestAnchor | null {
44
- const tab = /\/(?:pull|-\/merge_requests)\/\d+\/([a-z]+)(?:\/(.*))?$/i.exec(pathname);
45
+ const tab = /\/(?:pulls?|-\/merge_requests)\/\d+\/([a-z]+)(?:\/(.*))?$/i.exec(pathname);
46
const rest = tab?.[2] ?? "";
47
switch (tab?.[1]?.toLowerCase()) {
48
case "files":
@@ -206,7 +207,7 @@ export function pullRequestLinkCommit(url: string | null | undefined): string |
207
const { pathname, searchParams } = new URL(url);
208
const commit = /\/-\/merge_requests\/\d+\/diffs\/?$/i.test(pathname)
209
? searchParams.get("commit_id")
209
- : /\/pull\/\d+\/commits\/([a-f0-9]{40})\/?$/i.exec(pathname)?.[1];
210
+ : /\/pulls?\/\d+\/commits\/([a-f0-9]{40})\/?$/i.exec(pathname)?.[1];
211
return commit && /^[a-f0-9]{40}$/i.test(commit) ? commit : null;
212
} catch {
213
return null;