mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-10 12:09:33 +01:00
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:
parent
51b180d4a9
commit
7fc2bf7390
1 changed files with 10 additions and 4 deletions
14
src/repo.rs
14
src/repo.rs
|
@ -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()),
|
||||||
|
|
Loading…
Reference in a new issue