summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/auth.rs2
-rw-r--r--src/issues.rs26
-rw-r--r--src/main.rs6
-rw-r--r--src/prs.rs46
-rw-r--r--src/release.rs22
-rw-r--r--src/repo.rs45
-rw-r--r--src/user.rs10
-rw-r--r--src/wiki.rs8
8 files changed, 80 insertions, 85 deletions
diff --git a/src/auth.rs b/src/auth.rs
index 44cb20c..c0bd467 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -58,7 +58,7 @@ impl AuthCommand {
Some(key) => key,
None => crate::readline("new key: ").await?.trim().to_string(),
};
- if keys.hosts.get(&user).is_none() {
+ if !keys.hosts.contains_key(&user) {
keys.hosts.insert(
host,
crate::keys::LoginInfo::Application {
diff --git a/src/issues.rs b/src/issues.rs
index a65e3d4..de8822a 100644
--- a/src/issues.rs
+++ b/src/issues.rs
@@ -176,11 +176,11 @@ impl IssueCommand {
repo: _,
title,
body,
- } => create_issue(&repo, &api, title, body).await?,
+ } => create_issue(repo, &api, title, body).await?,
View { id, command } => match command.unwrap_or(ViewCommand::Body) {
- ViewCommand::Body => view_issue(&repo, &api, id.number).await?,
- ViewCommand::Comment { idx } => view_comment(&repo, &api, id.number, idx).await?,
- ViewCommand::Comments => view_comments(&repo, &api, id.number).await?,
+ ViewCommand::Body => view_issue(repo, &api, id.number).await?,
+ ViewCommand::Comment { idx } => view_comment(repo, &api, id.number, idx).await?,
+ ViewCommand::Comments => view_comments(repo, &api, id.number).await?,
},
Search {
repo: _,
@@ -189,21 +189,21 @@ impl IssueCommand {
creator,
assignee,
state,
- } => view_issues(&repo, &api, query, labels, creator, assignee, state).await?,
+ } => view_issues(repo, &api, query, labels, creator, assignee, state).await?,
Edit { issue, command } => match command {
EditCommand::Title { new_title } => {
- edit_title(&repo, &api, issue.number, new_title).await?
+ edit_title(repo, &api, issue.number, new_title).await?
}
EditCommand::Body { new_body } => {
- edit_body(&repo, &api, issue.number, new_body).await?
+ edit_body(repo, &api, issue.number, new_body).await?
}
EditCommand::Comment { idx, new_body } => {
- edit_comment(&repo, &api, issue.number, idx, new_body).await?
+ edit_comment(repo, &api, issue.number, idx, new_body).await?
}
},
- Close { issue, with_msg } => close_issue(&repo, &api, issue.number, with_msg).await?,
- Browse { id } => browse_issue(&repo, &api, id.number).await?,
- Comment { issue, body } => add_comment(&repo, &api, issue.number, body).await?,
+ Close { issue, with_msg } => close_issue(repo, &api, issue.number, with_msg).await?,
+ Browse { id } => browse_issue(repo, &api, id.number).await?,
+ Comment { issue, body } => add_comment(repo, &api, issue.number, body).await?,
}
Ok(())
}
@@ -408,7 +408,7 @@ pub async fn view_comment(repo: &RepoName, api: &Forgejo, id: u64, idx: usize) -
let comment = comments
.get(idx)
.ok_or_else(|| eyre!("comment {idx} doesn't exist"))?;
- print_comment(&comment)?;
+ print_comment(comment)?;
Ok(())
}
@@ -440,7 +440,7 @@ fn print_comment(comment: &Comment) -> eyre::Result<()> {
.as_ref()
.ok_or_else(|| eyre::eyre!("user does not have login"))?;
println!("{} said:", username);
- println!("{}", crate::markdown(&body));
+ println!("{}", crate::markdown(body));
let assets = comment
.assets
.as_ref()
diff --git a/src/main.rs b/src/main.rs
index c26081f..8e7ff0e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -159,9 +159,9 @@ async fn editor(contents: &mut String, ext: Option<&str>) -> eyre::Result<()> {
file.write_all(contents.as_bytes()).await?;
drop(file);
- // Closure acting as a try/catch block so that the temp file is deleted even
+ // Async block acting as a try/catch block so that the temp file is deleted even
// on errors
- let res = (|| async {
+ let res = async {
eprint!("waiting on editor\r");
let flags = get_editor_flags(&editor);
let status = tokio::process::Command::new(editor)
@@ -177,7 +177,7 @@ async fn editor(contents: &mut String, ext: Option<&str>) -> eyre::Result<()> {
eprint!(" \r");
Ok(())
- })()
+ }
.await;
tokio::fs::remove_file(path).await?;
diff --git a/src/prs.rs b/src/prs.rs
index 840ae12..d66dcf5 100644
--- a/src/prs.rs
+++ b/src/prs.rs
@@ -274,7 +274,7 @@ impl PrCommand {
head,
body,
repo: _,
- } => create_pr(&repo, &api, title, base, head, body).await?,
+ } => create_pr(repo, &api, title, base, head, body).await?,
Merge {
pr,
method,
@@ -283,7 +283,7 @@ impl PrCommand {
message,
} => {
merge_pr(
- &repo,
+ repo,
&api,
pr.map(|id| id.number),
method,
@@ -296,26 +296,26 @@ impl PrCommand {
View { id, command } => {
let id = id.map(|id| id.number);
match command.unwrap_or(ViewCommand::Body) {
- ViewCommand::Body => view_pr(&repo, &api, id).await?,
+ ViewCommand::Body => view_pr(repo, &api, id).await?,
ViewCommand::Comment { idx } => {
- let (repo, id) = try_get_pr_number(&repo, &api, id).await?;
+ let (repo, id) = try_get_pr_number(repo, &api, id).await?;
crate::issues::view_comment(&repo, &api, id, idx).await?
}
ViewCommand::Comments => {
- let (repo, id) = try_get_pr_number(&repo, &api, id).await?;
+ let (repo, id) = try_get_pr_number(repo, &api, id).await?;
crate::issues::view_comments(&repo, &api, id).await?
}
- ViewCommand::Labels => view_pr_labels(&repo, &api, id).await?,
+ ViewCommand::Labels => view_pr_labels(repo, &api, id).await?,
ViewCommand::Diff { patch, editor } => {
- view_diff(&repo, &api, id, patch, editor).await?
+ view_diff(repo, &api, id, patch, editor).await?
}
- ViewCommand::Files => view_pr_files(&repo, &api, id).await?,
+ ViewCommand::Files => view_pr_files(repo, &api, id).await?,
ViewCommand::Commits { oneline } => {
- view_pr_commits(&repo, &api, id, oneline).await?
+ view_pr_commits(repo, &api, id, oneline).await?
}
}
}
- Status { id } => view_pr_status(&repo, &api, id.map(|id| id.number)).await?,
+ Status { id } => view_pr_status(repo, &api, id.map(|id| id.number)).await?,
Search {
query,
labels,
@@ -323,38 +323,38 @@ impl PrCommand {
assignee,
state,
repo: _,
- } => view_prs(&repo, &api, query, labels, creator, assignee, state).await?,
+ } => view_prs(repo, &api, query, labels, creator, assignee, state).await?,
Edit { pr, command } => {
let pr = pr.map(|pr| pr.number);
match command {
EditCommand::Title { new_title } => {
- let (repo, id) = try_get_pr_number(&repo, &api, pr).await?;
+ let (repo, id) = try_get_pr_number(repo, &api, pr).await?;
crate::issues::edit_title(&repo, &api, id, new_title).await?
}
EditCommand::Body { new_body } => {
- let (repo, id) = try_get_pr_number(&repo, &api, pr).await?;
+ let (repo, id) = try_get_pr_number(repo, &api, pr).await?;
crate::issues::edit_body(&repo, &api, id, new_body).await?
}
EditCommand::Comment { idx, new_body } => {
- let (repo, id) = try_get_pr_number(&repo, &api, pr).await?;
+ let (repo, id) = try_get_pr_number(repo, &api, pr).await?;
crate::issues::edit_comment(&repo, &api, id, idx, new_body).await?
}
EditCommand::Labels { add, rm } => {
- edit_pr_labels(&repo, &api, pr, add, rm).await?
+ edit_pr_labels(repo, &api, pr, add, rm).await?
}
}
}
Close { pr, with_msg } => {
- let (repo, pr) = try_get_pr_number(&repo, &api, pr.map(|pr| pr.number)).await?;
+ let (repo, pr) = try_get_pr_number(repo, &api, pr.map(|pr| pr.number)).await?;
crate::issues::close_issue(&repo, &api, pr, with_msg).await?
}
- Checkout { pr, branch_name } => checkout_pr(&repo, &api, pr, branch_name).await?,
+ Checkout { pr, branch_name } => checkout_pr(repo, &api, pr, branch_name).await?,
Browse { id } => {
- let (repo, id) = try_get_pr_number(&repo, &api, id.map(|pr| pr.number)).await?;
+ let (repo, id) = try_get_pr_number(repo, &api, id.map(|pr| pr.number)).await?;
browse_pr(&repo, &api, id).await?
}
Comment { pr, body } => {
- let (repo, pr) = try_get_pr_number(&repo, &api, pr.map(|pr| pr.number)).await?;
+ let (repo, pr) = try_get_pr_number(repo, &api, pr.map(|pr| pr.number)).await?;
crate::issues::add_comment(&repo, &api, pr, body).await?
}
}
@@ -747,7 +747,7 @@ async fn edit_pr_labels(
for label_name in &add {
let maybe_label = labels
.iter()
- .find(|label| label.name.as_ref() == Some(&label_name));
+ .find(|label| label.name.as_ref() == Some(label_name));
if let Some(label) = maybe_label {
add_ids.push(serde_json::Value::Number(
label.id.ok_or_eyre("label does not have id")?.into(),
@@ -761,7 +761,7 @@ async fn edit_pr_labels(
for label_name in &rm {
let maybe_label = labels
.iter()
- .find(|label| label.name.as_ref() == Some(&label_name));
+ .find(|label| label.name.as_ref() == Some(label_name));
if let Some(label) = maybe_label {
rm_ids.push(label.id.ok_or_eyre("label does not have id")?);
} else {
@@ -865,7 +865,7 @@ async fn create_pr(
let (base, base_is_parent) = match base {
Some(base) => match base.strip_prefix("^") {
- Some(stripped) if stripped.is_empty() => (None, true),
+ Some("") => (None, true),
Some(stripped) => (Some(stripped.to_owned()), true),
None => (Some(base), false),
},
@@ -1291,7 +1291,7 @@ async fn view_pr_commits(
.ok_or_eyre("commit does not have commit?")?;
let message = repo_commit.message.as_deref().unwrap_or("[no msg]");
- let name = message.lines().next().unwrap_or(&message);
+ let name = message.lines().next().unwrap_or(message);
let sha = commit
.sha
diff --git a/src/release.rs b/src/release.rs
index fa9d7d7..49dd5b5 100644
--- a/src/release.rs
+++ b/src/release.rs
@@ -127,7 +127,7 @@ pub enum AssetCommand {
impl ReleaseCommand {
pub async fn run(self, keys: &mut KeyInfo, remote_name: Option<&str>) -> eyre::Result<()> {
let repo = RepoInfo::get_current(remote_name, self.repo.as_ref(), self.remote.as_deref())?;
- let api = keys.get_api(&repo.host_url()).await?;
+ let api = keys.get_api(repo.host_url()).await?;
let repo = repo
.name()
.ok_or_eyre("couldn't get repo name, try specifying with --repo")?;
@@ -143,7 +143,7 @@ impl ReleaseCommand {
prerelease,
} => {
create_release(
- &repo, &api, name, create_tag, tag, attach, body, branch, draft, prerelease,
+ repo, &api, name, create_tag, tag, attach, body, branch, draft, prerelease,
)
.await?
}
@@ -154,32 +154,32 @@ impl ReleaseCommand {
body,
draft,
prerelease,
- } => edit_release(&repo, &api, name, rename, tag, body, draft, prerelease).await?,
+ } => edit_release(repo, &api, name, rename, tag, body, draft, prerelease).await?,
ReleaseSubcommand::Delete { name, by_tag } => {
- delete_release(&repo, &api, name, by_tag).await?
+ delete_release(repo, &api, name, by_tag).await?
}
ReleaseSubcommand::List {
include_prerelease,
include_draft,
- } => list_releases(&repo, &api, include_prerelease, include_draft).await?,
+ } => list_releases(repo, &api, include_prerelease, include_draft).await?,
ReleaseSubcommand::View { name, by_tag } => {
- view_release(&repo, &api, name, by_tag).await?
+ view_release(repo, &api, name, by_tag).await?
}
- ReleaseSubcommand::Browse { name } => browse_release(&repo, &api, name).await?,
+ ReleaseSubcommand::Browse { name } => browse_release(repo, &api, name).await?,
ReleaseSubcommand::Asset(subcommand) => match subcommand {
AssetCommand::Create {
release,
path,
name,
- } => create_asset(&repo, &api, release, path, name).await?,
+ } => create_asset(repo, &api, release, path, name).await?,
AssetCommand::Delete { release, asset } => {
- delete_asset(&repo, &api, release, asset).await?
+ delete_asset(repo, &api, release, asset).await?
}
AssetCommand::Download {
release,
asset,
output,
- } => download_asset(&repo, &api, release, asset, output).await?,
+ } => download_asset(repo, &api, release, asset, output).await?,
},
}
Ok(())
@@ -394,7 +394,7 @@ async fn view_release(
.ok_or_else(|| eyre::eyre!("release does not have body"))?;
if !body.is_empty() {
println!();
- println!("{}", crate::markdown(&body));
+ println!("{}", crate::markdown(body));
println!();
}
let assets = release
diff --git a/src/repo.rs b/src/repo.rs
index dce5487..07370d3 100644
--- a/src/repo.rs
+++ b/src/repo.rs
@@ -95,7 +95,7 @@ impl RepoInfo {
remote_name.as_str().ok_or_eyre("remote name invalid")?;
if let Some(host_url) = &host_url {
- let remote = local_repo.find_remote(&remote_name_s)?;
+ let remote = local_repo.find_remote(remote_name_s)?;
let url_s = std::str::from_utf8(remote.url_bytes())?;
let url = Url::parse(url_s)?;
@@ -154,14 +154,12 @@ impl RepoInfo {
(repo_url, repo_name)
} else if repo_name.is_some() {
(host_url.or(remote_url), repo_name)
+ } else if remote.is_some() {
+ (remote_url, remote_repo_name)
+ } else if host_url.is_none() || remote_url == host_url {
+ (remote_url, remote_repo_name)
} else {
- if remote.is_some() {
- (remote_url, remote_repo_name)
- } else if host_url.is_none() || remote_url == host_url {
- (remote_url, remote_repo_name)
- } else {
- (host_url, None)
- }
+ (host_url, None)
};
let url = url.or_else(fallback_host);
@@ -377,17 +375,14 @@ impl RepoCommand {
let no_trailing_slash = no_scheme.strip_suffix("/").unwrap_or(no_scheme);
no_trailing_slash
}
- match (repo.host.as_deref(), host_name) {
- (Some(a), Some(b)) => {
- if strip(a) != strip(b) {
- eyre::bail!("conflicting hosts {a} and {b}. please only specify one");
- }
+ if let (Some(a), Some(b)) = (repo.host.as_deref(), host_name) {
+ if strip(a) != strip(b) {
+ eyre::bail!("conflicting hosts {a} and {b}. please only specify one");
}
- _ => (),
}
let repo_info = RepoInfo::get_current(host_name, Some(&repo), remote.as_deref())?;
- let api = keys.get_api(&repo_info.host_url()).await?;
+ let api = keys.get_api(repo_info.host_url()).await?;
let repo = repo_info
.name()
.ok_or_eyre("couldn't get repo name, please specify")?;
@@ -395,28 +390,28 @@ impl RepoCommand {
}
RepoCommand::View { name, remote } => {
let repo = RepoInfo::get_current(host_name, name.as_ref(), remote.as_deref())?;
- let api = keys.get_api(&repo.host_url()).await?;
+ let api = keys.get_api(repo.host_url()).await?;
let repo = repo
.name()
.ok_or_eyre("couldn't get repo name, please specify")?;
- view_repo(&api, &repo).await?
+ view_repo(&api, repo).await?
}
RepoCommand::Clone { repo, path } => {
let repo = RepoInfo::get_current(host_name, Some(&repo), None)?;
- let api = keys.get_api(&repo.host_url()).await?;
+ let api = keys.get_api(repo.host_url()).await?;
let name = repo.name().unwrap();
- cmd_clone_repo(&api, &name, path).await?;
+ cmd_clone_repo(&api, name, path).await?;
}
RepoCommand::Star { repo } => {
let repo = RepoInfo::get_current(host_name, Some(&repo), None)?;
- let api = keys.get_api(&repo.host_url()).await?;
+ let api = keys.get_api(repo.host_url()).await?;
let name = repo.name().unwrap();
api.user_current_put_star(name.owner(), name.name()).await?;
println!("Starred {}/{}!", name.owner(), name.name());
}
RepoCommand::Unstar { repo } => {
let repo = RepoInfo::get_current(host_name, Some(&repo), None)?;
- let api = keys.get_api(&repo.host_url()).await?;
+ let api = keys.get_api(repo.host_url()).await?;
let name = repo.name().unwrap();
api.user_current_delete_star(name.owner(), name.name())
.await?;
@@ -424,9 +419,9 @@ impl RepoCommand {
}
RepoCommand::Delete { repo } => {
let repo = RepoInfo::get_current(host_name, Some(&repo), None)?;
- let api = keys.get_api(&repo.host_url()).await?;
+ let api = keys.get_api(repo.host_url()).await?;
let name = repo.name().unwrap();
- delete_repo(&api, &name).await?;
+ delete_repo(&api, name).await?;
}
RepoCommand::Browse { name, remote } => {
let repo = RepoInfo::get_current(host_name, name.as_ref(), remote.as_deref())?;
@@ -668,7 +663,7 @@ async fn cmd_clone_repo(
let path = path.unwrap_or_else(|| PathBuf::from(format!("./{repo_name}")));
- let local_repo = clone_repo(&repo_full_name, &clone_url, &path)?;
+ let local_repo = clone_repo(repo_full_name, clone_url, &path)?;
if let Some(parent) = repo_data.parent.as_deref() {
let parent_clone_url = parent
@@ -740,7 +735,7 @@ pub fn clone_repo(
let local_repo = git2::build::RepoBuilder::new()
.fetch_options(options)
- .clone(url.as_str(), &path)?;
+ .clone(url.as_str(), path)?;
if fancy {
print!("{clear_line}{show_cursor}\r");
}
diff --git a/src/user.rs b/src/user.rs
index d38d8b5..6f7de40 100644
--- a/src/user.rs
+++ b/src/user.rs
@@ -685,12 +685,12 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
.as_deref()
.ok_or_eyre("parent repo does not have full name")?;
println!("{bold}{actor_name}{reset} forked repository {bold}{yellow}{parent_full_name}{reset} to {bold}{yellow}{full_name}{reset}");
+ } else if repo.mirror.is_some_and(|b| b) {
+ println!(
+ "{bold}{actor_name}{reset} created mirror {bold}{yellow}{full_name}{reset}"
+ );
} else {
- if repo.mirror.is_some_and(|b| b) {
- println!("{bold}{actor_name}{reset} created mirror {bold}{yellow}{full_name}{reset}");
- } else {
- println!("{bold}{actor_name}{reset} created repository {bold}{yellow}{full_name}{reset}");
- }
+ println!("{bold}{actor_name}{reset} created repository {bold}{yellow}{full_name}{reset}");
}
}
ActivityOpType::RenameRepo => {
diff --git a/src/wiki.rs b/src/wiki.rs
index 63d344f..616789d 100644
--- a/src/wiki.rs
+++ b/src/wiki.rs
@@ -52,10 +52,10 @@ impl WikiCommand {
.ok_or_else(|| eyre::eyre!("couldn't guess repo"))?;
match self.command {
- Contents { repo: _ } => wiki_contents(&repo, &api).await?,
- View { repo: _, page } => view_wiki_page(&repo, &api, &*page).await?,
- Clone { repo: _, path } => clone_wiki(&repo, &api, path).await?,
- Browse { repo: _, page } => browse_wiki_page(&repo, &api, &*page).await?,
+ Contents { repo: _ } => wiki_contents(repo, &api).await?,
+ View { repo: _, page } => view_wiki_page(repo, &api, &page).await?,
+ Clone { repo: _, path } => clone_wiki(repo, &api, path).await?,
+ Browse { repo: _, page } => browse_wiki_page(repo, &api, &page).await?,
}
Ok(())
}