diff --git a/src/repo.rs b/src/repo.rs index 9d5fc7a..a2cd210 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -23,8 +23,8 @@ impl RepoInfo { .to_string(); let name = path .next() - .ok_or_else(|| eyre!("path does not have repo name"))? - .to_string(); + .ok_or_else(|| eyre!("path does not have repo name"))?; + let name = name.strip_suffix(".git").unwrap_or(name).to_string(); let repo_info = RepoInfo { owner, @@ -44,6 +44,12 @@ impl RepoInfo { pub fn url(&self) -> &Url { &self.url } + + pub fn host_url(&self) -> Url { + let mut url = self.url.clone(); + url.path_segments_mut().expect("invalid url: cannot be a base").pop().pop(); + url + } } fn get_remote(repo: &git2::Repository) -> eyre::Result { @@ -130,7 +136,7 @@ impl RepoCommand { } RepoCommand::Info => { let repo = RepoInfo::get_current()?; - let api = keys.get_api(repo.url())?; + let api = keys.get_api(&repo.host_url())?; let repo = api.get_repo(repo.owner(), repo.name()).await?; match repo { Some(repo) => { @@ -141,7 +147,7 @@ impl RepoCommand { } RepoCommand::Browse => { let repo = RepoInfo::get_current()?; - let mut url = repo.url().clone(); + let mut url = repo.host_url().clone(); let new_path = format!( "{}/{}/{}", url.path().strip_suffix("/").unwrap_or(url.path()),