hubcaps_ex/
review_comments.rs

1//! Review comments interface
2use serde::{Deserialize, Serialize};
3
4use crate::users::User;
5use crate::{Future, Github};
6
7/// A structure for interfacing with a review comments
8pub struct ReviewComments {
9    github: Github,
10    owner: String,
11    repo: String,
12    number: u64,
13}
14
15impl ReviewComments {
16    #[doc(hidden)]
17    pub fn new<O, R>(github: Github, owner: O, repo: R, number: u64) -> Self
18    where
19        O: Into<String>,
20        R: Into<String>,
21    {
22        ReviewComments {
23            github,
24            owner: owner.into(),
25            repo: repo.into(),
26            number,
27        }
28    }
29
30    /// list review comments
31    pub fn list(&self) -> Future<Vec<ReviewComment>> {
32        self.github.get::<Vec<ReviewComment>>(&self.path())
33    }
34
35    /// Create new review comment
36    pub fn create(&self, review_comment: &ReviewCommentOptions) -> Future<ReviewComment> {
37        self.github.post(&self.path(), json!(review_comment))
38    }
39
40    fn path(&self) -> String {
41        format!(
42            "/repos/{}/{}/pulls/{}/comments",
43            self.owner, self.repo, self.number
44        )
45    }
46}
47
48// representations (todo: replace with derive_builder)
49
50#[derive(Default, Serialize)]
51pub struct ReviewCommentOptions {
52    pub body: String,
53    pub commit_id: String,
54    pub path: String,
55    pub position: usize,
56}
57
58#[derive(Debug, Deserialize)]
59pub struct ReviewComment {
60    pub id: u64,
61    pub url: String,
62    pub diff_hunk: String,
63    pub path: String,
64    pub position: u64,
65    pub original_position: u64,
66    pub commit_id: String,
67    pub original_commit_id: String,
68    pub user: User,
69    pub body: String,
70    pub created_at: String,
71    pub updated_at: String,
72    pub html_url: String,
73    pub pull_request_url: String,
74}