diff options
author | Cyborus <cyborus@noreply.codeberg.org> | 2023-12-13 02:06:00 +0100 |
---|---|---|
committer | Cyborus <cyborus@noreply.codeberg.org> | 2023-12-13 02:06:00 +0100 |
commit | 98e3cceff8170faf0b1f3a8e24b84d84714876d7 (patch) | |
tree | 92db800978e190cd63334945d2f44215cb5f49c0 | |
parent | Merge pull request 'add basic issue commands' (#7) from issues into main (diff) | |
parent | format (diff) | |
download | forgejo-cli-98e3cceff8170faf0b1f3a8e24b84d84714876d7.tar.xz forgejo-cli-98e3cceff8170faf0b1f3a8e24b84d84714876d7.zip |
Merge pull request 'add ci' (#8) from ci into main
Reviewed-on: https://codeberg.org/Cyborus/forgejo-cli/pulls/8
-rw-r--r-- | .woodpecker/check.yml | 13 | ||||
-rw-r--r-- | src/issues.rs | 26 | ||||
-rw-r--r-- | src/main.rs | 5 | ||||
-rw-r--r-- | src/repo.rs | 8 |
4 files changed, 38 insertions, 14 deletions
diff --git a/.woodpecker/check.yml b/.woodpecker/check.yml new file mode 100644 index 0000000..20508ea --- /dev/null +++ b/.woodpecker/check.yml @@ -0,0 +1,13 @@ +when: + - event: manual + - event: pull_request +steps: + check: + image: rust + commands: + - cargo check + check-fmt: + image: rust + commands: + - rustup component add rustfmt + - cargo fmt --check diff --git a/src/issues.rs b/src/issues.rs index 2970a26..56ee300 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -1,6 +1,6 @@ use clap::Subcommand; use eyre::eyre; -use forgejo_api::{Forgejo, CreateIssueCommentOption, EditIssueOption, IssueCommentQuery, Comment}; +use forgejo_api::{Comment, CreateIssueCommentOption, EditIssueOption, Forgejo, IssueCommentQuery}; use crate::repo::RepoInfo; @@ -52,9 +52,7 @@ pub enum EditCommand { #[derive(Subcommand, Clone, Debug)] pub enum ViewCommand { Body, - Comment { - idx: usize, - }, + Comment { idx: usize }, Comments, } @@ -68,7 +66,7 @@ impl IssueCommand { View { id, command } => match command.unwrap_or(ViewCommand::Body) { ViewCommand::Body => view_issue(&repo, &api, id).await?, ViewCommand::Comment { idx } => view_comment(&repo, &api, id, idx).await?, - ViewCommand::Comments => view_comments(&repo, &api, id).await? + ViewCommand::Comments => view_comments(&repo, &api, id).await?, }, Edit { issue, command } => match command { EditCommand::Title { new_title } => { @@ -134,7 +132,9 @@ async fn view_comment(repo: &RepoInfo, api: &Forgejo, id: u64, idx: usize) -> ey let comments = api .get_issue_comments(repo.owner(), repo.name(), id, IssueCommentQuery::default()) .await?; - let comment = comments.get(idx).ok_or_else(|| eyre!("comment {idx} doesn't exist"))?; + let comment = comments + .get(idx) + .ok_or_else(|| eyre!("comment {idx} doesn't exist"))?; print_comment(&comment); Ok(()) } @@ -309,7 +309,12 @@ async fn edit_comment( Ok(()) } -async fn close_issue(repo: &RepoInfo, api: &Forgejo, issue: u64, message: Option<Option<String>>) -> eyre::Result<()> { +async fn close_issue( + repo: &RepoInfo, + api: &Forgejo, + issue: u64, + message: Option<Option<String>>, +) -> eyre::Result<()> { if let Some(message) = message { let body = match message { Some(m) => m, @@ -321,15 +326,16 @@ async fn close_issue(repo: &RepoInfo, api: &Forgejo, issue: u64, message: Option }; let opt = CreateIssueCommentOption { body }; - api.create_comment(repo.owner(), repo.name(), issue, opt).await?; + api.create_comment(repo.owner(), repo.name(), issue, opt) + .await?; } let edit = EditIssueOption { state: Some(forgejo_api::State::Closed), ..Default::default() }; - api.edit_issue(repo.owner(), repo.name(), issue, edit).await?; + api.edit_issue(repo.owner(), repo.name(), issue, edit) + .await?; Ok(()) - } diff --git a/src/main.rs b/src/main.rs index 856f958..c7674d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,7 +67,7 @@ async fn readline(msg: &str) -> eyre::Result<String> { async fn editor(contents: &mut String, ext: Option<&str>) -> eyre::Result<()> { let editor = std::env::var_os("EDITOR").ok_or_else(|| eyre!("unable to locate editor"))?; - + let (mut file, path) = tempfile(ext).await?; file.write_all(contents.as_bytes()).await?; drop(file); @@ -88,7 +88,8 @@ async fn editor(contents: &mut String, ext: Option<&str>) -> eyre::Result<()> { eprint!(" \r"); Ok(()) - })().await; + })() + .await; tokio::fs::remove_file(path).await?; res?; diff --git a/src/repo.rs b/src/repo.rs index a98e1f5..7fdecd7 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -125,10 +125,14 @@ impl RepoCommand { if !head.is_branch() { eyre::bail!("HEAD is not on a branch; cannot push to remote"); } - let branch_shorthand = head.shorthand().ok_or_else(|| eyre!("branch name invalid utf-8"))?.to_owned(); + let branch_shorthand = head + .shorthand() + .ok_or_else(|| eyre!("branch name invalid utf-8"))? + .to_owned(); let branch_name = std::str::from_utf8(head.name_bytes())?.to_owned(); let mut current_branch = git2::Branch::wrap(head); - current_branch.set_upstream(Some(&dbg!(format!("{upstream}/{branch_shorthand}"))))?; + current_branch + .set_upstream(Some(&dbg!(format!("{upstream}/{branch_shorthand}"))))?; let auth = auth_git2::GitAuthenticator::new(); auth.push(&repo, &mut remote, &[&branch_name])?; |