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
11 changes: 5 additions & 6 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "github-cli"
version = "1.10.0"
version = "1.11.0"
edition = "2021"

[dependencies]
octorust = "0.10.0"
clap = { version = "4.5.39", features = ["derive"] }
tokio = { version = "1.45.1", features = ["full"] }
rstest = "0.25.0"
rstest = "0.26.1"
paste = "1.0.15"
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ github-cli release --help
### comment
- [x] Сделать создание комментария в issue/pull request
- [x] Сделать получение комментариев для issue/pull request
- [x] Сделать получение review комментариев для pull request
- [ ] Сделать редактирование комментария для issue/pull request
- [ ] Сделать удаление комментария для issue/pull request

Expand Down
15 changes: 14 additions & 1 deletion src/cli_in/comment_command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Subcommand;

use crate::cli_in::set_vars::CommentTarget;
use crate::cli_in::set_vars::{CommentTarget, Orders, Sorts};

#[derive(Subcommand)]
pub enum CommentCommand {
Expand All @@ -23,4 +23,17 @@ pub enum CommentCommand {
#[clap(long, short)]
target: CommentTarget,
},

/// Get all comments from issue/pull request
GetAllFromReview {
/// 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")]
order: Orders,
},
}
31 changes: 24 additions & 7 deletions src/cli_in/set_vars.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::str::FromStr;

use octorust::types::{IssuesListState, Order, ReposListOrgSort, ReposListUserType, State};
use octorust::types::{ReposCreateInOrgRequestVisibility, ReposListOrgType};
use octorust::types::{
IssuesListState, Order, ReposCreateInOrgRequestVisibility, ReposListOrgSort, ReposListOrgType,
ReposListUserType, Sort, State,
};

#[derive(Debug, Clone)]
pub struct Orders(pub Order);
Expand Down Expand Up @@ -139,17 +141,32 @@ impl ToString for IssuesListStates {
#[derive(Debug, Clone)]
pub enum CommentTarget {
Issue,
PullRequest,
PullRequest,
}

impl FromStr for CommentTarget {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"issue" => Ok(CommentTarget::Issue),
"pull-request" => Ok(CommentTarget::PullRequest),
_ => Err("Bad input. Comment target can be only 'issue' or 'pull-request'".to_string()),
}
}
}
}

#[derive(Debug, Clone)]
pub struct Sorts(pub Sort);

impl FromStr for Sorts {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"created" => Ok(Self(Sort::Created)),
"updated" => Ok(Self(Sort::Updated)),
_ => Err("Bad input. Sort can be only 'created' or 'updated'".to_string()),
}
}
}
1 change: 1 addition & 0 deletions src/cli_out/print_in_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn print_issues(list_issues: Vec<IssueSimple>, state: IssuesListStates, numb
println!("╭────────────────────────────────────────────────────────────────────────────────────────────────");
println!("│Issue {}: {};", issue.number, issue.title);
println!("│Body: {}", issue.body);
println!("│Time: {}", issue.timeline_url);
println!("╰────────────────────────────────────────────────────────────────────────────────────────────────");
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/cli_parse/handle_cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::error::Error;

use octorust::{self, Client};

use crate::cli_in::read_cli::Args;
Expand All @@ -7,22 +9,26 @@ use crate::cli_parse::handle_commands::handle_issue::handle_issue_command;
use crate::cli_parse::handle_commands::handle_release::handle_release_command;
use crate::cli_parse::handle_commands::handle_repo::handle_repo_command;

pub async fn handle_cli_command(args: Args, github_client: Client) {
pub async fn handle_cli_command(args: Args, github_client: Client) -> Result<(), Box<dyn Error>> {
match args.command {
CliCommand::Issue { subcommand } => {
handle_issue_command(github_client, subcommand).await;
handle_issue_command(github_client, subcommand).await?;
Ok(())
}

CliCommand::Comment { subcommand } => {
handle_comment_command(github_client, subcommand).await;
handle_comment_command(github_client, subcommand).await?;
Ok(())
}

CliCommand::Repo { subcommand } => {
handle_repo_command(github_client, subcommand).await;
handle_repo_command(github_client, subcommand).await?;
Ok(())
}

CliCommand::Release { subcommand } => {
handle_release_command(github_client, subcommand).await;
handle_release_command(github_client, subcommand).await?;
Ok(())
}
}
}
78 changes: 51 additions & 27 deletions src/cli_parse/handle_commands/handle_comment.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,58 @@
use octorust::{self, Client};
use std::process;
// use std::str::FromStr;
use std::error::Error;

use crate::cli_in::comment_command::CommentCommand;
use crate::cli_in::set_vars::CommentTarget;
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::{RepoName, RepoOwner};

pub async fn handle_comment_command(github_client: Client, subcommand: CommentCommand) {
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;
handle_create(github_client, number, body).await?;
Ok(())
}

CommentCommand::GetAll { number, target } => {
handle_get_all(github_client, number, target).await
handle_get_all(github_client, number, target).await?;
Ok(())
}
};
}

async fn handle_create(github_client: Client, number: i64, body: String) {
let repo_info: RepoInfo = match RepoInfo::new(Repo::Current, None, None) {
Ok(rep) => rep,
Err(message) => {
eprintln!("Error: {message}");
process::exit(1);
CommentCommand::GetAllFromReview {
number,
sort,
order,
} => {
handle_get_all_from_review(github_client, number, sort, order).await?;
Ok(())
}
};
}
}

let result = comments::create(&github_client, &repo_info, &number, &body).await;
async fn handle_create(
github_client: Client,
number: i64,
body: String,
) -> Result<(), Box<dyn Error>> {
let repo_info: RepoInfo = RepoInfo::new(Repo::Current, None, None)?;
let result = comments::create(&github_client, &repo_info, &number, &body).await?;

println!("{result}");
Ok(())
}

async fn handle_get_all(github_client: Client, number: i64, target: CommentTarget) {
let repo_info: RepoInfo = match RepoInfo::new(Repo::Current, None, None) {
Ok(rep) => rep,
Err(message) => {
eprintln!("Error: {message}");
process::exit(1);
}
};
async fn handle_get_all(
github_client: Client,
number: i64,
target: CommentTarget,
) -> Result<(), Box<dyn Error>> {
let repo_info: RepoInfo = RepoInfo::new(Repo::Current, None, None)?;

let result = comments::get_all(&github_client, &repo_info, &number).await;
let result = comments::get_all(&github_client, &repo_info, &number).await?;

print_comments(result);

Expand All @@ -57,11 +65,27 @@ async fn handle_get_all(github_client: Client, number: i64, target: CommentTarge
octorust::types::Sort::Created,
octorust::types::Order::Asc,
)
.await
.await?
}
CommentTarget::Issue => Vec::new(),
};
if !review_comments.is_empty() {
print_review_comments(review_comments);
}
Ok(())
}

async fn handle_get_all_from_review(
github_client: Client,
number: i64,
sort: Sorts,
order: Orders,
) -> Result<(), Box<dyn Error>> {
let repo_info: RepoInfo = 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(())
}
Loading