Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(forge): allow install private deps with https and gh token #9726

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions crates/cli/src/opts/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static GH_REPO_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[\w-]+/[\w

/// Git repo prefix regex
pub static GH_REPO_PREFIX_REGEX: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"((git@)|(git\+https://)|(https://)|(org-([A-Za-z0-9-])+@))?(?P<brand>[A-Za-z0-9-]+)\.(?P<tld>[A-Za-z0-9-]+)(/|:)")
Regex::new(r"((git@)|(git\+https://)|(https://)|https://(?P<token>[^@]+)@|(org-([A-Za-z0-9-])+@))?(?P<brand>[A-Za-z0-9-]+)\.(?P<tld>[A-Za-z0-9-]+)(/|:)")
.unwrap()
});

Expand Down Expand Up @@ -81,7 +81,15 @@ impl FromStr for Dependency {
let brand = captures.name("brand").unwrap().as_str();
let tld = captures.name("tld").unwrap().as_str();
let project = GH_REPO_PREFIX_REGEX.replace(dependency, "");
Some(format!("https://{brand}.{tld}/{}", project.trim_end_matches(".git")))
if let Some(token) = captures.name("token") {
Some(format!(
"https://{}@{brand}.{tld}/{}",
token.as_str(),
project.trim_end_matches(".git")
))
} else {
Some(format!("https://{brand}.{tld}/{}", project.trim_end_matches(".git")))
}
} else {
// If we don't have a URL and we don't have a valid
// GitHub repository name, then we assume this is the alias.
Expand Down Expand Up @@ -392,4 +400,18 @@ mod tests {
assert_eq!(dep.tag, Some("80eb41b".to_string()));
assert_eq!(dep.alias, None);
}

#[test]
fn can_parse_https_with_github_token() {
// <https://github.com/foundry-rs/foundry/issues/9717>
let dep = Dependency::from_str(
"https://ghp_mytoken@github.com/private-org/precompiles-solidity.git",
)
.unwrap();
assert_eq!(dep.name, "precompiles-solidity");
assert_eq!(
dep.url,
Some("https://ghp_mytoken@github.com/private-org/precompiles-solidity".to_string())
);
}
}
1 change: 1 addition & 0 deletions crates/forge/bin/cmd/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static DEPENDENCY_VERSION_TAG_REGEX: LazyLock<Regex> =
#[command(override_usage = "forge install [OPTIONS] [DEPENDENCIES]...
forge install [OPTIONS] <github username>/<github project>@<tag>...
forge install [OPTIONS] <alias>=<github username>/<github project>@<tag>...
forge install [OPTIONS] <https://<github token>@git url>...)]
forge install [OPTIONS] <https:// git url>...")]
pub struct InstallArgs {
/// The dependencies to install.
Expand Down
Loading