gitea_sdk/api/issues/comments/
create.rs

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
use build_it::Builder;
use serde::Serialize;

use crate::{error::Result, model::issues::Comment, Client};

#[derive(Debug, Clone, Builder, Serialize)]
pub struct CreateCommentBuilder {
    #[serde(skip)]
    #[build_it(skip)]
    owner: String,
    #[serde(skip)]
    #[build_it(skip)]
    repo: String,
    #[serde(skip)]
    #[build_it(skip)]
    issue: i64,

    /// The content of the comment.
    #[build_it(skip)]
    body: String,
    updated_at: Option<String>,
}

impl CreateCommentBuilder {
    pub fn new(owner: impl ToString, repo: impl ToString, issue: i64, body: impl ToString) -> Self {
        Self {
            issue,
            owner: owner.to_string(),
            repo: repo.to_string(),
            body: body.to_string(),
            updated_at: None,
        }
    }

    /// Sends the request to create a comment on an issue.
    pub async fn send(self, client: &Client) -> Result<Comment> {
        let owner = &self.owner;
        let repo = &self.repo;
        let issue = self.issue;
        let req = client
            .post(format!("repos/{owner}/{repo}/issues/{issue}/comments"))
            .json(&self)
            .build()?;
        let res = client.make_request(req).await?;
        client.parse_response(res).await
    }
}