From 9b06986689ccdc114dd6120311b8747acf331353 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 15:16:39 +0400 Subject: [PATCH 01/20] Feat(git_utils): add update method for comment --- src/git_utils/comments.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/git_utils/comments.rs b/src/git_utils/comments.rs index bb12cba..2874279 100644 --- a/src/git_utils/comments.rs +++ b/src/git_utils/comments.rs @@ -78,3 +78,28 @@ pub async fn get_all_from_review( Err(er) => Err(Box::new(er)), }; } + + +pub async fn update( + github_client: &Client, + repo_info: &RepoInfo, + comment_id: &i64, + body: &String, +) -> Result> { + let request = PullsUpdateReviewRequest { body: body.clone() }; + + let comment = github_client + .issues() + .update_comment( + &repo_info.get_owner().trim(), + &repo_info.get_name().trim(), + comment_id.clone(), + &request, + ) + .await; + + return match comment { + Ok(_) => Ok("Comment update successed".to_string()), + Err(er) => Err(Box::new(er)), + }; +} From 69833960c895b4807085e5cf9a37316cee9bbc6a Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 15:17:10 +0400 Subject: [PATCH 02/20] Feat(cli_parse): add handle_update for handle_comment --- .../handle_commands/handle_comment.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cli_parse/handle_commands/handle_comment.rs b/src/cli_parse/handle_commands/handle_comment.rs index 952e010..965d027 100644 --- a/src/cli_parse/handle_commands/handle_comment.rs +++ b/src/cli_parse/handle_commands/handle_comment.rs @@ -116,3 +116,21 @@ async fn handle_get_all_from_review( print_review_comments(result)?; Ok(()) } + +async fn handle_update( + github_client: Client, + owner: Option, + repo: Option, + number: i64, + body: String, +) -> Result<(), Box> { + let repo_info = match owner { + Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, + None => RepoInfo::new(Repo::Current, None, None)?, + }; + let result = comments::update(&github_client, &repo_info, &number, &body).await?; + + println!("{result}"); + Ok(()) +} + From 0f002286343b4fc4f5ccc5dc1c4ac03654b06c17 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 18:48:50 +0400 Subject: [PATCH 03/20] Fix(cli_out): not printing pull request in issues print Handle pull request's from issue vec and return error --- src/cli_out/print_in_cli.rs | 29 +++++++++++++++++-- src/cli_parse/handle_commands/handle_issue.rs | 4 +-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/cli_out/print_in_cli.rs b/src/cli_out/print_in_cli.rs index e1f56c1..2e0d232 100644 --- a/src/cli_out/print_in_cli.rs +++ b/src/cli_out/print_in_cli.rs @@ -13,6 +13,8 @@ pub struct PrintError { enum PrintErrorKind { /// Github response was wrong BadResponse, + /// Trying get pull request data from issue command + NotIssue, } impl Error for PrintError {} @@ -27,6 +29,12 @@ impl fmt::Display for PrintError { &self.description ) } + PrintErrorKind::NotIssue => { + write!( + f, + "you tried get pull request from issue command.\n Please use pull request commands" + ) + } } } } @@ -58,6 +66,9 @@ pub fn print_issues(list_issues: Vec, state: IssuesListStates, numb ); println!(); for issue in list_issues { + if issue.pull_request != None { + continue; + } println!("╭────────────────────────────────────────────────────────────────────────────────────────────────"); println!(" Issue {}: {};", issue.number, issue.title); println!(" Body: {}", issue.body); @@ -75,7 +86,13 @@ pub fn print_issues(list_issues: Vec, state: IssuesListStates, numb } } -pub fn print_simple_issue(issue: IssueSimple) { +pub fn print_simple_issue(issue: IssueSimple) -> Result<(), Box> { + if issue.pull_request != None { + return Err(Box::new(PrintError { + kind: PrintErrorKind::NotIssue, + description: "Trying get pull request from issue command".to_string(), + })); + } println!("╭────────────────────────────────────────────────────────────────────────────────────────────────"); println!(" Issue {}: {};", issue.number, issue.title); println!(" State: {}", issue.state); @@ -91,9 +108,16 @@ pub fn print_simple_issue(issue: IssueSimple) { None => {} }; println!("╰────────────────────────────────────────────────────────────────────────────────────────────────"); + Ok(()) } -pub fn print_issue(issue: Issue) { +pub fn print_issue(issue: Issue) -> Result<(), Box> { + if issue.pull_request != None { + return Err(Box::new(PrintError { + kind: PrintErrorKind::NotIssue, + description: "Trying get pull request from issue command".to_string(), + })); + } println!("╭────────────────────────────────────────────────────────────────────────────────────────────────"); println!(" Issue {}: {};", issue.number, issue.title); println!(" State: {}", issue.state); @@ -114,6 +138,7 @@ pub fn print_issue(issue: Issue) { None => {} }; println!("╰────────────────────────────────────────────────────────────────────────────────────────────────"); + Ok(()) } pub fn print_url(result: String, description: &str) { diff --git a/src/cli_parse/handle_commands/handle_issue.rs b/src/cli_parse/handle_commands/handle_issue.rs index a7679d1..3ba42ca 100644 --- a/src/cli_parse/handle_commands/handle_issue.rs +++ b/src/cli_parse/handle_commands/handle_issue.rs @@ -175,7 +175,7 @@ async fn handle_get( let list_comments = comments::get_all(&github_client, &repo_info, &number).await?; - print_issue(result); + print_issue(result)?; print_comments(list_comments)?; Ok(()) } @@ -213,7 +213,7 @@ async fn handle_get_form_list( if let Some(ch_i) = choosed_issue { let list_comments = comments::get_all(&github_client, &repo_info, &ch_i.number).await?; - print_simple_issue(ch_i); + print_simple_issue(ch_i)?; print_comments(list_comments)?; } else { println!("Issue not choosed or not find"); From 90ec07e08629464289e52fc3af461177ad32e2df Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 19:21:13 +0400 Subject: [PATCH 04/20] Feat(cli_parse): add update command and handle for comment --- src/cli_in/comment_command.rs | 16 ++++++++++++++++ src/cli_parse/handle_commands/handle_comment.rs | 16 +++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/cli_in/comment_command.rs b/src/cli_in/comment_command.rs index 202d863..8097e7f 100644 --- a/src/cli_in/comment_command.rs +++ b/src/cli_in/comment_command.rs @@ -55,4 +55,20 @@ pub enum CommentCommand { #[clap(long, default_value = "desc")] order: Orders, }, + + /// Update comment for issue/pull request by comment id + Update { + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, + /// Update comment from issue/pull request by id + #[clap(long, short)] + comment_id: i64, + /// Comment body (optional) + #[clap(long, short, default_value = "")] + body: String, + }, } diff --git a/src/cli_parse/handle_commands/handle_comment.rs b/src/cli_parse/handle_commands/handle_comment.rs index 965d027..7ba1ef2 100644 --- a/src/cli_parse/handle_commands/handle_comment.rs +++ b/src/cli_parse/handle_commands/handle_comment.rs @@ -42,6 +42,17 @@ pub async fn handle_comment_command( handle_get_all_from_review(github_client, owner, repo, number, sort, order).await?; Ok(()) } + + CommentCommand::Update { + owner, + repo, + comment_id, + body, + } => { + handle_update(github_client, owner, repo, comment_id, body).await?; + + Ok(()) + } } } @@ -121,16 +132,15 @@ async fn handle_update( github_client: Client, owner: Option, repo: Option, - number: i64, + comment_id: i64, body: String, ) -> Result<(), Box> { let repo_info = match owner { Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, None => RepoInfo::new(Repo::Current, None, None)?, }; - let result = comments::update(&github_client, &repo_info, &number, &body).await?; + let result = comments::update(&github_client, &repo_info, &comment_id, &body).await?; println!("{result}"); Ok(()) } - From 412c0354a8b1bca404ae921e78f3ba87930c4e70 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 20:39:54 +0400 Subject: [PATCH 05/20] Feat(cli_parse): add entities mod with CreateRepoArgs struct --- src/cli_parse/entities.rs | 20 ++++++++++++++++++++ src/cli_parse/mod.rs | 1 + 2 files changed, 21 insertions(+) create mode 100644 src/cli_parse/entities.rs diff --git a/src/cli_parse/entities.rs b/src/cli_parse/entities.rs new file mode 100644 index 0000000..afde4e6 --- /dev/null +++ b/src/cli_parse/entities.rs @@ -0,0 +1,20 @@ + +pub struct CreateRepoArgs { + pub allow_auto_merge: Option, + pub allow_merge_commit: Option, + pub allow_rebase_merge: Option, + pub allow_squash_merge: Option, + pub auto_init: Option, + pub delete_branch_on_merge: Option, + pub has_issues: Option, + pub has_projects: Option, + pub has_wiki: Option, + pub is_template: Option, + pub private: Option, + pub description: String, + pub gitignore_template: String, + pub homepage: String, + pub license_template: String, + pub name: String, +} + diff --git a/src/cli_parse/mod.rs b/src/cli_parse/mod.rs index 1087c8a..59da17e 100644 --- a/src/cli_parse/mod.rs +++ b/src/cli_parse/mod.rs @@ -1,2 +1,3 @@ pub mod handle_cli; +pub mod entities; mod handle_commands; From 7c4e9b26f81a5f64305e862b25181659d5769133 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 20:43:54 +0400 Subject: [PATCH 06/20] Chore(repo): add usage CreateRepoArgs --- src/cli_parse/entities.rs | 1 - src/cli_parse/handle_commands/handle_repo.rs | 51 +++++--------------- src/git_utils/repos.rs | 50 +++++++------------ 3 files changed, 31 insertions(+), 71 deletions(-) diff --git a/src/cli_parse/entities.rs b/src/cli_parse/entities.rs index afde4e6..ebd32dc 100644 --- a/src/cli_parse/entities.rs +++ b/src/cli_parse/entities.rs @@ -1,4 +1,3 @@ - pub struct CreateRepoArgs { pub allow_auto_merge: Option, pub allow_merge_commit: Option, diff --git a/src/cli_parse/handle_commands/handle_repo.rs b/src/cli_parse/handle_commands/handle_repo.rs index 5c2f0d3..587a4c2 100644 --- a/src/cli_parse/handle_commands/handle_repo.rs +++ b/src/cli_parse/handle_commands/handle_repo.rs @@ -13,6 +13,7 @@ use crate::git_utils::repo_info::Repo; use crate::git_utils::repo_info::RepoInfo; use crate::git_utils::repo_info::{RepoName, RepoOwner}; use crate::git_utils::repos; +use crate::cli_parse::entities::CreateRepoArgs; pub async fn handle_repo_command( github_client: Client, @@ -37,24 +38,28 @@ pub async fn handle_repo_command( name, private, } => { - handle_create_for_auth_user( - github_client, + let command_args = CreateRepoArgs { allow_auto_merge, allow_merge_commit, allow_rebase_merge, allow_squash_merge, auto_init, delete_branch_on_merge, - description, - gitignore_template, has_issues, has_projects, has_wiki, - homepage, is_template, + private, + description, + gitignore_template, + homepage, license_template, name, - private, + }; + + handle_create_for_auth_user( + github_client, + command_args ) .await?; Ok(()) @@ -157,41 +162,11 @@ pub async fn handle_repo_command( async fn handle_create_for_auth_user( github_client: Client, - allow_auto_merge: Option, - allow_merge_commit: Option, - allow_rebase_merge: Option, - allow_squash_merge: Option, - auto_init: Option, - delete_branch_on_merge: Option, - description: String, - gitignore_template: String, - has_issues: Option, - has_projects: Option, - has_wiki: Option, - homepage: String, - is_template: Option, - license_template: String, - name: String, - private: Option, + command_args: CreateRepoArgs, ) -> Result<(), Box> { let result = repos::create_for_authenticated_user( &github_client, - allow_auto_merge, - allow_merge_commit, - allow_rebase_merge, - allow_squash_merge, - auto_init, - delete_branch_on_merge, - &description, - &gitignore_template, - has_issues, - has_projects, - has_wiki, - &homepage, - is_template, - &license_template, - &name, - private, + command_args, ) .await?; diff --git a/src/git_utils/repos.rs b/src/git_utils/repos.rs index 5000173..4ab1e90 100644 --- a/src/git_utils/repos.rs +++ b/src/git_utils/repos.rs @@ -9,45 +9,31 @@ use octorust::{ Client, }; +use crate::cli_parse::entities::CreateRepoArgs; use crate::git_utils::{repo_info::RepoInfo, teams::get_id}; pub async fn create_for_authenticated_user( github_client: &Client, - allow_auto_merge: Option, - allow_merge_commit: Option, - allow_rebase_merge: Option, - allow_squash_merge: Option, - auto_init: Option, - delete_branch_on_merge: Option, - description: &String, - gitignore_template: &String, - has_issues: Option, - has_projects: Option, - has_wiki: Option, - homepage: &String, - is_template: Option, - license_template: &String, - name: &String, - private: Option, + command_args: CreateRepoArgs, ) -> Result> { let request = ReposCreateRequest { - allow_auto_merge: allow_auto_merge, - allow_merge_commit: allow_merge_commit, - allow_rebase_merge: allow_rebase_merge, - allow_squash_merge: allow_squash_merge, - auto_init: auto_init, - delete_branch_on_merge: delete_branch_on_merge, - description: description.clone(), - gitignore_template: gitignore_template.clone(), + allow_auto_merge: command_args.allow_auto_merge, + allow_merge_commit: command_args.allow_merge_commit, + allow_rebase_merge: command_args.allow_rebase_merge, + allow_squash_merge: command_args.allow_squash_merge, + auto_init: command_args.auto_init, + delete_branch_on_merge: command_args.delete_branch_on_merge, + description: command_args.description.clone(), + gitignore_template: command_args.gitignore_template.clone(), has_downloads: None, - has_issues: has_issues, - has_projects: has_projects, - has_wiki: has_wiki, - homepage: homepage.clone(), - is_template: is_template, - license_template: license_template.clone(), - name: name.clone(), - private: private, + has_issues: command_args.has_issues, + has_projects: command_args.has_projects, + has_wiki: command_args.has_wiki, + homepage: command_args.homepage.clone(), + is_template: command_args.is_template, + license_template: command_args.license_template.clone(), + name: command_args.name.clone(), + private: command_args.private, team_id: 1, }; From 50a4d0a31a898a23d7b1c57bc3bb2065b6718b82 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 21:06:45 +0400 Subject: [PATCH 07/20] Chore(repo): add usage CreateRepoArgs for create in org --- src/cli_parse/handle_commands/handle_repo.rs | 46 ++++++-------------- src/git_utils/repos.rs | 43 +++++++----------- 2 files changed, 28 insertions(+), 61 deletions(-) diff --git a/src/cli_parse/handle_commands/handle_repo.rs b/src/cli_parse/handle_commands/handle_repo.rs index 587a4c2..f1ba4d3 100644 --- a/src/cli_parse/handle_commands/handle_repo.rs +++ b/src/cli_parse/handle_commands/handle_repo.rs @@ -85,22 +85,28 @@ pub async fn handle_repo_command( team_name, visibility, } => { - handle_create_in_org( - github_client, + let command_args = CreateRepoArgs { allow_auto_merge, allow_merge_commit, allow_rebase_merge, allow_squash_merge, auto_init, delete_branch_on_merge, - description, - gitignore_template, has_issues, has_projects, has_wiki, - homepage, is_template, + private: None, + description, + gitignore_template, + homepage, license_template, + name: String::new(), + }; + + handle_create_in_org( + github_client, + command_args, name, org, team_name, @@ -176,20 +182,7 @@ async fn handle_create_for_auth_user( async fn handle_create_in_org( github_client: Client, - allow_auto_merge: Option, - allow_merge_commit: Option, - allow_rebase_merge: Option, - allow_squash_merge: Option, - auto_init: Option, - delete_branch_on_merge: Option, - description: String, - gitignore_template: String, - has_issues: Option, - has_projects: Option, - has_wiki: Option, - homepage: String, - is_template: Option, - license_template: String, + command_args: CreateRepoArgs, name: RepoName, org: RepoOwner, team_name: String, @@ -200,20 +193,7 @@ async fn handle_create_in_org( let result = repos::create_in_org( &github_client, repo_info, - allow_auto_merge, - allow_merge_commit, - allow_rebase_merge, - allow_squash_merge, - auto_init, - delete_branch_on_merge, - &description, - &gitignore_template, - has_issues, - has_projects, - has_wiki, - &homepage, - is_template, - &license_template, + command_args, &team_name, Some(visibility.0), ) diff --git a/src/git_utils/repos.rs b/src/git_utils/repos.rs index 4ab1e90..b35d87c 100644 --- a/src/git_utils/repos.rs +++ b/src/git_utils/repos.rs @@ -51,20 +51,7 @@ pub async fn create_for_authenticated_user( pub async fn create_in_org( github_client: &Client, repo_info: RepoInfo, - allow_auto_merge: Option, - allow_merge_commit: Option, - allow_rebase_merge: Option, - allow_squash_merge: Option, - auto_init: Option, - delete_branch_on_merge: Option, - description: &String, - gitignore_template: &String, - has_issues: Option, - has_projects: Option, - has_wiki: Option, - homepage: &String, - is_template: Option, - license_template: &String, + command_args: CreateRepoArgs, team_name: &String, visibility: Option, ) -> Result> { @@ -73,20 +60,20 @@ pub async fn create_in_org( let team_id = team.id; let request = ReposCreateInOrgRequest { - allow_auto_merge: allow_auto_merge, - allow_merge_commit: allow_merge_commit, - allow_rebase_merge: allow_rebase_merge, - allow_squash_merge: allow_squash_merge, - auto_init: auto_init, - delete_branch_on_merge: delete_branch_on_merge, - description: description.clone(), - gitignore_template: gitignore_template.clone(), - has_issues: has_issues, - has_projects: has_projects, - has_wiki: has_wiki, - homepage: homepage.clone(), - is_template: is_template, - license_template: license_template.clone(), + allow_auto_merge: command_args.allow_auto_merge, + allow_merge_commit: command_args.allow_merge_commit, + allow_rebase_merge: command_args.allow_rebase_merge, + allow_squash_merge: command_args.allow_squash_merge, + auto_init: command_args.auto_init, + delete_branch_on_merge: command_args.delete_branch_on_merge, + description: command_args.description.clone(), + gitignore_template: command_args.gitignore_template.clone(), + has_issues: command_args.has_issues, + has_projects: command_args.has_projects, + has_wiki: command_args.has_wiki, + homepage: command_args.homepage.clone(), + is_template: command_args.is_template, + license_template: command_args.license_template.clone(), name: repo_info.get_name(), private: None, team_id: team_id, From 12ad947015d94ba8c4e0032343fcbf1787c35a57 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 21:17:40 +0400 Subject: [PATCH 08/20] Chore(cli_in): change ToString trait to Display for IssuesListStates in set_vars mod --- src/cli_in/set_vars.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cli_in/set_vars.rs b/src/cli_in/set_vars.rs index d77fa52..f1b3029 100644 --- a/src/cli_in/set_vars.rs +++ b/src/cli_in/set_vars.rs @@ -1,4 +1,4 @@ -use std::str::FromStr; +use std::{fmt::Display, str::FromStr}; use octorust::types::{ IssuesListState, Order, ReposCreateInOrgRequestVisibility, ReposListOrgSort, ReposListOrgType, @@ -127,13 +127,13 @@ impl FromStr for IssuesListStates { } } -impl ToString for IssuesListStates { - fn to_string(&self) -> String { +impl Display for IssuesListStates { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self.0 { - IssuesListState::Open => String::from("open"), - IssuesListState::Closed => String::from("closed"), - IssuesListState::All => String::from("all"), - IssuesListState::FallthroughString => String::from("FallthroughString"), + IssuesListState::Open => write!(f, "open"), + IssuesListState::Closed => write!(f, "closed"), + IssuesListState::All => write!(f, "all"), + IssuesListState::FallthroughString => write!(f, "FallthroughString"), } } } From 1b80dcb901d68ea9a396697f157981bd0b02832a Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:00:27 +0400 Subject: [PATCH 09/20] Chore: cargo clippy fixes --- src/cli_out/print_in_cli.rs | 38 ++++++---------- src/git_utils/comments.rs | 50 ++++++++++---------- src/git_utils/issues.rs | 91 +++++++++++++++++-------------------- src/git_utils/releases.rs | 54 +++++++++------------- src/git_utils/repo_info.rs | 43 ++++++++---------- src/git_utils/repos.rs | 58 +++++++++++------------ src/git_utils/teams.rs | 22 +++++---- 7 files changed, 161 insertions(+), 195 deletions(-) diff --git a/src/cli_out/print_in_cli.rs b/src/cli_out/print_in_cli.rs index 2e0d232..85ee5be 100644 --- a/src/cli_out/print_in_cli.rs +++ b/src/cli_out/print_in_cli.rs @@ -66,7 +66,7 @@ pub fn print_issues(list_issues: Vec, state: IssuesListStates, numb ); println!(); for issue in list_issues { - if issue.pull_request != None { + if issue.pull_request.is_some() { continue; } println!("╭────────────────────────────────────────────────────────────────────────────────────────────────"); @@ -76,18 +76,16 @@ pub fn print_issues(list_issues: Vec, state: IssuesListStates, numb for label in issue.labels { println!(" {}: {}", label.name, label.description); } - match issue.created_at { - Some(time) => { - println!(" Created at: {}", time); - } - None => {} + + if let Some(time) = issue.created_at { + println!(" Created at: {time}"); }; println!("╰────────────────────────────────────────────────────────────────────────────────────────────────"); } } pub fn print_simple_issue(issue: IssueSimple) -> Result<(), Box> { - if issue.pull_request != None { + if issue.pull_request.is_some() { return Err(Box::new(PrintError { kind: PrintErrorKind::NotIssue, description: "Trying get pull request from issue command".to_string(), @@ -101,41 +99,35 @@ pub fn print_simple_issue(issue: IssueSimple) -> Result<(), Box> { for label in issue.labels { println!(" {}: {}", label.name, label.description); } - match issue.created_at { - Some(time) => { - println!(" Created at: {}", time); - } - None => {} + + if let Some(time) = issue.created_at { + println!(" Created at: {time}"); }; println!("╰────────────────────────────────────────────────────────────────────────────────────────────────"); Ok(()) } pub fn print_issue(issue: Issue) -> Result<(), Box> { - if issue.pull_request != None { + if issue.pull_request.is_some() { return Err(Box::new(PrintError { kind: PrintErrorKind::NotIssue, description: "Trying get pull request from issue command".to_string(), })); } + println!("╭────────────────────────────────────────────────────────────────────────────────────────────────"); println!(" Issue {}: {};", issue.number, issue.title); println!(" State: {}", issue.state); println!(" Body: {}", issue.body); println!(" labels:"); for label in issue.labels { - match label.labels_data() { - Some(data) => { - println!(" {}: {}", data.name, data.description); - } - None => {} + if let Some(data) = label.labels_data() { + println!(" {}: {}", data.name, data.description); } } - match issue.created_at { - Some(time) => { - println!(" Created at: {}", time); - } - None => {} + + if let Some(time) = issue.created_at { + println!(" Created at: {time}"); }; println!("╰────────────────────────────────────────────────────────────────────────────────────────────────"); Ok(()) diff --git a/src/git_utils/comments.rs b/src/git_utils/comments.rs index 2874279..08533d2 100644 --- a/src/git_utils/comments.rs +++ b/src/git_utils/comments.rs @@ -11,24 +11,26 @@ pub async fn create( github_client: &Client, repo_info: &RepoInfo, issue_number: &i64, - body: &String, + body: &str, ) -> Result> { - let request = PullsUpdateReviewRequest { body: body.clone() }; + let request = PullsUpdateReviewRequest { + body: body.to_owned(), + }; let comment = github_client .issues() .create_comment( - &repo_info.get_owner().trim(), - &repo_info.get_name().trim(), - issue_number.clone(), + &repo_info.get_owner(), + &repo_info.get_name(), + *issue_number, &request, ) .await; - return match comment { + match comment { Ok(_) => Ok("Comment create successed".to_string()), Err(er) => Err(Box::new(er)), - }; + } } // Get all Comments for issue/pull request without review comments @@ -39,18 +41,13 @@ pub async fn get_all( ) -> Result, Box> { let list_comments = github_client .issues() - .list_all_comments( - &repo_info.get_owner(), - &repo_info.get_name(), - number.clone(), - None, - ) + .list_all_comments(&repo_info.get_owner(), &repo_info.get_name(), *number, None) .await; - return match list_comments { + match list_comments { Ok(c) => Ok(c.body), Err(er) => Err(Box::new(er)), - }; + } } // Get all review Comments for pull request @@ -66,40 +63,41 @@ pub async fn get_all_from_review( .list_all_review_comments( &repo_info.get_owner(), &repo_info.get_name(), - number.clone(), + *number, sort, direction, None, ) .await; - return match list_comments { + match list_comments { Ok(c) => Ok(c.body), Err(er) => Err(Box::new(er)), - }; + } } - pub async fn update( github_client: &Client, repo_info: &RepoInfo, comment_id: &i64, - body: &String, + body: &str, ) -> Result> { - let request = PullsUpdateReviewRequest { body: body.clone() }; + let request = PullsUpdateReviewRequest { + body: body.to_owned(), + }; let comment = github_client .issues() .update_comment( - &repo_info.get_owner().trim(), - &repo_info.get_name().trim(), - comment_id.clone(), + &repo_info.get_owner(), + &repo_info.get_name(), + *comment_id, &request, ) .await; - return match comment { + match comment { Ok(_) => Ok("Comment update successed".to_string()), Err(er) => Err(Box::new(er)), - }; + } } diff --git a/src/git_utils/issues.rs b/src/git_utils/issues.rs index 31fa38c..c393c5a 100644 --- a/src/git_utils/issues.rs +++ b/src/git_utils/issues.rs @@ -25,10 +25,10 @@ pub async fn get( pub async fn get_list( github_client: &Client, repo_info: &RepoInfo, - creator: &String, - assignee: &String, + creator: &str, + assignee: &str, state: &types::IssuesListState, - labels: &String, + labels: &str, numb_of_page: &i64, iss_on_page: &i64, ) -> Result, Box> { @@ -37,10 +37,10 @@ pub async fn get_list( let issues = github_client .issues() .list_for_repo( - &repo_info.get_owner().trim(), - &repo_info.get_name().trim(), + &repo_info.get_owner(), + &repo_info.get_name(), "", - state.clone(), + state.to_owned(), assignee, creator, "", @@ -48,38 +48,38 @@ pub async fn get_list( sort, types::Order::Noop, None, - iss_on_page.clone(), - numb_of_page.clone(), + *iss_on_page, + *numb_of_page, ) .await; - return match issues { + match issues { Ok(info) => Ok(info.body), Err(er) => Err(Box::new(er)), - }; + } } fn get_create_request( - title: &String, - body: &String, - assignees: &Vec, - labels: &Vec, + title: &str, + body: &str, + assignees: &[String], + labels: &[String], ) -> IssuesCreateRequest { - let new_title = TitleOneOf::String(title.clone()); + let new_title = TitleOneOf::String(title.to_owned()); let new_labels = labels - .into_iter() + .iter() .map(|s| IssuesCreateRequestLabelsOneOf::String(s.into())) .collect(); IssuesCreateRequest { title: new_title, - body: body.clone(), + body: body.to_owned(), assignee: String::new(), assignees: if assignees.is_empty() { Vec::new() } else { - assignees.clone() + assignees.to_owned() }, labels: new_labels, milestone: None, @@ -89,39 +89,32 @@ fn get_create_request( pub async fn create( github_client: &Client, repo_info: RepoInfo, - title: &String, - body: &String, - assignees: &Vec, - labels: &Vec, + title: &str, + body: &str, + assignees: &[String], + labels: &[String], ) -> Result> { let request = get_create_request(title, body, assignees, labels); let new_issue = github_client .issues() - .create( - &repo_info.get_owner().trim(), - &repo_info.get_name().trim(), - &request, - ) + .create(&repo_info.get_owner(), &repo_info.get_name(), &request) .await; - return match new_issue { + match new_issue { Ok(_) => Ok("Success".to_string()), Err(er) => Err(Box::new(er)), - }; + } } fn get_update_request( title: Option, body: Option, - assignees: Option<&Vec>, - labels: Option<&Vec>, + assignees: Option<&[String]>, + labels: Option<&[String]>, state: &State, ) -> IssuesUpdateRequest { - let new_title = match title { - Some(t) => Some(TitleOneOf::String(t.to_string())), - None => None, - }; + let new_title = title.map(|t| TitleOneOf::String(t.to_string())); let new_labels = match labels { Some(l) => l @@ -146,9 +139,9 @@ pub async fn close( github_client: &Client, repo_info: RepoInfo, issue_number: &i64, - comment: &String, + comment: &str, ) -> Result> { - if comment != "" { + if comment.is_empty() { let new_comment = comments::create(github_client, &repo_info, issue_number, comment).await?; println!("{new_comment}"); @@ -159,17 +152,17 @@ pub async fn close( let close = github_client .issues() .update( - &repo_info.get_owner().trim(), - &repo_info.get_name().trim(), - issue_number.clone(), + &repo_info.get_owner(), + &repo_info.get_name(), + *issue_number, &request, ) .await; - return match close { + match close { Ok(_) => Ok("Success".to_string()), Err(er) => Err(Box::new(er)), - }; + } } pub async fn update( @@ -178,8 +171,8 @@ pub async fn update( issue_number: &i64, title: Option, body: Option, - assignees: &Vec, - labels: &Vec, + assignees: &[String], + labels: &[String], state: &State, ) -> Result> { let request = get_update_request(title, body, Some(assignees), Some(labels), state); @@ -187,15 +180,15 @@ pub async fn update( let update_iss = github_client .issues() .update( - &repo_info.get_owner().trim(), - &repo_info.get_name().trim(), - issue_number.clone(), + &repo_info.get_owner(), + &repo_info.get_name(), + *issue_number, &request, ) .await; - return match update_iss { + match update_iss { Ok(_) => Ok("Success".to_string()), Err(er) => Err(Box::new(er)), - }; + } } diff --git a/src/git_utils/releases.rs b/src/git_utils/releases.rs index 9b5f9c7..23ff90f 100644 --- a/src/git_utils/releases.rs +++ b/src/git_utils/releases.rs @@ -13,34 +13,30 @@ pub async fn create( body: String, discussion_category_name: String, draft: Option, - name: &String, + name: &str, prerelease: Option, - tag_name: &String, + tag_name: &str, target_commitish: String, ) -> Result> { let request = ReposCreateReleaseRequest { - body: body, - discussion_category_name: discussion_category_name, - draft: draft, - name: name.clone(), - prerelease: prerelease, - tag_name: tag_name.clone(), - target_commitish: target_commitish, + body, + discussion_category_name, + draft, + name: name.to_owned(), + prerelease, + tag_name: tag_name.to_owned(), + target_commitish, }; let result = github_client .repos() - .create_release( - repo_info.get_owner().trim(), - repo_info.get_name().trim(), - &request, - ) + .create_release(&repo_info.get_owner(), &repo_info.get_name(), &request) .await; - return match result { + match result { Ok(_) => Ok(repo_info.get_release_url(tag_name)), Err(er) => Err(Box::new(er)), - }; + } } pub async fn get_latest( @@ -49,13 +45,13 @@ pub async fn get_latest( ) -> Result> { let result = github_client .repos() - .get_latest_release(&repo_info.get_owner().trim(), &repo_info.get_name().trim()) + .get_latest_release(&repo_info.get_owner(), &repo_info.get_name()) .await; - return match result { + match result { Ok(r) => Ok(r.body), Err(er) => Err(Box::new(er)), - }; + } } pub async fn get_by_tag( @@ -65,17 +61,13 @@ pub async fn get_by_tag( ) -> Result> { let result = github_client .repos() - .get_release_by_tag( - &repo_info.get_owner().trim(), - &repo_info.get_name().trim(), - &tag, - ) + .get_release_by_tag(&repo_info.get_owner(), &repo_info.get_name(), &tag) .await; - return match result { + match result { Ok(r) => Ok(r.body), Err(er) => Err(Box::new(er)), - }; + } } pub async fn get_by_id( @@ -85,15 +77,11 @@ pub async fn get_by_id( ) -> Result> { let result = github_client .repos() - .get_release( - &repo_info.get_owner().trim(), - &repo_info.get_name().trim(), - id, - ) + .get_release(&repo_info.get_owner(), &repo_info.get_name(), id) .await; - return match result { + match result { Ok(r) => Ok(r.body), Err(er) => Err(Box::new(er)), - }; + } } diff --git a/src/git_utils/repo_info.rs b/src/git_utils/repo_info.rs index 4693151..a7911df 100644 --- a/src/git_utils/repo_info.rs +++ b/src/git_utils/repo_info.rs @@ -16,13 +16,13 @@ pub struct RepoSsh(String); impl RepoOwner { pub fn trim(&self) -> &str { - return self.0.trim(); + self.0.trim() } } impl RepoName { pub fn trim(&self) -> &str { - return self.0.trim(); + self.0.trim() } } @@ -84,12 +84,12 @@ impl RepoInfo { if parts.len() > 2 { let owner = parts[parts.len() - 2]; let repo = parts[parts.len() - 1]; - return Ok((RepoOwner(owner.to_string()), RepoName(repo.to_string()))); + Ok((RepoOwner(owner.to_string()), RepoName(repo.to_string()))) } else { - return Err(io::Error::new( + Err(io::Error::new( io::ErrorKind::InvalidData, "Can't parse string", - )); + )) } } @@ -97,13 +97,12 @@ impl RepoInfo { fn get_current_repo(mut self) -> Result { // Creating a command to search for a link to a remote repository let git_link = Command::new("git") - .args(&["remote", "get-url", "origin"]) + .args(["remote", "get-url", "origin"]) .output()?; // Git repository was not found in this directory if !git_link.status.success() { - return Err(io::Error::new( - io::ErrorKind::Other, + return Err(io::Error::other( "Git repository not found in this directory", )); } @@ -116,7 +115,7 @@ impl RepoInfo { Self::set_url(&mut self); Self::set_ssh(&mut self); - return Ok(self); + Ok(self) } fn set_url(&mut self) { @@ -136,22 +135,22 @@ impl RepoInfo { } pub fn get_owner(&self) -> String { - return self.owner.clone().0; + self.owner.clone().0 } pub fn get_name(&self) -> String { - return self.name.clone().0; + self.name.clone().0 } - pub fn get_release_url(&self, tag: &String) -> String { + pub fn get_release_url(&self, tag: &str) -> String { let mut release_url = self.url.clone(); release_url.push_str("releases/tag/"); release_url.push_str(tag.trim()); - return release_url.0; + release_url.0 } pub fn get_ssh(&self) -> String { - return self.ssh.clone().0; + self.ssh.clone().0 } fn create_repo_info( @@ -159,15 +158,15 @@ impl RepoInfo { name: Option, ) -> Result { if owner.is_none() { - return Err(io::Error::new( + Err(io::Error::new( io::ErrorKind::NotFound, "Not found repo owner", - )); + )) } else if name.is_none() { - return Err(io::Error::new( + Err(io::Error::new( io::ErrorKind::NotFound, "Not found repo name", - )); + )) } else { let mut new_repo = RepoInfo { owner: RepoOwner(owner.unwrap().0.trim().to_string()), @@ -178,7 +177,7 @@ impl RepoInfo { Self::set_url(&mut new_repo); Self::set_ssh(&mut new_repo); - return Ok(new_repo); + Ok(new_repo) } } @@ -195,11 +194,9 @@ impl RepoInfo { url: RepoUrl(String::new()), ssh: RepoSsh(String::new()), }; - return Self::get_current_repo(new_repo); - } - Repo::Input => { - return Self::create_repo_info(owner, name); + Self::get_current_repo(new_repo) } + Repo::Input => Self::create_repo_info(owner, name), } } } diff --git a/src/git_utils/repos.rs b/src/git_utils/repos.rs index b35d87c..5bd602b 100644 --- a/src/git_utils/repos.rs +++ b/src/git_utils/repos.rs @@ -42,20 +42,20 @@ pub async fn create_for_authenticated_user( .create_for_authenticated_user(&request) .await; - return match new_repo { + match new_repo { Ok(_) => Ok("Success".to_string()), Err(er) => Err(Box::new(er)), - }; + } } pub async fn create_in_org( github_client: &Client, repo_info: RepoInfo, - command_args: CreateRepoArgs, - team_name: &String, + command_args: CreateRepoArgs, + team_name: &str, visibility: Option, ) -> Result> { - let team = get_id(github_client, &repo_info.get_owner(), team_name).await; + let team = get_id(github_client, &repo_info.get_owner(), team_name).await?; let team_id = team.id; @@ -76,8 +76,8 @@ pub async fn create_in_org( license_template: command_args.license_template.clone(), name: repo_info.get_name(), private: None, - team_id: team_id, - visibility: visibility, + team_id, + visibility, }; let new_repo = github_client @@ -85,15 +85,15 @@ pub async fn create_in_org( .create_in_org(repo_info.get_owner().trim(), &request) .await; - return match new_repo { + match new_repo { Ok(_) => Ok(repo_info.get_ssh()), Err(er) => Err(Box::new(er)), - }; + } } pub async fn get_all_from_org( github_client: &Client, - org: &String, + org: &str, order: Order, type_value: ReposListOrgType, sort_value: ReposListOrgSort, @@ -103,65 +103,61 @@ pub async fn get_all_from_org( .list_all_for_org(org.trim(), type_value, sort_value, order) .await; - return match all_repos { + match all_repos { Ok(r) => Ok(r.body), Err(er) => Err(Box::new(er)), - }; + } } pub async fn create_using_template( github_client: &Client, template_info: RepoInfo, repo_info: RepoInfo, - description: &String, + description: &str, include_all_branches: Option, private: Option, ) -> Result> { let request = ReposCreateUsingTemplateRequest { - description: description.clone(), - include_all_branches: include_all_branches, + description: description.to_owned(), + include_all_branches, name: repo_info.get_name(), owner: repo_info.get_owner(), - private: private, + private, }; let new_repo = github_client .repos() .create_using_template( - &template_info.get_owner().trim(), - &template_info.get_name().trim(), + &template_info.get_owner(), + &template_info.get_name(), &request, ) .await; - return match new_repo { + match new_repo { Ok(_) => Ok(repo_info.get_ssh()), Err(er) => Err(Box::new(er)), - }; + } } pub async fn create_fork( github_client: &Client, - org: &String, + org: &str, fork_info: RepoInfo, ) -> Result> { let request = ReposCreateForkRequest { - organization: org.clone(), + organization: org.to_owned(), }; let new_fork = github_client .repos() - .create_fork( - &fork_info.get_owner().trim(), - &fork_info.get_name().trim(), - &request, - ) + .create_fork(&fork_info.get_owner(), &fork_info.get_name(), &request) .await; - return match new_fork { + match new_fork { Ok(_) => Ok("Success".to_string()), Err(er) => Err(Box::new(er)), - }; + } } pub async fn get_all_from_user( @@ -176,8 +172,8 @@ pub async fn get_all_from_user( .list_all_for_user(owner.trim(), type_value, sort_value, order) .await; - return match all_repos { + match all_repos { Ok(reps) => Ok(reps.body), Err(er) => Err(Box::new(er)), - }; + } } diff --git a/src/git_utils/teams.rs b/src/git_utils/teams.rs index c7a7753..eedc33e 100644 --- a/src/git_utils/teams.rs +++ b/src/git_utils/teams.rs @@ -1,17 +1,19 @@ -use std::process; +use std::error::Error; use octorust::{types::FullTeam, Client}; -pub async fn get_id(github_client: &Client, org: &String, name: &String) -> FullTeam { +pub async fn get_id( + github_client: &Client, + org: &str, + name: &str, +) -> Result> { let team = github_client .teams() - .get_by_name(org.trim(), name.trim()) + .get_by_name(org, name) .await; - return match team { - Ok(t) => t.body, - Err(message) => { - eprintln!("Error: {message}"); - process::exit(1); - } - }; + + match team { + Ok(t) => Ok(t.body), + Err(err) => Err(Box::new(err)), + } } From ce9e456e9c4f69e4172a3e86c36a343f3f086f3f Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:16:14 +0400 Subject: [PATCH 10/20] Feat(entities): add ListIssueArgs struct --- src/cli_parse/entities.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cli_parse/entities.rs b/src/cli_parse/entities.rs index ebd32dc..562cdbf 100644 --- a/src/cli_parse/entities.rs +++ b/src/cli_parse/entities.rs @@ -1,3 +1,14 @@ +use crate::cli_in::set_vars::IssuesListStates; + + +pub struct ListIssueArgs { + pub creator: String, + pub assignee: String, + pub state: IssuesListStates, + pub labels: String, + pub numb_of_page: i64, + pub iss_on_page: i64, +} pub struct CreateRepoArgs { pub allow_auto_merge: Option, pub allow_merge_commit: Option, From 42511ae7fc267ca398db401f5d6d96d4b97dba93 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:16:52 +0400 Subject: [PATCH 11/20] Chore(issue): add usage ListIssueArgs --- src/cli_parse/handle_commands/handle_issue.rs | 60 ++++--------------- src/git_utils/issues.rs | 20 +++---- 2 files changed, 20 insertions(+), 60 deletions(-) diff --git a/src/cli_parse/handle_commands/handle_issue.rs b/src/cli_parse/handle_commands/handle_issue.rs index 3ba42ca..1d8491c 100644 --- a/src/cli_parse/handle_commands/handle_issue.rs +++ b/src/cli_parse/handle_commands/handle_issue.rs @@ -2,13 +2,13 @@ use octorust::{self, Client}; use std::error::Error; use crate::cli_in::issue_command::IssueCommand; -use crate::cli_in::set_vars::IssuesListStates; use crate::cli_in::set_vars::States; use crate::cli_out::fuzzy_select::choose_issue; use crate::cli_out::print_in_cli::print_comments; use crate::cli_out::print_in_cli::print_issue; use crate::cli_out::print_in_cli::print_issues; use crate::cli_out::print_in_cli::print_simple_issue; +use crate::cli_parse::entities::ListIssueArgs; use crate::git_utils::comments; use crate::git_utils::issues; use crate::git_utils::repo_info::Repo; @@ -30,18 +30,15 @@ pub async fn handle_issue_command( numb_of_page, iss_on_page, } => { - handle_list( - github_client, - owner, - repo, + let command_args = ListIssueArgs { creator, assignee, state, labels, numb_of_page, iss_on_page, - ) - .await?; + }; + handle_list(github_client, owner, repo, command_args).await?; Ok(()) } @@ -64,18 +61,15 @@ pub async fn handle_issue_command( numb_of_page, iss_on_page, } => { - handle_get_form_list( - github_client, - owner, - repo, + let command_args = ListIssueArgs { creator, assignee, state, labels, numb_of_page, iss_on_page, - ) - .await?; + }; + handle_get_form_list(github_client, owner, repo, command_args).await?; Ok(()) } @@ -132,31 +126,16 @@ async fn handle_list( github_client: Client, owner: Option, repo: Option, - creator: String, - assignee: String, - state: IssuesListStates, - labels: String, - numb_of_page: i64, - iss_on_page: i64, + command_args: ListIssueArgs, ) -> Result<(), Box> { let repo_info = match owner { Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, None => RepoInfo::new(Repo::Current, None, None)?, }; - let list_issues = issues::get_list( - &github_client, - &repo_info, - &creator, - &assignee, - &state.0, - &labels, - &numb_of_page, - &iss_on_page, - ) - .await?; + let list_issues = issues::get_list(&github_client, &repo_info, &command_args).await?; - print_issues(list_issues, state, numb_of_page); + print_issues(list_issues, command_args.state, command_args.numb_of_page); Ok(()) } @@ -184,29 +163,14 @@ async fn handle_get_form_list( github_client: Client, owner: Option, repo: Option, - creator: String, - assignee: String, - state: IssuesListStates, - labels: String, - numb_of_page: i64, - iss_on_page: i64, + command_args: ListIssueArgs, ) -> Result<(), Box> { let repo_info = match owner { Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, None => RepoInfo::new(Repo::Current, None, None)?, }; - let list_issues = issues::get_list( - &github_client, - &repo_info, - &creator, - &assignee, - &state.0, - &labels, - &numb_of_page, - &iss_on_page, - ) - .await?; + let list_issues = issues::get_list(&github_client, &repo_info, &command_args).await?; let choosed_issue = choose_issue(list_issues)?; diff --git a/src/git_utils/issues.rs b/src/git_utils/issues.rs index c393c5a..d3f174b 100644 --- a/src/git_utils/issues.rs +++ b/src/git_utils/issues.rs @@ -6,6 +6,7 @@ use octorust::types::{ }; use octorust::Client; +use crate::cli_parse::entities::ListIssueArgs; use crate::git_utils::comments; use crate::git_utils::repo_info::RepoInfo; @@ -25,12 +26,7 @@ pub async fn get( pub async fn get_list( github_client: &Client, repo_info: &RepoInfo, - creator: &str, - assignee: &str, - state: &types::IssuesListState, - labels: &str, - numb_of_page: &i64, - iss_on_page: &i64, + command_args: &ListIssueArgs, ) -> Result, Box> { let sort = types::IssuesListSort::Created; @@ -40,16 +36,16 @@ pub async fn get_list( &repo_info.get_owner(), &repo_info.get_name(), "", - state.to_owned(), - assignee, - creator, + command_args.state.0.to_owned(), + &command_args.assignee, + &command_args.creator, "", - labels, + &command_args.labels, sort, types::Order::Noop, None, - *iss_on_page, - *numb_of_page, + command_args.iss_on_page, + command_args.numb_of_page, ) .await; From d74423041847af9e67c53f82b551f3ae752fe5fc Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:29:21 +0400 Subject: [PATCH 12/20] Feat(entities): add UpdateIssueArgs struct --- src/cli_parse/entities.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cli_parse/entities.rs b/src/cli_parse/entities.rs index 562cdbf..0cc205a 100644 --- a/src/cli_parse/entities.rs +++ b/src/cli_parse/entities.rs @@ -1,5 +1,4 @@ -use crate::cli_in::set_vars::IssuesListStates; - +use crate::cli_in::set_vars::{IssuesListStates, States}; pub struct ListIssueArgs { pub creator: String, @@ -9,6 +8,14 @@ pub struct ListIssueArgs { pub numb_of_page: i64, pub iss_on_page: i64, } + +pub struct UpdateIssueArgs { + pub title: Option, + pub body: Option, + pub number: i64, + pub state: States, +} + pub struct CreateRepoArgs { pub allow_auto_merge: Option, pub allow_merge_commit: Option, @@ -27,4 +34,3 @@ pub struct CreateRepoArgs { pub license_template: String, pub name: String, } - From 03ffa61b27882e81f21cd38cf7febbb619e73212 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:29:30 +0400 Subject: [PATCH 13/20] Chore(issue): add usage UpdateIssueArgs --- src/cli_parse/handle_commands/handle_issue.rs | 23 +++++-------------- src/git_utils/issues.rs | 17 ++++++++------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/cli_parse/handle_commands/handle_issue.rs b/src/cli_parse/handle_commands/handle_issue.rs index 1d8491c..59d2b67 100644 --- a/src/cli_parse/handle_commands/handle_issue.rs +++ b/src/cli_parse/handle_commands/handle_issue.rs @@ -2,13 +2,13 @@ use octorust::{self, Client}; use std::error::Error; use crate::cli_in::issue_command::IssueCommand; -use crate::cli_in::set_vars::States; use crate::cli_out::fuzzy_select::choose_issue; use crate::cli_out::print_in_cli::print_comments; use crate::cli_out::print_in_cli::print_issue; use crate::cli_out::print_in_cli::print_issues; use crate::cli_out::print_in_cli::print_simple_issue; use crate::cli_parse::entities::ListIssueArgs; +use crate::cli_parse::entities::UpdateIssueArgs; use crate::git_utils::comments; use crate::git_utils::issues; use crate::git_utils::repo_info::Repo; @@ -105,18 +105,13 @@ pub async fn handle_issue_command( state, labels, } => { - handle_update( - github_client, - owner, - repo, + let command_args = UpdateIssueArgs { title, body, number, - labels, - assignees, state, - ) - .await?; + }; + handle_update(github_client, owner, repo, labels, assignees, command_args).await?; Ok(()) } } @@ -239,12 +234,9 @@ async fn handle_update( github_client: Client, owner: Option, repo: Option, - title: Option, - body: Option, - number: i64, labels: Option, assignees: Option, - state: States, + command_args: UpdateIssueArgs, ) -> Result<(), Box> { let repo_info = match owner { Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, @@ -263,12 +255,9 @@ async fn handle_update( let result = issues::update( &github_client, repo_info, - &number, - title, - body, + command_args, &assignees_list, &labels_list, - &state.0, ) .await?; diff --git a/src/git_utils/issues.rs b/src/git_utils/issues.rs index d3f174b..f2a7408 100644 --- a/src/git_utils/issues.rs +++ b/src/git_utils/issues.rs @@ -6,7 +6,7 @@ use octorust::types::{ }; use octorust::Client; -use crate::cli_parse::entities::ListIssueArgs; +use crate::cli_parse::entities::{ListIssueArgs, UpdateIssueArgs}; use crate::git_utils::comments; use crate::git_utils::repo_info::RepoInfo; @@ -164,21 +164,24 @@ pub async fn close( pub async fn update( github_client: &Client, repo_info: RepoInfo, - issue_number: &i64, - title: Option, - body: Option, + command_args: UpdateIssueArgs, assignees: &[String], labels: &[String], - state: &State, ) -> Result> { - let request = get_update_request(title, body, Some(assignees), Some(labels), state); + let request = get_update_request( + command_args.title, + command_args.body, + Some(assignees), + Some(labels), + &command_args.state.0, + ); let update_iss = github_client .issues() .update( &repo_info.get_owner(), &repo_info.get_name(), - *issue_number, + command_args.number, &request, ) .await; From adfdce3603a386f645c9b4c956707f8c51286d60 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:35:23 +0400 Subject: [PATCH 14/20] Feat(entities): add CreateRepoFromTemplateArgs struct --- src/cli_parse/entities.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cli_parse/entities.rs b/src/cli_parse/entities.rs index 0cc205a..fda0dcc 100644 --- a/src/cli_parse/entities.rs +++ b/src/cli_parse/entities.rs @@ -34,3 +34,9 @@ pub struct CreateRepoArgs { pub license_template: String, pub name: String, } + +pub struct CreateRepoFromTemplateArgs { + pub description: String, + pub include_all_branches: Option, + pub private: Option, +} From c04ebd16a66ace4ebce499ba3d3090ab6b89158d Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:36:09 +0400 Subject: [PATCH 15/20] Chore(repo): add usage CreateRepoFromTemplateArgs --- src/cli_parse/handle_commands/handle_repo.rs | 18 +++++++++--------- src/git_utils/repos.rs | 12 +++++------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/cli_parse/handle_commands/handle_repo.rs b/src/cli_parse/handle_commands/handle_repo.rs index f1ba4d3..a54dcf8 100644 --- a/src/cli_parse/handle_commands/handle_repo.rs +++ b/src/cli_parse/handle_commands/handle_repo.rs @@ -9,6 +9,7 @@ use crate::cli_in::set_vars::ReposListUserTypes; use crate::cli_in::set_vars::Visibilities; use crate::cli_out::print_in_cli::print_repos; use crate::cli_out::print_in_cli::print_url; +use crate::cli_parse::entities::CreateRepoFromTemplateArgs; use crate::git_utils::repo_info::Repo; use crate::git_utils::repo_info::RepoInfo; use crate::git_utils::repo_info::{RepoName, RepoOwner}; @@ -135,15 +136,18 @@ pub async fn handle_repo_command( private, include_all_branches, } => { + let command_args = CreateRepoFromTemplateArgs { + description, + private, + include_all_branches + }; handle_create_using_template( github_client, owner, name, template_owner, template_name, - description, - include_all_branches, - private, + command_args ) .await?; Ok(()) @@ -223,9 +227,7 @@ async fn handle_create_using_template( name: RepoName, template_owner: RepoOwner, template_name: RepoName, - description: String, - include_all_branches: Option, - private: Option, + command_args: CreateRepoFromTemplateArgs ) -> Result<(), Box> { let repo_info: RepoInfo = RepoInfo::new(Repo::Input, Some(owner), Some(name))?; let template_info: RepoInfo = @@ -235,9 +237,7 @@ async fn handle_create_using_template( &github_client, template_info, repo_info, - &description, - include_all_branches, - private, + command_args ) .await?; diff --git a/src/git_utils/repos.rs b/src/git_utils/repos.rs index 5bd602b..d3511bf 100644 --- a/src/git_utils/repos.rs +++ b/src/git_utils/repos.rs @@ -9,7 +9,7 @@ use octorust::{ Client, }; -use crate::cli_parse::entities::CreateRepoArgs; +use crate::cli_parse::entities::{CreateRepoArgs, CreateRepoFromTemplateArgs}; use crate::git_utils::{repo_info::RepoInfo, teams::get_id}; pub async fn create_for_authenticated_user( @@ -113,16 +113,14 @@ pub async fn create_using_template( github_client: &Client, template_info: RepoInfo, repo_info: RepoInfo, - description: &str, - include_all_branches: Option, - private: Option, + command_args: CreateRepoFromTemplateArgs, ) -> Result> { let request = ReposCreateUsingTemplateRequest { - description: description.to_owned(), - include_all_branches, + description: command_args.description, + include_all_branches: command_args.include_all_branches, name: repo_info.get_name(), owner: repo_info.get_owner(), - private, + private: command_args.private, }; let new_repo = github_client From 99eb3b1283cd41f9d764156b20f21c170e9627ac Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:45:41 +0400 Subject: [PATCH 16/20] Feat(entities): add CreateReleaseArgs struct --- src/cli_parse/entities.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/cli_parse/entities.rs b/src/cli_parse/entities.rs index fda0dcc..8f6dc52 100644 --- a/src/cli_parse/entities.rs +++ b/src/cli_parse/entities.rs @@ -36,7 +36,17 @@ pub struct CreateRepoArgs { } pub struct CreateRepoFromTemplateArgs { - pub description: String, - pub include_all_branches: Option, - pub private: Option, + pub description: String, + pub include_all_branches: Option, + pub private: Option, +} + +pub struct CreateReleaseArgs { + pub body: String, + pub name: String, + pub discussion_category_name: String, + pub tag_name: String, + pub draft: Option, + pub prerelease: Option, + pub target_commitish: String, } From ddf781aab891cd74c88d958bb7829a5499994718 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:46:20 +0400 Subject: [PATCH 17/20] Chore(release): add usage CreateReleaseArgs --- .../handle_commands/handle_release.rs | 37 +++++-------------- src/git_utils/releases.rs | 26 +++++-------- 2 files changed, 19 insertions(+), 44 deletions(-) diff --git a/src/cli_parse/handle_commands/handle_release.rs b/src/cli_parse/handle_commands/handle_release.rs index a62a598..e8caa9a 100644 --- a/src/cli_parse/handle_commands/handle_release.rs +++ b/src/cli_parse/handle_commands/handle_release.rs @@ -4,6 +4,7 @@ use std::error::Error; use crate::cli_in::release_command::ReleaseCommand; use crate::cli_out::print_in_cli::print_release; use crate::cli_out::print_in_cli::print_url; +use crate::cli_parse::entities::CreateReleaseArgs; use crate::git_utils::releases; use crate::git_utils::repo_info::Repo; use crate::git_utils::repo_info::RepoInfo; @@ -26,19 +27,16 @@ pub async fn handle_release_command( tag_name, target_commitish, } => { - handle_create( - github_client, - owner, - repo, + let command_args = CreateReleaseArgs { body, - discussion_category_name, name, - draft, - prerelease, tag_name, target_commitish, - ) - .await?; + discussion_category_name, + draft, + prerelease, + }; + handle_create(github_client, owner, repo, command_args).await?; Ok(()) } @@ -63,28 +61,11 @@ async fn handle_create( github_client: Client, owner: RepoOwner, repo: RepoName, - body: String, - discussion_category_name: String, - name: String, - draft: Option, - prerelease: Option, - tag_name: String, - target_commitish: String, + command_args: CreateReleaseArgs, ) -> Result<(), Box> { let repo_info: RepoInfo = RepoInfo::new(Repo::Input, Some(owner), Some(repo))?; - let result = releases::create( - &github_client, - repo_info, - body, - discussion_category_name, - draft, - &name, - prerelease, - &tag_name, - target_commitish, - ) - .await?; + let result = releases::create(&github_client, repo_info, command_args).await?; print_url(result, "New release"); Ok(()) diff --git a/src/git_utils/releases.rs b/src/git_utils/releases.rs index 23ff90f..e7fd35e 100644 --- a/src/git_utils/releases.rs +++ b/src/git_utils/releases.rs @@ -5,27 +5,21 @@ use octorust::{ Client, }; -use crate::git_utils::repo_info::RepoInfo; +use crate::{cli_parse::entities::CreateReleaseArgs, git_utils::repo_info::RepoInfo}; pub async fn create( github_client: &Client, repo_info: RepoInfo, - body: String, - discussion_category_name: String, - draft: Option, - name: &str, - prerelease: Option, - tag_name: &str, - target_commitish: String, + command_args: CreateReleaseArgs, ) -> Result> { let request = ReposCreateReleaseRequest { - body, - discussion_category_name, - draft, - name: name.to_owned(), - prerelease, - tag_name: tag_name.to_owned(), - target_commitish, + body: command_args.body, + discussion_category_name: command_args.discussion_category_name, + draft: command_args.draft, + name: command_args.name, + prerelease: command_args.prerelease, + tag_name: command_args.tag_name, + target_commitish: command_args.target_commitish.to_owned(), }; let result = github_client @@ -34,7 +28,7 @@ pub async fn create( .await; match result { - Ok(_) => Ok(repo_info.get_release_url(tag_name)), + Ok(_) => Ok(repo_info.get_release_url(&command_args.target_commitish)), Err(er) => Err(Box::new(er)), } } From 2c814a4428a3165524fda158a2fde74a6e62ff0b Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:46:35 +0400 Subject: [PATCH 18/20] Chore: cargo fmt fixes --- src/cli_in/issue_command.rs | 12 ++--- src/cli_in/set_vars.rs | 2 +- src/cli_out/mod.rs | 2 +- src/cli_parse/handle_cli.rs | 8 ++-- src/cli_parse/handle_commands/handle_repo.rs | 46 ++++++++------------ src/cli_parse/mod.rs | 2 +- src/git_utils/teams.rs | 5 +-- 7 files changed, 31 insertions(+), 46 deletions(-) diff --git a/src/cli_in/issue_command.rs b/src/cli_in/issue_command.rs index d4ebe5c..28b6990 100644 --- a/src/cli_in/issue_command.rs +++ b/src/cli_in/issue_command.rs @@ -33,8 +33,8 @@ pub enum IssueCommand { iss_on_page: i64, }, - /// Get issue by number - Get { + /// Get issue by number + Get { /// Repo owner (optional) #[clap(long, short, default_value = None)] owner: Option, @@ -44,10 +44,10 @@ pub enum IssueCommand { /// Get issue with number #[clap(long, short)] number: i64, - }, + }, - /// Get issue with comment from issues list - GetFromList { + /// Get issue with comment from issues list + GetFromList { /// Repo owner (optional) #[clap(long, short, default_value = None)] owner: Option, @@ -72,7 +72,7 @@ pub enum IssueCommand { /// Results on page (max 100) (optional) #[clap(long, short, default_value = "30", value_parser = clap::value_parser!(i64).range(1..=100))] iss_on_page: i64, - }, + }, /// Create issue Create { diff --git a/src/cli_in/set_vars.rs b/src/cli_in/set_vars.rs index f1b3029..a883ba3 100644 --- a/src/cli_in/set_vars.rs +++ b/src/cli_in/set_vars.rs @@ -128,7 +128,7 @@ impl FromStr for IssuesListStates { } impl Display for IssuesListStates { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self.0 { IssuesListState::Open => write!(f, "open"), IssuesListState::Closed => write!(f, "closed"), diff --git a/src/cli_out/mod.rs b/src/cli_out/mod.rs index 513cfbf..0349e0e 100644 --- a/src/cli_out/mod.rs +++ b/src/cli_out/mod.rs @@ -1,2 +1,2 @@ -pub mod print_in_cli; pub mod fuzzy_select; +pub mod print_in_cli; diff --git a/src/cli_parse/handle_cli.rs b/src/cli_parse/handle_cli.rs index 85cd147..aa33bab 100644 --- a/src/cli_parse/handle_cli.rs +++ b/src/cli_parse/handle_cli.rs @@ -13,22 +13,22 @@ pub async fn handle_cli_command(args: Args, github_client: Client) -> Result<(), match args.command { CliCommand::Issue { subcommand } => { handle_issue_command(github_client, subcommand).await?; - Ok(()) + Ok(()) } CliCommand::Comment { subcommand } => { handle_comment_command(github_client, subcommand).await?; - Ok(()) + Ok(()) } CliCommand::Repo { subcommand } => { handle_repo_command(github_client, subcommand).await?; - Ok(()) + Ok(()) } CliCommand::Release { subcommand } => { handle_release_command(github_client, subcommand).await?; - Ok(()) + Ok(()) } } } diff --git a/src/cli_parse/handle_commands/handle_repo.rs b/src/cli_parse/handle_commands/handle_repo.rs index a54dcf8..e83fd92 100644 --- a/src/cli_parse/handle_commands/handle_repo.rs +++ b/src/cli_parse/handle_commands/handle_repo.rs @@ -9,12 +9,12 @@ use crate::cli_in::set_vars::ReposListUserTypes; use crate::cli_in::set_vars::Visibilities; use crate::cli_out::print_in_cli::print_repos; use crate::cli_out::print_in_cli::print_url; +use crate::cli_parse::entities::CreateRepoArgs; use crate::cli_parse::entities::CreateRepoFromTemplateArgs; use crate::git_utils::repo_info::Repo; use crate::git_utils::repo_info::RepoInfo; use crate::git_utils::repo_info::{RepoName, RepoOwner}; use crate::git_utils::repos; -use crate::cli_parse::entities::CreateRepoArgs; pub async fn handle_repo_command( github_client: Client, @@ -58,11 +58,7 @@ pub async fn handle_repo_command( name, }; - handle_create_for_auth_user( - github_client, - command_args - ) - .await?; + handle_create_for_auth_user(github_client, command_args).await?; Ok(()) } @@ -107,7 +103,7 @@ pub async fn handle_repo_command( handle_create_in_org( github_client, - command_args, + command_args, name, org, team_name, @@ -136,18 +132,18 @@ pub async fn handle_repo_command( private, include_all_branches, } => { - let command_args = CreateRepoFromTemplateArgs { - description, - private, - include_all_branches - }; + let command_args = CreateRepoFromTemplateArgs { + description, + private, + include_all_branches, + }; handle_create_using_template( github_client, owner, name, template_owner, template_name, - command_args + command_args, ) .await?; Ok(()) @@ -172,13 +168,9 @@ pub async fn handle_repo_command( async fn handle_create_for_auth_user( github_client: Client, - command_args: CreateRepoArgs, + command_args: CreateRepoArgs, ) -> Result<(), Box> { - let result = repos::create_for_authenticated_user( - &github_client, - command_args, - ) - .await?; + let result = repos::create_for_authenticated_user(&github_client, command_args).await?; println!("{result}"); Ok(()) @@ -186,7 +178,7 @@ async fn handle_create_for_auth_user( async fn handle_create_in_org( github_client: Client, - command_args: CreateRepoArgs, + command_args: CreateRepoArgs, name: RepoName, org: RepoOwner, team_name: String, @@ -197,7 +189,7 @@ async fn handle_create_in_org( let result = repos::create_in_org( &github_client, repo_info, - command_args, + command_args, &team_name, Some(visibility.0), ) @@ -227,19 +219,15 @@ async fn handle_create_using_template( name: RepoName, template_owner: RepoOwner, template_name: RepoName, - command_args: CreateRepoFromTemplateArgs + command_args: CreateRepoFromTemplateArgs, ) -> Result<(), Box> { let repo_info: RepoInfo = RepoInfo::new(Repo::Input, Some(owner), Some(name))?; let template_info: RepoInfo = RepoInfo::new(Repo::Input, Some(template_owner), Some(template_name))?; - let result = repos::create_using_template( - &github_client, - template_info, - repo_info, - command_args - ) - .await?; + let result = + repos::create_using_template(&github_client, template_info, repo_info, command_args) + .await?; print_url(result, "New repo"); Ok(()) diff --git a/src/cli_parse/mod.rs b/src/cli_parse/mod.rs index 59da17e..08f2cd4 100644 --- a/src/cli_parse/mod.rs +++ b/src/cli_parse/mod.rs @@ -1,3 +1,3 @@ -pub mod handle_cli; pub mod entities; +pub mod handle_cli; mod handle_commands; diff --git a/src/git_utils/teams.rs b/src/git_utils/teams.rs index eedc33e..3fdbdc9 100644 --- a/src/git_utils/teams.rs +++ b/src/git_utils/teams.rs @@ -7,10 +7,7 @@ pub async fn get_id( org: &str, name: &str, ) -> Result> { - let team = github_client - .teams() - .get_by_name(org, name) - .await; + let team = github_client.teams().get_by_name(org, name).await; match team { Ok(t) => Ok(t.body), From ca67a6fa8251fa743d277ae0744d564109b191e5 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:49:50 +0400 Subject: [PATCH 19/20] Chore(readme): update road map --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 6b140b1..c999a51 100644 --- a/Readme.md +++ b/Readme.md @@ -54,7 +54,7 @@ github-cli release --help - [x] Сделать создание комментария в issue/pull request - [x] Сделать получение комментариев для issue/pull request - [x] Сделать получение review комментариев для pull request -- [ ] Сделать редактирование комментария для issue/pull request +- [x] Сделать редактирование комментария для issue/pull request - [ ] Сделать удаление комментария для issue/pull request ### issue From 8750223bdaa7c26d0e107e14740e6e58ee92f2a1 Mon Sep 17 00:00:00 2001 From: aragami3070 Date: Sat, 23 Aug 2025 23:50:01 +0400 Subject: [PATCH 20/20] Feat(cargo): update package version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7bacea6..d999487 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -487,7 +487,7 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "github-cli" -version = "1.13.0" +version = "1.14.0" dependencies = [ "clap", "fzf-wrapped", diff --git a/Cargo.toml b/Cargo.toml index c62f162..cd4f6b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "github-cli" -version = "1.13.0" +version = "1.14.0" edition = "2021" [dependencies]