aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2020-11-16 15:26:19 +0100
committerBond_009 <bond.009@outlook.com>2020-11-16 15:26:19 +0100
commit256f1f305fc47b06d470abf66dc3dfdcd1d6b790 (patch)
tree43f167c5795873ab933af9d932102de076cbcd5b /src/utils.rs
parent5f2f7e824f0af2550f2a3d52dfbbe5ea7fba6499 (diff)
Use upstream repo name when no name is specified
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs19
1 files changed, 19 insertions, 0 deletions
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");
+ }
+}