This commit is contained in:
Cyborus 2023-11-17 15:32:58 -05:00
parent 7fc2bf7390
commit 5999e1e0b5
No known key found for this signature in database
2 changed files with 8 additions and 14 deletions

View file

@ -41,9 +41,7 @@ async fn main() -> eyre::Result<()> {
let host = host.map(|host| Url::parse(&host)).transpose()?; let host = host.map(|host| Url::parse(&host)).transpose()?;
let url = match host { let url = match host {
Some(url) => url, Some(url) => url,
None => { None => repo::RepoInfo::get_current()?.url().clone(),
repo::RepoInfo::get_current()?.url().clone()
}
}; };
let name = keys.get_login(&url)?.username(); let name = keys.get_login(&url)?.username();
eprintln!("currently signed in to {name}@{url}"); eprintln!("currently signed in to {name}@{url}");
@ -65,4 +63,3 @@ async fn readline(msg: &str) -> eyre::Result<String> {
}) })
.await? .await?
} }

View file

@ -1,7 +1,7 @@
use clap::Subcommand; use clap::Subcommand;
use eyre::eyre;
use forgejo_api::CreateRepoOption; use forgejo_api::CreateRepoOption;
use url::Url; use url::Url;
use eyre::eyre;
pub struct RepoInfo { pub struct RepoInfo {
owner: String, owner: String,
@ -14,9 +14,7 @@ impl RepoInfo {
let repo = git2::Repository::open(".")?; let repo = git2::Repository::open(".")?;
let url = get_remote(&repo)?; let url = get_remote(&repo)?;
let mut path = url let mut path = url.path_segments().ok_or_else(|| eyre!("bad path"))?;
.path_segments()
.ok_or_else(|| eyre!("bad path"))?;
let owner = path let owner = path
.next() .next()
.ok_or_else(|| eyre!("path does not have owner name"))? .ok_or_else(|| eyre!("path does not have owner name"))?
@ -26,11 +24,7 @@ impl RepoInfo {
.ok_or_else(|| eyre!("path does not have repo name"))?; .ok_or_else(|| eyre!("path does not have repo name"))?;
let name = name.strip_suffix(".git").unwrap_or(name).to_string(); let name = name.strip_suffix(".git").unwrap_or(name).to_string();
let repo_info = RepoInfo { let repo_info = RepoInfo { owner, name, url };
owner,
name,
url,
};
Ok(repo_info) Ok(repo_info)
} }
pub fn owner(&self) -> &str { pub fn owner(&self) -> &str {
@ -47,7 +41,10 @@ impl RepoInfo {
pub fn host_url(&self) -> Url { pub fn host_url(&self) -> Url {
let mut url = self.url.clone(); let mut url = self.url.clone();
url.path_segments_mut().expect("invalid url: cannot be a base").pop().pop(); url.path_segments_mut()
.expect("invalid url: cannot be a base")
.pop()
.pop();
url url
} }
} }