Skip to content

feat: support GitHub mirrors and proxy URLs in repo import#103

Open
iarhaaan wants to merge 6 commits into
EdgeTypE:mainfrom
iarhaaan:feat/support-github-proxies
Open

feat: support GitHub mirrors and proxy URLs in repo import#103
iarhaaan wants to merge 6 commits into
EdgeTypE:mainfrom
iarhaaan:feat/support-github-proxies

Conversation

@iarhaaan

@iarhaaan iarhaaan commented Jul 9, 2026

Copy link
Copy Markdown

Description

This PR resolves an issue where the repository import feature strictly validates and rejects GitHub mirror domains and proxy URLs. In regions where ISPs heavily throttle direct GitHub connections, users rely on mirrors or proxy prefixes to fetch code at reasonable speeds.

Changes

  1. Relaxed URL Parsing:
    • Updated parseGitHubUrl to extract double-protocol proxy prefixes (e.g. https://hk.gh-proxy.org/https://github.com/...).
    • Removed strict github.com hostname checking to support mirror domains (e.g. github.com.cnpmjs.org, hub.fastgit.xyz).
  2. Dynamic ZIP URL Construction:
    • Modified fetchGitHubRepo to detect proxy/mirror hostnames and automatically map downloads to standard archive URLs (/archive/refs/heads/branch.zip) instead of codeload.github.com, preventing 403 Forbidden blocks common on public proxies.
  3. Tests Added:
    • Extended integration tests in github-reader.test.js to assert parsing and URL generation for shorthand, standard, proxy-prefixed, and domain-mirror URL schemes.

All unit and integration tests are passing and the extension compiles cleanly.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the GitHub repository import pipeline to accept GitHub mirror/proxy URL formats (including “double-protocol” proxy prefixes) and to construct download ZIP URLs in a way that works better with public proxies/mirrors that block codeload.github.com.

Changes:

  • Extended parseGitHubUrl to extract a proxy prefix and return { hostname, proxyPrefix } alongside { owner, repo, branch }.
  • Updated fetchGitHubRepo ZIP URL construction to use GitHub “archive” URLs for proxy/mirror scenarios instead of always using codeload.github.com.
  • Added integration tests covering parsing and ZIP URL generation for shorthand, standard GitHub, proxy-prefixed, and mirror-domain inputs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/content/files/github-reader.js Relaxes parsing to support proxy/mirror URLs and changes ZIP download URL generation accordingly.
tests/integration/github-reader.test.js Adds integration coverage for parsing and URL construction across proxy/mirror scenarios.
Comments suppressed due to low confidence (1)

src/content/files/github-reader.js:167

  • When a proxy prefix or mirror hostname is used, the constructed download URL is no longer codeload.github.com, and the background fetcher intentionally will not attach a GitHub token (it only sends tokens to codeload.github.com). This means users cannot import private repos via proxy/mirror URLs, and the resulting failures can be misleading. Consider failing fast with a clear error when a token is provided with a proxy/mirror URL.
  const { owner, repo, branch, hostname, proxyPrefix } = parsed;
  const token = String(
    typeof options.token === "string" ? options.token : ""
  ).trim();


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 87 to 91
try {
const url = new URL(trimmed);
if (url.hostname !== "github.com") return null;
const hostname = url.hostname;

const parts = url.pathname.split("/").filter(Boolean);
hostname: "hub.fastgit.xyz",
proxyPrefix: "https://hk.gh-proxy.org/",
});
expect(parseGitHubUrl("https://example.com/nope")).toBeNull();
Comment on lines 74 to +78
// owner/repo shorthand
if (/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(trimmed)) {
const [owner, repo] = trimmed.split("/");
return { owner, repo, branch: "main" };
return { owner, repo, branch: "main", hostname: "github.com", proxyPrefix: "" };
}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment on lines +64 to +68
function isPrivateOrLocal(hostname) {
const host = hostname.toLowerCase().trim();
if (host === "localhost" || host === "[::1]") {
return true;
}
Comment on lines +259 to +263
if (lastFailure && lastFailure.status === 404 && token && (proxyPrefix || hostname !== "github.com")) {
throw new Error(
"Private repositories cannot be imported using proxy or mirror URLs. Please use a direct GitHub URL to use your access token safely."
);
}
Comment on lines 128 to 136
try {
const url = new URL(trimmed);
if (url.hostname !== "github.com") return null;
if (url.protocol !== "http:" && url.protocol !== "https:") return null;
if (isPrivateOrLocal(url.hostname)) return null;

const hostname = url.hostname;

const parts = url.pathname.split("/").filter(Boolean);
if (parts.length < 2) return null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants