use serde::{Deserialize, Serialize};
use crate::users::User;
use crate::{Future, Github};
pub struct ReviewComments {
github: Github,
owner: String,
repo: String,
number: u64,
}
impl ReviewComments {
#[doc(hidden)]
pub fn new<O, R>(github: Github, owner: O, repo: R, number: u64) -> Self
where
O: Into<String>,
R: Into<String>,
{
ReviewComments {
github,
owner: owner.into(),
repo: repo.into(),
number,
}
}
pub fn list(&self) -> Future<Vec<ReviewComment>> {
self.github.get::<Vec<ReviewComment>>(&self.path())
}
pub fn create(&self, review_comment: &ReviewCommentOptions) -> Future<ReviewComment> {
self.github.post(&self.path(), json!(review_comment))
}
fn path(&self) -> String {
format!(
"/repos/{}/{}/pulls/{}/comments",
self.owner, self.repo, self.number
)
}
}
#[derive(Default, Serialize)]
pub struct ReviewCommentOptions {
pub body: String,
pub commit_id: String,
pub path: String,
pub position: usize,
}
#[derive(Debug, Deserialize)]
pub struct ReviewComment {
pub id: u64,
pub url: String,
pub diff_hunk: String,
pub path: String,
pub position: u64,
pub original_position: u64,
pub commit_id: String,
pub original_commit_id: String,
pub user: User,
pub body: String,
pub created_at: String,
pub updated_at: String,
pub html_url: String,
pub pull_request_url: String,
}