mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-12 21:19:49 +01:00
Clippy Fixes
There are still some clippy warnings left, but this covers most of them
This commit is contained in:
parent
e5eb3e479b
commit
a979a34b78
8 changed files with 80 additions and 85 deletions
|
@ -58,7 +58,7 @@ impl AuthCommand {
|
||||||
Some(key) => key,
|
Some(key) => key,
|
||||||
None => crate::readline("new key: ").await?.trim().to_string(),
|
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(
|
keys.hosts.insert(
|
||||||
host,
|
host,
|
||||||
crate::keys::LoginInfo::Application {
|
crate::keys::LoginInfo::Application {
|
||||||
|
|
|
@ -176,11 +176,11 @@ impl IssueCommand {
|
||||||
repo: _,
|
repo: _,
|
||||||
title,
|
title,
|
||||||
body,
|
body,
|
||||||
} => create_issue(&repo, &api, title, body).await?,
|
} => create_issue(repo, &api, title, body).await?,
|
||||||
View { id, command } => match command.unwrap_or(ViewCommand::Body) {
|
View { id, command } => match command.unwrap_or(ViewCommand::Body) {
|
||||||
ViewCommand::Body => view_issue(&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::Comment { idx } => view_comment(repo, &api, id.number, idx).await?,
|
||||||
ViewCommand::Comments => view_comments(&repo, &api, id.number).await?,
|
ViewCommand::Comments => view_comments(repo, &api, id.number).await?,
|
||||||
},
|
},
|
||||||
Search {
|
Search {
|
||||||
repo: _,
|
repo: _,
|
||||||
|
@ -189,21 +189,21 @@ impl IssueCommand {
|
||||||
creator,
|
creator,
|
||||||
assignee,
|
assignee,
|
||||||
state,
|
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 {
|
Edit { issue, command } => match command {
|
||||||
EditCommand::Title { new_title } => {
|
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 } => {
|
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 } => {
|
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?,
|
Close { issue, with_msg } => close_issue(repo, &api, issue.number, with_msg).await?,
|
||||||
Browse { id } => browse_issue(&repo, &api, id.number).await?,
|
Browse { id } => browse_issue(repo, &api, id.number).await?,
|
||||||
Comment { issue, body } => add_comment(&repo, &api, issue.number, body).await?,
|
Comment { issue, body } => add_comment(repo, &api, issue.number, body).await?,
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ pub async fn view_comment(repo: &RepoName, api: &Forgejo, id: u64, idx: usize) -
|
||||||
let comment = comments
|
let comment = comments
|
||||||
.get(idx)
|
.get(idx)
|
||||||
.ok_or_else(|| eyre!("comment {idx} doesn't exist"))?;
|
.ok_or_else(|| eyre!("comment {idx} doesn't exist"))?;
|
||||||
print_comment(&comment)?;
|
print_comment(comment)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +440,7 @@ fn print_comment(comment: &Comment) -> eyre::Result<()> {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or_else(|| eyre::eyre!("user does not have login"))?;
|
.ok_or_else(|| eyre::eyre!("user does not have login"))?;
|
||||||
println!("{} said:", username);
|
println!("{} said:", username);
|
||||||
println!("{}", crate::markdown(&body));
|
println!("{}", crate::markdown(body));
|
||||||
let assets = comment
|
let assets = comment
|
||||||
.assets
|
.assets
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
|
@ -159,9 +159,9 @@ async fn editor(contents: &mut String, ext: Option<&str>) -> eyre::Result<()> {
|
||||||
file.write_all(contents.as_bytes()).await?;
|
file.write_all(contents.as_bytes()).await?;
|
||||||
drop(file);
|
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
|
// on errors
|
||||||
let res = (|| async {
|
let res = async {
|
||||||
eprint!("waiting on editor\r");
|
eprint!("waiting on editor\r");
|
||||||
let flags = get_editor_flags(&editor);
|
let flags = get_editor_flags(&editor);
|
||||||
let status = tokio::process::Command::new(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");
|
eprint!(" \r");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})()
|
}
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
tokio::fs::remove_file(path).await?;
|
tokio::fs::remove_file(path).await?;
|
||||||
|
|
46
src/prs.rs
46
src/prs.rs
|
@ -274,7 +274,7 @@ impl PrCommand {
|
||||||
head,
|
head,
|
||||||
body,
|
body,
|
||||||
repo: _,
|
repo: _,
|
||||||
} => create_pr(&repo, &api, title, base, head, body).await?,
|
} => create_pr(repo, &api, title, base, head, body).await?,
|
||||||
Merge {
|
Merge {
|
||||||
pr,
|
pr,
|
||||||
method,
|
method,
|
||||||
|
@ -283,7 +283,7 @@ impl PrCommand {
|
||||||
message,
|
message,
|
||||||
} => {
|
} => {
|
||||||
merge_pr(
|
merge_pr(
|
||||||
&repo,
|
repo,
|
||||||
&api,
|
&api,
|
||||||
pr.map(|id| id.number),
|
pr.map(|id| id.number),
|
||||||
method,
|
method,
|
||||||
|
@ -296,26 +296,26 @@ impl PrCommand {
|
||||||
View { id, command } => {
|
View { id, command } => {
|
||||||
let id = id.map(|id| id.number);
|
let id = id.map(|id| id.number);
|
||||||
match command.unwrap_or(ViewCommand::Body) {
|
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 } => {
|
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?
|
crate::issues::view_comment(&repo, &api, id, idx).await?
|
||||||
}
|
}
|
||||||
ViewCommand::Comments => {
|
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?
|
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 } => {
|
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 } => {
|
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 {
|
Search {
|
||||||
query,
|
query,
|
||||||
labels,
|
labels,
|
||||||
|
@ -323,38 +323,38 @@ impl PrCommand {
|
||||||
assignee,
|
assignee,
|
||||||
state,
|
state,
|
||||||
repo: _,
|
repo: _,
|
||||||
} => view_prs(&repo, &api, query, labels, creator, assignee, state).await?,
|
} => view_prs(repo, &api, query, labels, creator, assignee, state).await?,
|
||||||
Edit { pr, command } => {
|
Edit { pr, command } => {
|
||||||
let pr = pr.map(|pr| pr.number);
|
let pr = pr.map(|pr| pr.number);
|
||||||
match command {
|
match command {
|
||||||
EditCommand::Title { new_title } => {
|
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?
|
crate::issues::edit_title(&repo, &api, id, new_title).await?
|
||||||
}
|
}
|
||||||
EditCommand::Body { new_body } => {
|
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?
|
crate::issues::edit_body(&repo, &api, id, new_body).await?
|
||||||
}
|
}
|
||||||
EditCommand::Comment { idx, new_body } => {
|
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?
|
crate::issues::edit_comment(&repo, &api, id, idx, new_body).await?
|
||||||
}
|
}
|
||||||
EditCommand::Labels { add, rm } => {
|
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 } => {
|
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?
|
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 } => {
|
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?
|
browse_pr(&repo, &api, id).await?
|
||||||
}
|
}
|
||||||
Comment { pr, body } => {
|
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?
|
crate::issues::add_comment(&repo, &api, pr, body).await?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -747,7 +747,7 @@ async fn edit_pr_labels(
|
||||||
for label_name in &add {
|
for label_name in &add {
|
||||||
let maybe_label = labels
|
let maybe_label = labels
|
||||||
.iter()
|
.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 {
|
if let Some(label) = maybe_label {
|
||||||
add_ids.push(serde_json::Value::Number(
|
add_ids.push(serde_json::Value::Number(
|
||||||
label.id.ok_or_eyre("label does not have id")?.into(),
|
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 {
|
for label_name in &rm {
|
||||||
let maybe_label = labels
|
let maybe_label = labels
|
||||||
.iter()
|
.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 {
|
if let Some(label) = maybe_label {
|
||||||
rm_ids.push(label.id.ok_or_eyre("label does not have id")?);
|
rm_ids.push(label.id.ok_or_eyre("label does not have id")?);
|
||||||
} else {
|
} else {
|
||||||
|
@ -865,7 +865,7 @@ async fn create_pr(
|
||||||
|
|
||||||
let (base, base_is_parent) = match base {
|
let (base, base_is_parent) = match base {
|
||||||
Some(base) => match base.strip_prefix("^") {
|
Some(base) => match base.strip_prefix("^") {
|
||||||
Some(stripped) if stripped.is_empty() => (None, true),
|
Some("") => (None, true),
|
||||||
Some(stripped) => (Some(stripped.to_owned()), true),
|
Some(stripped) => (Some(stripped.to_owned()), true),
|
||||||
None => (Some(base), false),
|
None => (Some(base), false),
|
||||||
},
|
},
|
||||||
|
@ -1291,7 +1291,7 @@ async fn view_pr_commits(
|
||||||
.ok_or_eyre("commit does not have commit?")?;
|
.ok_or_eyre("commit does not have commit?")?;
|
||||||
|
|
||||||
let message = repo_commit.message.as_deref().unwrap_or("[no msg]");
|
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
|
let sha = commit
|
||||||
.sha
|
.sha
|
||||||
|
|
|
@ -127,7 +127,7 @@ pub enum AssetCommand {
|
||||||
impl ReleaseCommand {
|
impl ReleaseCommand {
|
||||||
pub async fn run(self, keys: &mut KeyInfo, remote_name: Option<&str>) -> eyre::Result<()> {
|
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 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
|
let repo = repo
|
||||||
.name()
|
.name()
|
||||||
.ok_or_eyre("couldn't get repo name, try specifying with --repo")?;
|
.ok_or_eyre("couldn't get repo name, try specifying with --repo")?;
|
||||||
|
@ -143,7 +143,7 @@ impl ReleaseCommand {
|
||||||
prerelease,
|
prerelease,
|
||||||
} => {
|
} => {
|
||||||
create_release(
|
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?
|
.await?
|
||||||
}
|
}
|
||||||
|
@ -154,32 +154,32 @@ impl ReleaseCommand {
|
||||||
body,
|
body,
|
||||||
draft,
|
draft,
|
||||||
prerelease,
|
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 } => {
|
ReleaseSubcommand::Delete { name, by_tag } => {
|
||||||
delete_release(&repo, &api, name, by_tag).await?
|
delete_release(repo, &api, name, by_tag).await?
|
||||||
}
|
}
|
||||||
ReleaseSubcommand::List {
|
ReleaseSubcommand::List {
|
||||||
include_prerelease,
|
include_prerelease,
|
||||||
include_draft,
|
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 } => {
|
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 {
|
ReleaseSubcommand::Asset(subcommand) => match subcommand {
|
||||||
AssetCommand::Create {
|
AssetCommand::Create {
|
||||||
release,
|
release,
|
||||||
path,
|
path,
|
||||||
name,
|
name,
|
||||||
} => create_asset(&repo, &api, release, path, name).await?,
|
} => create_asset(repo, &api, release, path, name).await?,
|
||||||
AssetCommand::Delete { release, asset } => {
|
AssetCommand::Delete { release, asset } => {
|
||||||
delete_asset(&repo, &api, release, asset).await?
|
delete_asset(repo, &api, release, asset).await?
|
||||||
}
|
}
|
||||||
AssetCommand::Download {
|
AssetCommand::Download {
|
||||||
release,
|
release,
|
||||||
asset,
|
asset,
|
||||||
output,
|
output,
|
||||||
} => download_asset(&repo, &api, release, asset, output).await?,
|
} => download_asset(repo, &api, release, asset, output).await?,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -394,7 +394,7 @@ async fn view_release(
|
||||||
.ok_or_else(|| eyre::eyre!("release does not have body"))?;
|
.ok_or_else(|| eyre::eyre!("release does not have body"))?;
|
||||||
if !body.is_empty() {
|
if !body.is_empty() {
|
||||||
println!();
|
println!();
|
||||||
println!("{}", crate::markdown(&body));
|
println!("{}", crate::markdown(body));
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
let assets = release
|
let assets = release
|
||||||
|
|
33
src/repo.rs
33
src/repo.rs
|
@ -95,7 +95,7 @@ impl RepoInfo {
|
||||||
remote_name.as_str().ok_or_eyre("remote name invalid")?;
|
remote_name.as_str().ok_or_eyre("remote name invalid")?;
|
||||||
|
|
||||||
if let Some(host_url) = &host_url {
|
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_s = std::str::from_utf8(remote.url_bytes())?;
|
||||||
let url = Url::parse(url_s)?;
|
let url = Url::parse(url_s)?;
|
||||||
|
|
||||||
|
@ -154,14 +154,12 @@ impl RepoInfo {
|
||||||
(repo_url, repo_name)
|
(repo_url, repo_name)
|
||||||
} else if repo_name.is_some() {
|
} else if repo_name.is_some() {
|
||||||
(host_url.or(remote_url), repo_name)
|
(host_url.or(remote_url), repo_name)
|
||||||
} else {
|
} else if remote.is_some() {
|
||||||
if remote.is_some() {
|
|
||||||
(remote_url, remote_repo_name)
|
(remote_url, remote_repo_name)
|
||||||
} else if host_url.is_none() || remote_url == host_url {
|
} else if host_url.is_none() || remote_url == host_url {
|
||||||
(remote_url, remote_repo_name)
|
(remote_url, remote_repo_name)
|
||||||
} else {
|
} else {
|
||||||
(host_url, None)
|
(host_url, None)
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let url = url.or_else(fallback_host);
|
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);
|
let no_trailing_slash = no_scheme.strip_suffix("/").unwrap_or(no_scheme);
|
||||||
no_trailing_slash
|
no_trailing_slash
|
||||||
}
|
}
|
||||||
match (repo.host.as_deref(), host_name) {
|
if let (Some(a), Some(b)) = (repo.host.as_deref(), host_name) {
|
||||||
(Some(a), Some(b)) => {
|
|
||||||
if strip(a) != strip(b) {
|
if strip(a) != strip(b) {
|
||||||
eyre::bail!("conflicting hosts {a} and {b}. please only specify one");
|
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 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
|
let repo = repo_info
|
||||||
.name()
|
.name()
|
||||||
.ok_or_eyre("couldn't get repo name, please specify")?;
|
.ok_or_eyre("couldn't get repo name, please specify")?;
|
||||||
|
@ -395,28 +390,28 @@ impl RepoCommand {
|
||||||
}
|
}
|
||||||
RepoCommand::View { name, remote } => {
|
RepoCommand::View { name, remote } => {
|
||||||
let repo = RepoInfo::get_current(host_name, name.as_ref(), remote.as_deref())?;
|
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
|
let repo = repo
|
||||||
.name()
|
.name()
|
||||||
.ok_or_eyre("couldn't get repo name, please specify")?;
|
.ok_or_eyre("couldn't get repo name, please specify")?;
|
||||||
view_repo(&api, &repo).await?
|
view_repo(&api, repo).await?
|
||||||
}
|
}
|
||||||
RepoCommand::Clone { repo, path } => {
|
RepoCommand::Clone { repo, path } => {
|
||||||
let repo = RepoInfo::get_current(host_name, Some(&repo), None)?;
|
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();
|
let name = repo.name().unwrap();
|
||||||
cmd_clone_repo(&api, &name, path).await?;
|
cmd_clone_repo(&api, name, path).await?;
|
||||||
}
|
}
|
||||||
RepoCommand::Star { repo } => {
|
RepoCommand::Star { repo } => {
|
||||||
let repo = RepoInfo::get_current(host_name, Some(&repo), None)?;
|
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();
|
let name = repo.name().unwrap();
|
||||||
api.user_current_put_star(name.owner(), name.name()).await?;
|
api.user_current_put_star(name.owner(), name.name()).await?;
|
||||||
println!("Starred {}/{}!", name.owner(), name.name());
|
println!("Starred {}/{}!", name.owner(), name.name());
|
||||||
}
|
}
|
||||||
RepoCommand::Unstar { repo } => {
|
RepoCommand::Unstar { repo } => {
|
||||||
let repo = RepoInfo::get_current(host_name, Some(&repo), None)?;
|
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();
|
let name = repo.name().unwrap();
|
||||||
api.user_current_delete_star(name.owner(), name.name())
|
api.user_current_delete_star(name.owner(), name.name())
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -424,9 +419,9 @@ impl RepoCommand {
|
||||||
}
|
}
|
||||||
RepoCommand::Delete { repo } => {
|
RepoCommand::Delete { repo } => {
|
||||||
let repo = RepoInfo::get_current(host_name, Some(&repo), None)?;
|
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();
|
let name = repo.name().unwrap();
|
||||||
delete_repo(&api, &name).await?;
|
delete_repo(&api, name).await?;
|
||||||
}
|
}
|
||||||
RepoCommand::Browse { name, remote } => {
|
RepoCommand::Browse { name, remote } => {
|
||||||
let repo = RepoInfo::get_current(host_name, name.as_ref(), remote.as_deref())?;
|
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 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() {
|
if let Some(parent) = repo_data.parent.as_deref() {
|
||||||
let parent_clone_url = parent
|
let parent_clone_url = parent
|
||||||
|
@ -740,7 +735,7 @@ pub fn clone_repo(
|
||||||
|
|
||||||
let local_repo = git2::build::RepoBuilder::new()
|
let local_repo = git2::build::RepoBuilder::new()
|
||||||
.fetch_options(options)
|
.fetch_options(options)
|
||||||
.clone(url.as_str(), &path)?;
|
.clone(url.as_str(), path)?;
|
||||||
if fancy {
|
if fancy {
|
||||||
print!("{clear_line}{show_cursor}\r");
|
print!("{clear_line}{show_cursor}\r");
|
||||||
}
|
}
|
||||||
|
|
|
@ -685,14 +685,14 @@ async fn list_activity(api: &Forgejo, user: Option<&str>) -> eyre::Result<()> {
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.ok_or_eyre("parent repo does not have full name")?;
|
.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}");
|
println!("{bold}{actor_name}{reset} forked repository {bold}{yellow}{parent_full_name}{reset} to {bold}{yellow}{full_name}{reset}");
|
||||||
} else {
|
} else if repo.mirror.is_some_and(|b| b) {
|
||||||
if repo.mirror.is_some_and(|b| b) {
|
println!(
|
||||||
println!("{bold}{actor_name}{reset} created mirror {bold}{yellow}{full_name}{reset}");
|
"{bold}{actor_name}{reset} created mirror {bold}{yellow}{full_name}{reset}"
|
||||||
|
);
|
||||||
} else {
|
} 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 => {
|
ActivityOpType::RenameRepo => {
|
||||||
let repo = repo?;
|
let repo = repo?;
|
||||||
let content = content?;
|
let content = content?;
|
||||||
|
|
|
@ -52,10 +52,10 @@ impl WikiCommand {
|
||||||
.ok_or_else(|| eyre::eyre!("couldn't guess repo"))?;
|
.ok_or_else(|| eyre::eyre!("couldn't guess repo"))?;
|
||||||
|
|
||||||
match self.command {
|
match self.command {
|
||||||
Contents { repo: _ } => wiki_contents(&repo, &api).await?,
|
Contents { repo: _ } => wiki_contents(repo, &api).await?,
|
||||||
View { repo: _, page } => view_wiki_page(&repo, &api, &*page).await?,
|
View { repo: _, page } => view_wiki_page(repo, &api, &page).await?,
|
||||||
Clone { repo: _, path } => clone_wiki(&repo, &api, path).await?,
|
Clone { repo: _, path } => clone_wiki(repo, &api, path).await?,
|
||||||
Browse { repo: _, page } => browse_wiki_page(&repo, &api, &*page).await?,
|
Browse { repo: _, page } => browse_wiki_page(repo, &api, &page).await?,
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue