summaryrefslogtreecommitdiffstats
path: root/src/repo.rs
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2023-11-17 21:25:55 +0100
committerCyborus <cyborus@cyborus.xyz>2023-11-17 21:25:55 +0100
commit7fc2bf739094cb7d2f8cd7d6fb24e3e75e40a88c (patch)
tree7ada9b34593aaa934693e19b17c9fd93ba47ae86 /src/repo.rs
parentdecouple repo info from key info (diff)
downloadforgejo-cli-7fc2bf739094cb7d2f8cd7d6fb24e3e75e40a88c.tar.xz
forgejo-cli-7fc2bf739094cb7d2f8cd7d6fb24e3e75e40a88c.zip
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`
Diffstat (limited to 'src/repo.rs')
-rw-r--r--src/repo.rs14
1 files changed, 10 insertions, 4 deletions
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<Url> {
@@ -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()),