Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(projects): decode pasted GitHub branch URLs (#10875)

LANdec0f23fe78d
diff --git a/apps/docs/content/docs/project-resources.fr.mdx b/apps/docs/content/docs/project-resources.fr.mdx
index 60778d8656..795391c0be 100644
--- a/apps/docs/content/docs/project-resources.fr.mdx
+++ b/apps/docs/content/docs/project-resources.fr.mdx
@@ -30,6 +30,8 @@ Un répertoire local ne s'applique qu'au daemon auquel il est lié. Lorsque le d
Ouvrez le projet et cliquez sur **Ajouter un dépôt** dans **Ressources → Dépôts**. Recherchez un dépôt rattaché à l'espace de travail ou collez une URL Git. Les dépôts de l'espace de travail se gèrent dans **Paramètres → Code** ; une fois GitHub connecté, la même page propose **Choisir depuis GitHub** pour importer les dépôts auxquels la GitHub App a accès.
+Coller une URL de branche GitHub (`https://github.com/owner/repo/tree/branch`) renseigne séparément l’URL du dépôt et la branche de départ. Les noms de branche encodés dans l’URL sont décodés ; les paramètres de requête et les ancres de page sont exclus. Vérifiez la branche de départ avant d’ajouter le dépôt.
+
Les dépôts ne se limitent pas à GitHub : toute URL Git accessible par le runtime fonctionne comme ressource de dépôt. Une instance Multica auto-hébergée peut aussi connecter des instances Forgejo, Gitea ou GitLab auto-hébergées dans **Paramètres → Code** ; voir [Fournisseurs Git auto-hébergés](/vcs-integration).
Lors de la création d'un projet, vous pouvez aussi choisir des dépôts directement sous **Dépôts**. Un même projet peut rattacher plusieurs dépôts GitHub.
diff --git a/apps/docs/content/docs/project-resources.ja.mdx b/apps/docs/content/docs/project-resources.ja.mdx
index 7c646eec8f..95a7e11ad6 100644
--- a/apps/docs/content/docs/project-resources.ja.mdx
+++ b/apps/docs/content/docs/project-resources.ja.mdx
@@ -30,6 +30,8 @@ import { LocalDirModeDemo } from "@/components/demos/local-dir-mode-demo";
プロジェクトの **リソース → リポジトリ** で **リポジトリを追加** をクリックします。ワークスペースに紐づけ済みのリポジトリを検索するか、Git URL を貼り付けます。ワークスペースのリポジトリは **設定 → コード** で管理します。GitHub を接続すると、同じページの **GitHub から選択** で、App が認可済みのリポジトリをインポートできます。
+GitHub のブランチ URL(`https://github.com/owner/repo/tree/branch`)を貼り付けると、リポジトリ URL と開始ブランチが別々に入力されます。URL エンコードされたブランチ名はデコードされ、クエリパラメータやページ内アンカーは除外されます。リポジトリを追加する前に開始ブランチを確認してください。
+
リポジトリは GitHub に限定されません。ランタイムがアクセスできる Git URL であれば、どれでもリポジトリリソースとして使えます。セルフホストの Multica では、**設定 → コード** でセルフホストの Forgejo、Gitea、GitLab も接続できます。詳細は[セルフホスト Git ホスティング](/vcs-integration)を参照してください。
プロジェクトの作成時に、**リポジトリ** で直接リポジトリを選ぶこともできます。1 つのプロジェクトには複数の GitHub リポジトリを紐づけられます。
diff --git a/apps/docs/content/docs/project-resources.ko.mdx b/apps/docs/content/docs/project-resources.ko.mdx
index 74aeb9455d..594aea5b81 100644
--- a/apps/docs/content/docs/project-resources.ko.mdx
+++ b/apps/docs/content/docs/project-resources.ko.mdx
@@ -30,6 +30,8 @@ import { LocalDirModeDemo } from "@/components/demos/local-dir-mode-demo";
프로젝트의 **리소스 → 저장소**에서 **저장소 추가**를 클릭합니다. 워크스페이스에 연결된 저장소를 검색하거나 Git URL을 붙여 넣습니다. 워크스페이스 저장소는 **설정 → 코드**에서 관리합니다. GitHub를 연결한 뒤 같은 페이지에서 **GitHub에서 선택**을 통해 App에 승인된 저장소를 가져올 수 있습니다.
+GitHub 브랜치 URL(`https://github.com/owner/repo/tree/branch`)을 붙여 넣으면 저장소 URL과 시작 브랜치가 각각 입력됩니다. URL로 인코딩된 브랜치 이름은 디코딩되며, 쿼리 매개변수와 페이지 앵커는 제외됩니다. 저장소를 추가하기 전에 시작 브랜치를 확인하세요.
+
저장소는 GitHub로 제한되지 않습니다. 런타임이 접근할 수 있는 Git URL이라면 모두 저장소 리소스로 사용할 수 있습니다. 자체 배포한 Multica에서는 **설정 → 코드**에서 자체 호스팅 Forgejo, Gitea, GitLab을 연결할 수도 있습니다. [자체 호스팅 Git 코드 호스팅](/vcs-integration)을 참고하세요.
프로젝트를 만들 때 **Repos**에서 바로 저장소를 선택할 수도 있습니다. 하나의 프로젝트에 여러 GitHub 저장소를 연결할 수 있습니다.
diff --git a/apps/docs/content/docs/project-resources.mdx b/apps/docs/content/docs/project-resources.mdx
index dcb67e2ae8..340d70ea97 100644
--- a/apps/docs/content/docs/project-resources.mdx
+++ b/apps/docs/content/docs/project-resources.mdx
@@ -30,6 +30,8 @@ A local directory only applies to the daemon it is bound to. When the daemon exe
Open the project and click **Add repository** in **Resources → Repositories**. Search for a repository already linked to the workspace, or paste a Git URL. Workspace repositories are managed in **Settings → Code**; once GitHub is connected, the same page offers **Pick from GitHub** to import repositories the App is authorized for.
+Pasting a GitHub branch URL (`https://github.com/owner/repo/tree/branch`) fills in the repository URL and starting branch separately. URL-encoded branch names are decoded; query parameters and page anchors are excluded. Check the starting branch before adding the repository.
+
Repositories are not limited to GitHub: any Git URL the runtime can reach works as a repository resource. Self-hosted Multica can also connect self-hosted Forgejo, Gitea, or GitLab under **Settings → Code**; see [Self-hosted Git hosting](/vcs-integration).
When creating a project, you can also pick repositories directly under **Repos**. One project can link multiple GitHub repositories.
diff --git a/apps/docs/content/docs/project-resources.zh-Hant.mdx b/apps/docs/content/docs/project-resources.zh-Hant.mdx
index d650ab111a..7a3bf85f4e 100644
--- a/apps/docs/content/docs/project-resources.zh-Hant.mdx
+++ b/apps/docs/content/docs/project-resources.zh-Hant.mdx
@@ -30,6 +30,8 @@ import { LocalDirModeDemo } from "@/components/demos/local-dir-mode-demo";
開啟專案,在 **資源 → 倉庫** 中點選 **新增倉庫**。搜尋已關聯到工作區的倉庫,或貼上 Git URL。工作區倉庫在 **設定 → 程式碼** 中維護;連線 GitHub 後,可在同一頁面透過 **從 GitHub 選擇** 匯入 App 已授權的倉庫。
+貼上 GitHub 分支頁面的 URL(`https://github.com/owner/repo/tree/branch`)時,倉庫位址和起始分支會分別填入。經過 URL 編碼的分支名稱會還原,查詢參數和頁面錨點不會算入分支名稱。新增倉庫前請檢查起始分支。
+
倉庫不限於 GitHub:任何執行時能訪問的 Git URL 都可以作為倉庫資源。自部署的 Multica 還可以在 **設定 → 程式碼** 連線自託管的 Forgejo、Gitea 或 GitLab,見[自託管 Git 程式碼託管](/vcs-integration)。
建立專案時,也可以直接在 **Repos** 中選擇倉庫。一個專案可以關聯多個 GitHub 倉庫。
diff --git a/apps/docs/content/docs/project-resources.zh.mdx b/apps/docs/content/docs/project-resources.zh.mdx
index 57a68f7844..401a21b3c2 100644
--- a/apps/docs/content/docs/project-resources.zh.mdx
+++ b/apps/docs/content/docs/project-resources.zh.mdx
@@ -30,6 +30,8 @@ import { LocalDirModeDemo } from "@/components/demos/local-dir-mode-demo";
打开项目,在 **资源 → 仓库** 中点击 **添加仓库**。搜索已关联到工作区的仓库,或粘贴 Git URL。工作区仓库在 **设置 → 代码** 中维护;连接 GitHub 后,可在同一页面通过 **从 GitHub 选择** 导入 App 已授权的仓库。
+粘贴 GitHub 分支页面的 URL(`https://github.com/owner/repo/tree/branch`)时,仓库地址和起始分支会分别填入。经过 URL 编码的分支名会还原,查询参数和页面锚点不会算入分支名。添加仓库前请检查起始分支。
+
仓库不限于 GitHub:任何运行时能访问的 Git URL 都可以作为仓库资源。自部署的 Multica 还可以在 **设置 → 代码** 连接自托管的 Forgejo、Gitea 或 GitLab,见[自托管 Git 代码托管](/vcs-integration)。
创建项目时,也可以直接在 **Repos** 中选择仓库。一个项目可以关联多个 GitHub 仓库。
diff --git a/packages/core/github/repo-ref.test.ts b/packages/core/github/repo-ref.test.ts
index a8b9d904e1..f46139c753 100644
--- a/packages/core/github/repo-ref.test.ts
+++ b/packages/core/github/repo-ref.test.ts
@@ -87,6 +87,30 @@ describe("splitGithubUrlRef", () => {
).toEqual({ url: "https://github.com/multica-ai/multica", ref: "main" });
});
+ it.each([
+ ["feature/%E4%B8%AD%E6%96%87", "feature/中文"],
+ ["release%2F2026-09", "release/2026-09"],
+ ["fix%23issue", "fix#issue"],
+ ["fix%252Fissue", "fix%2Fissue"],
+ ["feature+name", "feature+name"],
+ ["main?tab=readme-ov-file", "main"],
+ ["main#readme", "main"],
+ ["release%2F2026-09/?tab=readme-ov-file#readme", "release/2026-09"],
+ ])("extracts the branch from /tree/%s", (path, ref) => {
+ expect(splitGithubUrlRef(`https://github.com/owner/repo/tree/${path}`)).toEqual({
+ url: "https://github.com/owner/repo",
+ ref,
+ });
+ });
+
+ it.each(["bad%", "%E4%B8", "my%20branch", "%20main", "main%20", "main%3F", "main%2F", "main%00"])(
+ "leaves malformed or invalid encoded refs untouched: %s",
+ (ref) => {
+ const url = `https://github.com/owner/repo/tree/${ref}`;
+ expect(splitGithubUrlRef(url)).toEqual({ url });
+ },
+ );
+
it("leaves a plain clone URL untouched", () => {
for (const url of [
"https://github.com/multica-ai/multica",
diff --git a/packages/core/github/repo-ref.ts b/packages/core/github/repo-ref.ts
index f8726c03b2..bba3d6c73e 100644
--- a/packages/core/github/repo-ref.ts
+++ b/packages/core/github/repo-ref.ts
@@ -116,11 +116,16 @@ export function looksLikeCommitSha(value: string): boolean {
export function splitGithubUrlRef(input: string): { url: string; ref?: string } {
const value = input.trim();
const match = value.match(
- /^(https?:\/\/(?:www\.)?github\.com\/[^/\s]+\/[^/\s]+?)(?:\.git)?\/tree\/(.+)$/i,
+ /^(https?:\/\/(?:www\.)?github\.com\/[^/?#\s]+\/[^/?#\s]+?)(?:\.git)?\/tree\/([^?#]+)(?:[?#].*)?$/i,
);
const [, cloneUrl, rawRef] = match ?? [];
if (!cloneUrl || !rawRef) return { url: value };
- const ref = rawRef.replace(/\/+$/, "");
- if (!ref || validateGitRef(ref).ok === false) return { url: value };
+ let ref: string;
+ try {
+ ref = decodeURIComponent(rawRef.replace(/\/+$/, ""));
+ } catch {
+ return { url: value };
+ }
+ if (!ref || ref !== ref.trim() || validateGitRef(ref).ok === false) return { url: value };
return { url: cloneUrl, ref };
}
diff --git a/packages/views/projects/components/project-resources-github-ref.test.tsx b/packages/views/projects/components/project-resources-github-ref.test.tsx
index 2196292ff3..a947596bf0 100644
--- a/packages/views/projects/components/project-resources-github-ref.test.tsx
+++ b/packages/views/projects/components/project-resources-github-ref.test.tsx
@@ -293,20 +293,20 @@ describe("ProjectResourcesSection — github_repo checkout ref", () => {
expect(createMock).not.toHaveBeenCalled();
});
- it("splits a pasted /tree/ URL into the repo and the branch it points at", async () => {
+ it("saves the decoded branch from a pasted GitHub URL without page parameters", async () => {
renderWithI18n(<ProjectResourcesSection projectId="p1" />);
fireEvent.click(screen.getByRole("button", { name: /add repository/i }));
// What someone copies out of the address bar when they want a branch.
// Stored whole, this is a clone URL that does not exist.
fireEvent.change(screen.getByLabelText(/paste a github url/i), {
- target: { value: "https://github.com/multica-ai/other/tree/release/2026-09" },
+ target: { value: "https://github.com/multica-ai/other/tree/release%2F%E4%B8%AD%E6%96%87?tab=readme-ov-file#readme" },
});
const urlInput = screen.getByLabelText(/paste a github url/i) as HTMLInputElement;
const refInput = screen.getByLabelText(/starting branch/i) as HTMLInputElement;
expect(urlInput.value).toBe("https://github.com/multica-ai/other");
- expect(refInput.value).toBe("release/2026-09");
+ expect(refInput.value).toBe("release/中文");
fireEvent.click(screen.getByRole("button", { name: /^add multica-ai\//i }));
await waitFor(() => expect(createMock).toHaveBeenCalledTimes(1));
@@ -314,7 +314,7 @@ describe("ProjectResourcesSection — github_repo checkout ref", () => {
resource_type: "github_repo",
resource_ref: {
url: "https://github.com/multica-ai/other",
- ref: "release/2026-09",
+ ref: "release/中文",
},
});
});