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

View file

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