Skip to content

Commit c7b8820

Browse files
core: fix the repo name from url
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent f4208f9 commit c7b8820

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

coffee_lib/src/url.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct URL {
1818
}
1919

2020
/// Handle GitHub HTTP links
21-
fn remove_dot_git_from_url(url: &str) -> &str {
21+
pub(crate) fn remove_dot_git_from_url(url: &str) -> &str {
2222
match url.strip_suffix(".git") {
2323
Some(s) => s,
2424
None => url,
@@ -42,8 +42,9 @@ fn handle_incorrect_url(mut url: &str) -> String {
4242

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

4950
impl URL {
@@ -71,13 +72,21 @@ impl fmt::Display for URL {
7172
#[cfg(test)]
7273
mod tests {
7374
use super::URL;
75+
use super::remove_dot_git_from_url;
7476

7577
#[test]
7678
fn test_remote() {
7779
let u = "https://github.com/lightningd/plugins";
7880
let url = URL::new("/tmp/", u, "lightningd_plugins");
7981
assert_eq!(url.repo_name, "plugins");
8082
assert_eq!(url.url_string, u);
81-
println!("{}", &url);
83+
}
84+
85+
#[test]
86+
fn test_remote_git_prefix() {
87+
let u = "https://github.com/lightningd/plugins.git";
88+
let url = URL::new("/tmp/", u, "lightningd_plugins");
89+
assert_eq!(url.repo_name, "plugins");
90+
assert_eq!(url.url_string, remove_dot_git_from_url(u));
8291
}
8392
}

0 commit comments

Comments
 (0)