mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-10 12:09:33 +01:00
format
This commit is contained in:
parent
7b63ecd552
commit
5dd4dbb690
3 changed files with 25 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
use forgejo_api::{Forgejo, CreateIssueCommentOption, EditIssueOption, IssueCommentQuery, Comment};
|
use forgejo_api::{Comment, CreateIssueCommentOption, EditIssueOption, Forgejo, IssueCommentQuery};
|
||||||
|
|
||||||
use crate::repo::RepoInfo;
|
use crate::repo::RepoInfo;
|
||||||
|
|
||||||
|
@ -52,9 +52,7 @@ pub enum EditCommand {
|
||||||
#[derive(Subcommand, Clone, Debug)]
|
#[derive(Subcommand, Clone, Debug)]
|
||||||
pub enum ViewCommand {
|
pub enum ViewCommand {
|
||||||
Body,
|
Body,
|
||||||
Comment {
|
Comment { idx: usize },
|
||||||
idx: usize,
|
|
||||||
},
|
|
||||||
Comments,
|
Comments,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +66,7 @@ impl IssueCommand {
|
||||||
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).await?,
|
ViewCommand::Body => view_issue(&repo, &api, id).await?,
|
||||||
ViewCommand::Comment { idx } => view_comment(&repo, &api, id, idx).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 {
|
Edit { issue, command } => match command {
|
||||||
EditCommand::Title { new_title } => {
|
EditCommand::Title { new_title } => {
|
||||||
|
@ -134,7 +132,9 @@ async fn view_comment(repo: &RepoInfo, api: &Forgejo, id: u64, idx: usize) -> ey
|
||||||
let comments = api
|
let comments = api
|
||||||
.get_issue_comments(repo.owner(), repo.name(), id, IssueCommentQuery::default())
|
.get_issue_comments(repo.owner(), repo.name(), id, IssueCommentQuery::default())
|
||||||
.await?;
|
.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);
|
print_comment(&comment);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -309,7 +309,12 @@ async fn edit_comment(
|
||||||
Ok(())
|
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 {
|
if let Some(message) = message {
|
||||||
let body = match message {
|
let body = match message {
|
||||||
Some(m) => m,
|
Some(m) => m,
|
||||||
|
@ -321,15 +326,16 @@ async fn close_issue(repo: &RepoInfo, api: &Forgejo, issue: u64, message: Option
|
||||||
};
|
};
|
||||||
|
|
||||||
let opt = CreateIssueCommentOption { body };
|
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 {
|
let edit = EditIssueOption {
|
||||||
state: Some(forgejo_api::State::Closed),
|
state: Some(forgejo_api::State::Closed),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
api.edit_issue(repo.owner(), repo.name(), issue, edit).await?;
|
api.edit_issue(repo.owner(), repo.name(), issue, edit)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ async fn readline(msg: &str) -> eyre::Result<String> {
|
||||||
|
|
||||||
async fn editor(contents: &mut String, ext: Option<&str>) -> eyre::Result<()> {
|
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 editor = std::env::var_os("EDITOR").ok_or_else(|| eyre!("unable to locate editor"))?;
|
||||||
|
|
||||||
let (mut file, path) = tempfile(ext).await?;
|
let (mut file, path) = tempfile(ext).await?;
|
||||||
file.write_all(contents.as_bytes()).await?;
|
file.write_all(contents.as_bytes()).await?;
|
||||||
drop(file);
|
drop(file);
|
||||||
|
@ -88,7 +88,8 @@ 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?;
|
||||||
res?;
|
res?;
|
||||||
|
|
|
@ -125,10 +125,14 @@ impl RepoCommand {
|
||||||
if !head.is_branch() {
|
if !head.is_branch() {
|
||||||
eyre::bail!("HEAD is not on a branch; cannot push to remote");
|
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 branch_name = std::str::from_utf8(head.name_bytes())?.to_owned();
|
||||||
let mut current_branch = git2::Branch::wrap(head);
|
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();
|
let auth = auth_git2::GitAuthenticator::new();
|
||||||
auth.push(&repo, &mut remote, &[&branch_name])?;
|
auth.push(&repo, &mut remote, &[&branch_name])?;
|
||||||
|
|
Loading…
Reference in a new issue