From 256f1f305fc47b06d470abf66dc3dfdcd1d6b790 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Mon, 16 Nov 2020 15:26:19 +0100 Subject: Use upstream repo name when no name is specified --- src/utils.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/utils.rs (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..6e737aa --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,19 @@ +pub fn get_repo_name(url: &str) -> &str { + let start = url.rfind('/').unwrap_or_default() + 1; + if url.ends_with(".git") + { + return &url[start..url.len() - 4]; + } + + &url[start..] +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn get_repo_name_test() { + assert_eq!(get_repo_name("https://github.com/Bond-009/git-mirror.git"), "git-mirror"); + } +} -- cgit v1.2.3