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
use crate::{
    builders::{
        builder, builder_nested_string_setters, builder_nested_string_setters_required, builder_string_setters, Builder,
    },
    methods::{comment_on_commit, CommitCommentBody},
    model::commits::comments::CommitComment,
    GithubRestError, Requester,
};
use async_trait::async_trait;

builder!(
    /// * tags repos
    /// * post `/repos/{owner}/{repo}/commits/{commit_sha}/comments`
    /// * docs <https://docs.github.com/rest/reference/repos#create-a-commit-comment>
    ///
    /// Create a commit comment
    /// Create a comment for a commit using its `:commit_sha`.
    ///
    /// This endpoint triggers [notifications](https://docs.github.com/en/github/managing-subscriptions-and-notifications-on-github/about-notifications). Creating content too quickly using this endpoint may result in secondary rate limiting. See "[Secondary rate limits](https://docs.github.com/rest/overview/resources-in-the-rest-api#secondary-rate-limits)" and "[Dealing with secondary rate limits](https://docs.github.com/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits)" for details.
    CommitCommentBuilder {
        owner: String,
        repo: String,
        sha: String,
        options: CommitCommentBody
    }
);

builder_string_setters!(CommitCommentBuilder { owner, repo, sha });
builder_nested_string_setters!(CommitCommentBuilder {
    options {
        path,
        position,
        line
    }
});

builder_nested_string_setters_required!(CommitCommentBuilder {
    options {
        body
    }
});

#[async_trait]
impl Builder for CommitCommentBuilder {
    type Response = CommitComment;

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

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

    #[tokio::test]
    async fn test_comment_on_commit() {
        let comment = CommitCommentBuilder::new()
            .owner("octocat-rs")
            .repo("octocat-rs")
            .sha("04235f407fbe0cde62b36335965ca48ae099da9f")
            .body("Testing, ignore");

        // You'll need to add your auth to get this to pass
        let a = comment.execute(&util::github_auth()).await.unwrap();

        dbg!(a);
    }
}