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.14.1"
version = "1.15.0"
edition = "2021"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ github-cli release --help
- [x] Сделать получение комментариев для issue/pull request
- [x] Сделать получение review комментариев для pull request
- [x] Сделать редактирование комментария для issue/pull request
- [ ] Сделать удаление комментария для issue/pull request
- [x] Сделать удаление комментария для issue/pull request

### issue
- [x] Сделать автораспознование гит репозитория
Expand All @@ -68,7 +68,7 @@ github-cli release --help

### pull request
- [ ] Сделать получение всех pull requests
- [ ] Сделать выбор pull request через fzf или аналоги из списка всех pull requests
- [ ] Сделать выбор pull request через fzf из списка всех pull requests
- [ ] Сделать создание pull request
- [ ] Сделать апрув pull request
- [ ] Сделать merge pull request
Expand Down
13 changes: 13 additions & 0 deletions src/cli_in/comment_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@ pub enum CommentCommand {
#[clap(long, short, default_value = "")]
body: String,
},

/// Delete comment for issue/pull request by comment id
Delete {
/// Repo owner (optional)
#[clap(long, short, default_value = None)]
owner: Option<RepoOwner>,
/// Repo name (optional)
#[clap(long, short, default_value = None)]
repo: Option<RepoName>,
/// Delete comment from issue/pull request by id
#[clap(long, short)]
comment_id: i64,
},
}
26 changes: 26 additions & 0 deletions src/cli_parse/handle_commands/handle_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ pub async fn handle_comment_command(
body,
} => {
handle_update(github_client, owner, repo, comment_id, body).await?;
Ok(())
}
CommentCommand::Delete {
owner,
repo,
comment_id,
} => {
handle_delete(github_client, owner, repo, comment_id).await?;

Ok(())
}
Expand Down Expand Up @@ -139,8 +147,26 @@ async fn handle_update(
Some(_) => RepoInfo::new(Repo::Input, owner, repo)?,
None => RepoInfo::new(Repo::Current, None, None)?,
};

let result = comments::update(&github_client, &repo_info, &comment_id, &body).await?;

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

async fn handle_delete(
github_client: Client,
owner: Option<RepoOwner>,
repo: Option<RepoName>,
comment_id: i64,
) -> Result<(), Box<dyn Error>> {
let repo_info = match owner {
Some(_) => RepoInfo::new(Repo::Input, owner, repo)?,
None => RepoInfo::new(Repo::Current, None, None)?,
};

let result = comments::delete(&github_client, &repo_info, &comment_id).await?;

println!("{result}");
Ok(())
}
20 changes: 20 additions & 0 deletions src/git_utils/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,23 @@ pub async fn update(
Err(er) => Err(Box::new(er)),
}
}

pub async fn delete(
github_client: &Client,
repo_info: &RepoInfo,
comment_id: &i64,
) -> Result<String, Box<dyn Error>> {
let comment = github_client
.issues()
.delete_comment(
&repo_info.get_owner(),
&repo_info.get_name(),
*comment_id,
)
.await;

match comment {
Ok(_) => Ok("Comment deleted successed".to_string()),
Err(er) => Err(Box::new(er)),
}
}