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
use crate::{
    builders::{builder, builder_setters, builder_string_setters, Builder},
    methods::react_to_commit_comment,
    model::reactions::{CommitCommentReactionCreated, Reaction},
    GithubRestError, Requester,
};
use async_trait::async_trait;

builder!(
    /// * tags reactions
    /// * post `/repos/{owner}/{repo}/comments/{comment_id}/reactions`
    /// * docs <https://docs.github.com/rest/reference/reactions#create-reaction-for-a-commit-comment>
    ///
    /// Create reaction for a commit comment
    /// Create a reaction to a [commit comment](https://docs.github.com/rest/reference/repos#comments). A response with an HTTP `200` status means that you already added the reaction type to this commit comment.
    CommentReactionBuilder {
        owner: String,
        repo: String,
        comment_id: i64,
        reaction: Reaction
    }
);

builder_string_setters!(CommentReactionBuilder { owner, repo });
builder_setters!(CommentReactionBuilder {
    comment_id: i64,
    reaction: Reaction
});

#[async_trait]
impl Builder for CommentReactionBuilder {
    type Response = CommitCommentReactionCreated;

    async fn execute<T>(self, client: &T) -> Result<Self::Response, GithubRestError>
    where
        T: Requester,
    {
        react_to_commit_comment(client, self.owner, self.repo, self.comment_id, self.reaction).await
    }
}

#[cfg(all(feature = "builders", feature = "client"))]
#[cfg(test)]
mod tests {
    use crate::{
        builders::{Builder, CommentReactionBuilder},
        methods::util,
        model::reactions::Reaction,
    };

    #[tokio::test]
    async fn test_react_to_commit_comment() {
        let res = CommentReactionBuilder::new()
            .owner("octocat-rs")
            .repo("octocat-rs")
            .comment_id(62802084)
            .reaction(Reaction::Rocket)
            .execute(&util::github_auth())
            .await;

        dbg!(res.unwrap());
    }
}