Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "github-cli"
version = "1.11.0"
version = "1.12.0"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ github-cli release --help

### test
- [ ] Сделать тесты (maybe in feature)
- [ ] Добавить тесты в github workflow
- [x] Добавить тесты в github workflow

### tui
- [ ] Добавить TUI через ratatui на issues
Expand Down
21 changes: 20 additions & 1 deletion src/cli_in/comment_command.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::git_utils::repo_info::{RepoName, RepoOwner};
use clap::Subcommand;

use crate::cli_in::set_vars::{CommentTarget, Orders, Sorts};
Expand All @@ -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<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
/// Create comment for issue/pull request with number
#[clap(long, short)]
number: i64,
Expand All @@ -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<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
/// Get all comments from issue/pull request with number
#[clap(long, short)]
number: i64,
Expand All @@ -26,14 +39,20 @@ pub enum CommentCommand {

/// Get all comments from issue/pull request
GetAllFromReview {
/// Repo owner (optional)
#[clap(long, short, default_value = None)]
owner: Option<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
/// Get all comments from issue/pull request with number
#[clap(long, short)]
number: i64,
/// Can be only 'created' or 'updated' (optional)
#[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,
},
}
33 changes: 29 additions & 4 deletions src/cli_in/issue_command.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::git_utils::repo_info::{RepoName, RepoOwner};
use clap::Subcommand;

use crate::cli_in::set_vars::{IssuesListStates, States};
Expand All @@ -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<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
/// The user that created the issues (optional)
#[clap(long, short, default_value = "")]
creator: String,
Expand All @@ -28,6 +35,12 @@ pub enum IssueCommand {

/// Create issue
Create {
/// Repo owner (optional)
#[clap(long, short, default_value = None)]
owner: Option<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
/// Issue title
#[clap(long, short)]
title: String,
Expand All @@ -44,15 +57,21 @@ pub enum IssueCommand {

/// Update issue
Update {
/// Repo owner (optional)
#[clap(long, short, default_value = None)]
owner: Option<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
/// 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<String>,
/// Issue body (optional)
#[clap(long, short, default_value = "None")]
body: String,
#[clap(long, short, default_value = None)]
body: Option<String>,
/// A list of comma separated assignee names. Example: `aragami3070,danilasar` (optional)
#[clap(long, short, default_value = None)]
assignees: Option<String>,
Expand All @@ -66,6 +85,12 @@ pub enum IssueCommand {

/// Close issue
Close {
/// Repo owner (optional)
#[clap(long, short, default_value = None)]
owner: Option<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
/// Close issue with number
#[clap(long, short)]
number: i64,
Expand Down
44 changes: 22 additions & 22 deletions src/cli_in/release_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -37,35 +37,35 @@ 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<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
},

/// 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<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
/// Release tag
#[clap(long, short)]
tag: String,
},

/// 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<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
/// Release id
#[clap(long, short)]
id: i64,
Expand Down
45 changes: 35 additions & 10 deletions src/cli_parse/handle_commands/handle_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,55 @@ 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<dyn Error>> {
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(())
}
}
}

async fn handle_create(
github_client: Client,
owner: Option<RepoOwner>,
repo: Option<RepoName>,
number: i64,
body: String,
) -> Result<(), Box<dyn Error>> {
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}");
Expand All @@ -47,10 +62,15 @@ async fn handle_create(

async fn handle_get_all(
github_client: Client,
owner: Option<RepoOwner>,
repo: Option<RepoName>,
number: i64,
target: CommentTarget,
) -> Result<(), Box<dyn Error>> {
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?;

Expand All @@ -77,15 +97,20 @@ async fn handle_get_all(

async fn handle_get_all_from_review(
github_client: Client,
owner: Option<RepoOwner>,
repo: Option<RepoName>,
number: i64,
sort: Sorts,
order: Orders,
) -> Result<(), Box<dyn Error>> {
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(())
}
Loading