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

core: fix the repo name from url #266

Merged
merged 1 commit into from
Apr 12, 2024
Merged
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
17 changes: 13 additions & 4 deletions coffee_lib/src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct URL {
}

/// Handle GitHub HTTP links
fn remove_dot_git_from_url(url: &str) -> &str {
pub(crate) fn remove_dot_git_from_url(url: &str) -> &str {
vincenzopalazzo marked this conversation as resolved.
Show resolved Hide resolved
match url.strip_suffix(".git") {
Some(s) => s,
None => url,
Expand All @@ -42,8 +42,9 @@ fn handle_incorrect_url(mut url: &str) -> String {

/// Get repo_name field from the URL
fn get_repo_name_from_url(url: &str) -> String {
let repo_name = url.split('/').last().unwrap().to_string();
repo_name
let repo_name = url.split('/').last().unwrap_or(url);
let repo_name = remove_dot_git_from_url(repo_name);
repo_name.to_owned()
}

impl URL {
Expand All @@ -70,6 +71,7 @@ impl fmt::Display for URL {

#[cfg(test)]
mod tests {
use super::remove_dot_git_from_url;
use super::URL;

#[test]
Expand All @@ -78,6 +80,13 @@ mod tests {
let url = URL::new("/tmp/", u, "lightningd_plugins");
assert_eq!(url.repo_name, "plugins");
assert_eq!(url.url_string, u);
println!("{}", &url);
}

#[test]
fn test_remote_git_prefix() {
let u = "https://github.com/lightningd/plugins.git";
let url = URL::new("/tmp/", u, "lightningd_plugins");
assert_eq!(url.repo_name, "plugins");
assert_eq!(url.url_string, remove_dot_git_from_url(u));
}
}
Loading