fix url issues

The old system return the host's url, i.e. `https://codeberg.org`. The
new system returns the repo's url, i.e.
`https://codeberg.org/Cyborus/forgejo-cli`
This commit is contained in:
Cyborus 2023-11-17 15:25:55 -05:00
parent 51b180d4a9
commit 7fc2bf7390
No known key found for this signature in database

View file

@ -23,8 +23,8 @@ impl RepoInfo {
.to_string(); .to_string();
let name = path let name = path
.next() .next()
.ok_or_else(|| eyre!("path does not have repo name"))? .ok_or_else(|| eyre!("path does not have repo name"))?;
.to_string(); let name = name.strip_suffix(".git").unwrap_or(name).to_string();
let repo_info = RepoInfo { let repo_info = RepoInfo {
owner, owner,
@ -44,6 +44,12 @@ impl RepoInfo {
pub fn url(&self) -> &Url { pub fn url(&self) -> &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<Url> { fn get_remote(repo: &git2::Repository) -> eyre::Result<Url> {
@ -130,7 +136,7 @@ impl RepoCommand {
} }
RepoCommand::Info => { RepoCommand::Info => {
let repo = RepoInfo::get_current()?; 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?; let repo = api.get_repo(repo.owner(), repo.name()).await?;
match repo { match repo {
Some(repo) => { Some(repo) => {
@ -141,7 +147,7 @@ impl RepoCommand {
} }
RepoCommand::Browse => { RepoCommand::Browse => {
let repo = RepoInfo::get_current()?; let repo = RepoInfo::get_current()?;
let mut url = repo.url().clone(); let mut url = repo.host_url().clone();
let new_path = format!( let new_path = format!(
"{}/{}/{}", "{}/{}/{}",
url.path().strip_suffix("/").unwrap_or(url.path()), url.path().strip_suffix("/").unwrap_or(url.path()),