diff --git a/Cargo.lock b/Cargo.lock index a87c0fb..7ba21ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -412,7 +412,7 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "github-cli" -version = "1.11.0" +version = "1.12.0" dependencies = [ "clap", "octorust", diff --git a/Cargo.toml b/Cargo.toml index d8abc04..c43ff3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "github-cli" -version = "1.11.0" +version = "1.12.0" edition = "2021" [dependencies] diff --git a/Readme.md b/Readme.md index 85210a9..68c7774 100644 --- a/Readme.md +++ b/Readme.md @@ -87,7 +87,7 @@ github-cli release --help ### test - [ ] Сделать тесты (maybe in feature) -- [ ] Добавить тесты в github workflow +- [x] Добавить тесты в github workflow ### tui - [ ] Добавить TUI через ratatui на issues diff --git a/src/cli_in/comment_command.rs b/src/cli_in/comment_command.rs index 051a56a..202d863 100644 --- a/src/cli_in/comment_command.rs +++ b/src/cli_in/comment_command.rs @@ -1,3 +1,4 @@ +use crate::git_utils::repo_info::{RepoName, RepoOwner}; use clap::Subcommand; use crate::cli_in::set_vars::{CommentTarget, Orders, Sorts}; @@ -6,6 +7,12 @@ use crate::cli_in::set_vars::{CommentTarget, Orders, Sorts}; pub enum CommentCommand { /// Create new comment for issue/pull request Create { + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, /// Create comment for issue/pull request with number #[clap(long, short)] number: i64, @@ -16,6 +23,12 @@ pub enum CommentCommand { /// Get all comments from issue/pull request GetAll { + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, /// Get all comments from issue/pull request with number #[clap(long, short)] number: i64, @@ -26,6 +39,12 @@ pub enum CommentCommand { /// Get all comments from issue/pull request GetAllFromReview { + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, /// Get all comments from issue/pull request with number #[clap(long, short)] number: i64, @@ -33,7 +52,7 @@ pub enum CommentCommand { #[clap(long, short, default_value = "created")] sort: Sorts, /// Can be only 'asc' or 'desc' (optional) - #[clap(long, short, default_value = "desc")] + #[clap(long, default_value = "desc")] order: Orders, }, } diff --git a/src/cli_in/issue_command.rs b/src/cli_in/issue_command.rs index a06a98e..5338497 100644 --- a/src/cli_in/issue_command.rs +++ b/src/cli_in/issue_command.rs @@ -1,3 +1,4 @@ +use crate::git_utils::repo_info::{RepoName, RepoOwner}; use clap::Subcommand; use crate::cli_in::set_vars::{IssuesListStates, States}; @@ -6,6 +7,12 @@ use crate::cli_in::set_vars::{IssuesListStates, States}; pub enum IssueCommand { /// Get list of issues List { + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, /// The user that created the issues (optional) #[clap(long, short, default_value = "")] creator: String, @@ -28,6 +35,12 @@ pub enum IssueCommand { /// Create issue Create { + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, /// Issue title #[clap(long, short)] title: String, @@ -44,15 +57,21 @@ pub enum IssueCommand { /// Update issue Update { + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, /// Update issue with number #[clap(long, short)] number: i64, /// Issue title - #[clap(long, short, default_value = "None")] - title: String, + #[clap(long, short, default_value = None)] + title: Option, /// Issue body (optional) - #[clap(long, short, default_value = "None")] - body: String, + #[clap(long, short, default_value = None)] + body: Option, /// A list of comma separated assignee names. Example: `aragami3070,danilasar` (optional) #[clap(long, short, default_value = None)] assignees: Option, @@ -66,6 +85,12 @@ pub enum IssueCommand { /// Close issue Close { + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, /// Close issue with number #[clap(long, short)] number: i64, diff --git a/src/cli_in/release_command.rs b/src/cli_in/release_command.rs index 8ba1c02..641d63d 100644 --- a/src/cli_in/release_command.rs +++ b/src/cli_in/release_command.rs @@ -6,17 +6,17 @@ use crate::git_utils::repo_info::{RepoName, RepoOwner}; pub enum ReleaseCommand { /// Create new release Create { - /// Repo owner + /// Repo owner (optional) #[clap(long, short)] owner: RepoOwner, - /// Repo name + /// Repo name (optional) #[clap(long, short)] repo: RepoName, /// Tag name #[clap(long)] tag_name: String, - /// Target commit hash (only long variant of commit hash) - #[clap(long)] + /// Target commit hash (only long variant of commit hash) (optional) + #[clap(long, default_value = "")] target_commitish: String, /// Release name #[clap(long, short)] @@ -37,22 +37,22 @@ pub enum ReleaseCommand { /// Get latest release GetLatest { - /// Repo owner - #[clap(long, short)] - owner: RepoOwner, - /// Repo name - #[clap(long, short)] - repo: RepoName, + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, }, /// Get release by tag GetByTag { - /// Repo owner - #[clap(long, short)] - owner: RepoOwner, - /// Repo name - #[clap(long, short)] - repo: RepoName, + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, /// Release tag #[clap(long, short)] tag: String, @@ -60,12 +60,12 @@ pub enum ReleaseCommand { /// Get release by id GetById { - /// Repo owner - #[clap(long, short)] - owner: RepoOwner, - /// Repo name - #[clap(long, short)] - repo: RepoName, + /// Repo owner (optional) + #[clap(long, short, default_value = None)] + owner: Option, + /// Repo name (optional) + #[clap(long, short, default_value = None)] + repo: Option, /// Release id #[clap(long, short)] id: i64, diff --git a/src/cli_parse/handle_commands/handle_comment.rs b/src/cli_parse/handle_commands/handle_comment.rs index c76e1f2..5e7a311 100644 --- a/src/cli_parse/handle_commands/handle_comment.rs +++ b/src/cli_parse/handle_commands/handle_comment.rs @@ -5,29 +5,39 @@ use crate::cli_in::comment_command::CommentCommand; use crate::cli_in::set_vars::{CommentTarget, Orders, Sorts}; use crate::cli_out::print_in_cli::{print_comments, print_review_comments}; use crate::git_utils::comments; -use crate::git_utils::repo_info::{Repo, RepoInfo}; +use crate::git_utils::repo_info::{Repo, RepoInfo, RepoName, RepoOwner}; pub async fn handle_comment_command( github_client: Client, subcommand: CommentCommand, ) -> Result<(), Box> { match subcommand { - CommentCommand::Create { number, body } => { - handle_create(github_client, number, body).await?; + CommentCommand::Create { + owner, + repo, + number, + body, + } => { + handle_create(github_client, owner, repo, number, body).await?; Ok(()) } - CommentCommand::GetAll { number, target } => { - handle_get_all(github_client, number, target).await?; + CommentCommand::GetAll { + owner, + repo, + number, target } => { + handle_get_all(github_client, owner, repo, number, target).await?; Ok(()) } CommentCommand::GetAllFromReview { + owner, + repo, number, sort, order, } => { - handle_get_all_from_review(github_client, number, sort, order).await?; + handle_get_all_from_review(github_client, owner, repo, number, sort, order).await?; Ok(()) } } @@ -35,10 +45,15 @@ pub async fn handle_comment_command( async fn handle_create( github_client: Client, + owner: Option, + repo: Option, number: i64, body: String, ) -> Result<(), Box> { - let repo_info: RepoInfo = RepoInfo::new(Repo::Current, None, None)?; + let repo_info = match owner { + Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, + None => RepoInfo::new(Repo::Current, None, None)?, + }; let result = comments::create(&github_client, &repo_info, &number, &body).await?; println!("{result}"); @@ -47,10 +62,15 @@ async fn handle_create( async fn handle_get_all( github_client: Client, + owner: Option, + repo: Option, number: i64, target: CommentTarget, ) -> Result<(), Box> { - let repo_info: RepoInfo = RepoInfo::new(Repo::Current, None, None)?; + let repo_info = match owner { + Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, + None => RepoInfo::new(Repo::Current, None, None)?, + }; let result = comments::get_all(&github_client, &repo_info, &number).await?; @@ -77,15 +97,20 @@ async fn handle_get_all( async fn handle_get_all_from_review( github_client: Client, + owner: Option, + repo: Option, number: i64, sort: Sorts, order: Orders, ) -> Result<(), Box> { - let repo_info: RepoInfo = RepoInfo::new(Repo::Current, None, None)?; + let repo_info = match owner { + Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, + None => RepoInfo::new(Repo::Current, None, None)?, + }; let result = comments::get_all_from_review(&github_client, &repo_info, &number, sort.0, order.0).await?; print_review_comments(result); - Ok(()) + Ok(()) } diff --git a/src/cli_parse/handle_commands/handle_issue.rs b/src/cli_parse/handle_commands/handle_issue.rs index b6a199f..bcbc8ad 100644 --- a/src/cli_parse/handle_commands/handle_issue.rs +++ b/src/cli_parse/handle_commands/handle_issue.rs @@ -8,6 +8,7 @@ use crate::cli_out::print_in_cli::print_issues; use crate::git_utils::issues; use crate::git_utils::repo_info::Repo; use crate::git_utils::repo_info::RepoInfo; +use crate::git_utils::repo_info::{RepoName, RepoOwner}; pub async fn handle_issue_command( github_client: Client, @@ -15,6 +16,8 @@ pub async fn handle_issue_command( ) -> Result<(), Box> { match subcommand { IssueCommand::List { + owner, + repo, creator, assignee, state, @@ -24,6 +27,8 @@ pub async fn handle_issue_command( } => { handle_list( github_client, + owner, + repo, creator, assignee, state, @@ -36,21 +41,30 @@ pub async fn handle_issue_command( } IssueCommand::Create { + owner, + repo, title, body, assignees, labels, } => { - handle_create(github_client, title, body, assignees, labels).await?; + handle_create(github_client, owner, repo, title, body, assignees, labels).await?; Ok(()) } - IssueCommand::Close { number, comment } => { - handle_close(github_client, number, comment).await?; + IssueCommand::Close { + owner, + repo, + number, + comment, + } => { + handle_close(github_client, owner, repo, number, comment).await?; Ok(()) } IssueCommand::Update { + owner, + repo, number, title, body, @@ -58,7 +72,18 @@ pub async fn handle_issue_command( state, labels, } => { - handle_update(github_client, title, body, number, labels, assignees, state).await?; + handle_update( + github_client, + owner, + repo, + title, + body, + number, + labels, + assignees, + state, + ) + .await?; Ok(()) } } @@ -66,6 +91,8 @@ pub async fn handle_issue_command( async fn handle_list( github_client: Client, + owner: Option, + repo: Option, creator: String, assignee: String, state: IssuesListStates, @@ -73,7 +100,10 @@ async fn handle_list( numb_of_page: i64, iss_on_page: i64, ) -> Result<(), Box> { - let repo_info: RepoInfo = RepoInfo::new(Repo::Current, None, None)?; + 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, @@ -93,12 +123,17 @@ async fn handle_list( async fn handle_create( github_client: Client, + owner: Option, + repo: Option, title: String, body: String, assignees: String, labels: String, ) -> Result<(), Box> { - let repo_info: RepoInfo = RepoInfo::new(Repo::Current, None, None)?; + let repo_info = match owner { + Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, + None => RepoInfo::new(Repo::Current, None, None)?, + }; let labels_list: Vec = labels.split(",").map(|s| s.to_string()).collect(); let assignees_list: Vec = assignees.split(",").map(|s| s.to_string()).collect(); @@ -119,10 +154,15 @@ async fn handle_create( async fn handle_close( github_client: Client, + owner: Option, + repo: Option, number: i64, comment: String, ) -> Result<(), Box> { - let repo_info: RepoInfo = RepoInfo::new(Repo::Current, None, None)?; + let repo_info = match owner { + Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, + None => RepoInfo::new(Repo::Current, None, None)?, + }; let result = issues::close(&github_client, repo_info, &number, &comment).await?; @@ -132,14 +172,19 @@ async fn handle_close( async fn handle_update( github_client: Client, - title: String, - body: String, + owner: Option, + repo: Option, + title: Option, + body: Option, number: i64, labels: Option, assignees: Option, state: States, ) -> Result<(), Box> { - let repo_info: RepoInfo = RepoInfo::new(Repo::Current, None, None)?; + let repo_info = match owner { + Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, + None => RepoInfo::new(Repo::Current, None, None)?, + }; let labels_list: Vec = match labels { Some(l) => l.split(",").map(|s| s.to_string()).collect(), @@ -154,8 +199,8 @@ async fn handle_update( &github_client, repo_info, &number, - Some(title), - Some(body), + title, + body, &assignees_list, &labels_list, &state.0, diff --git a/src/cli_parse/handle_commands/handle_release.rs b/src/cli_parse/handle_commands/handle_release.rs index 8467fc3..a62a598 100644 --- a/src/cli_parse/handle_commands/handle_release.rs +++ b/src/cli_parse/handle_commands/handle_release.rs @@ -92,10 +92,13 @@ async fn handle_create( async fn handle_get_latest( github_client: Client, - owner: RepoOwner, - repo: RepoName, + owner: Option, + repo: Option, ) -> Result<(), Box> { - let repo_info: RepoInfo = RepoInfo::new(Repo::Input, Some(owner), Some(repo))?; + let repo_info = match owner { + Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, + None => RepoInfo::new(Repo::Current, None, None)?, + }; let result = releases::get_latest(&github_client, repo_info).await?; @@ -105,11 +108,14 @@ async fn handle_get_latest( async fn handle_get_by_tag( github_client: Client, - owner: RepoOwner, - repo: RepoName, + owner: Option, + repo: Option, tag: String, ) -> Result<(), Box> { - let repo_info: RepoInfo = RepoInfo::new(Repo::Input, Some(owner), Some(repo))?; + let repo_info = match owner { + Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, + None => RepoInfo::new(Repo::Current, None, None)?, + }; let result = releases::get_by_tag(&github_client, repo_info, tag).await?; @@ -119,11 +125,14 @@ async fn handle_get_by_tag( async fn handle_get_by_id( github_client: Client, - owner: RepoOwner, - repo: RepoName, + owner: Option, + repo: Option, id: i64, ) -> Result<(), Box> { - let repo_info: RepoInfo = RepoInfo::new(Repo::Input, Some(owner), Some(repo))?; + let repo_info = match owner { + Some(_) => RepoInfo::new(Repo::Input, owner, repo)?, + None => RepoInfo::new(Repo::Current, None, None)?, + }; let result = releases::get_by_id(&github_client, repo_info, id).await?; diff --git a/src/git_utils/issues.rs b/src/git_utils/issues.rs index 611f3bc..30cc28a 100644 --- a/src/git_utils/issues.rs +++ b/src/git_utils/issues.rs @@ -105,7 +105,10 @@ fn get_update_request( labels: Option<&Vec>, state: &State, ) -> IssuesUpdateRequest { - let new_title = title.map(|t| TitleOneOf::String(t.to_string())); + let new_title = match title { + Some(t) => Some(TitleOneOf::String(t.to_string())), + None => None + }; let new_labels = match labels { Some(l) => l