1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use std::sync::Arc;

use serde::{Deserialize, Serialize};

use crate::{
    methods::util,
    model::{commits::comments::CommitComment, user::SimpleUser},
    GithubRestError, Requester,
};

pub type Commits = Vec<Commit>;

/// <https://docs.github.com/en/rest/commits/commits#get-a-commit=>
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Commit {
    pub url: String,
    pub sha: String,
    pub node_id: String,
    pub html_url: String,
    pub comments_url: String,
    pub commit: nested::CommitObject,
    pub author: SimpleUser,
    pub committer: SimpleUser,
    pub parents: Vec<nested::Parent>,
}

impl Commit {
    pub async fn add_comment_arc(
        &self,
        client: Arc<&impl Requester>,
        body: String,
        path: Option<String>,
        position: Option<String>,
    ) -> Result<CommitComment, GithubRestError> {
        self.add_comment(*client, body, path, position).await
    }
    /// Adds a comment to the current instance.
    pub async fn add_comment(
        &self,
        client: &impl Requester,
        body: String,
        path: Option<String>,
        position: Option<String>,
    ) -> Result<CommitComment, GithubRestError> {
        util::helper_for_helper_for_helper(client, self.html_url.clone(), self.sha.clone(), body, path, position).await
    }
}

pub mod nested {
    use crate::model::user::GitUser;
    use serde::{Deserialize, Serialize};

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct Parent {
        pub sha: String,
        pub url: String,
        pub html_url: String,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct CommitObject {
        pub url: String,
        pub author: Option<GitUser>,
        pub committer: Option<GitUser>,
        pub message: String,
        pub comment_count: i64,
        pub tree: Tree,
        pub verification: Verification,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct Tree {
        pub sha: String,
        pub url: String,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct Verification {
        pub verified: bool,
        pub reason: String,
        pub signature: Option<String>,
        pub payload: Option<String>,
    }
}