gitea_sdk/api/issues/comments/
create.rs

1use build_it::Builder;
2use serde::Serialize;
3
4use crate::{error::Result, model::issues::Comment, Client};
5
6#[derive(Debug, Clone, Builder, Serialize)]
7pub struct CreateCommentBuilder {
8    #[serde(skip)]
9    #[build_it(skip)]
10    owner: String,
11    #[serde(skip)]
12    #[build_it(skip)]
13    repo: String,
14    #[serde(skip)]
15    #[build_it(skip)]
16    issue: i64,
17
18    /// The content of the comment.
19    #[build_it(skip)]
20    body: String,
21    updated_at: Option<String>,
22}
23
24impl CreateCommentBuilder {
25    pub fn new(owner: impl ToString, repo: impl ToString, issue: i64, body: impl ToString) -> Self {
26        Self {
27            issue,
28            owner: owner.to_string(),
29            repo: repo.to_string(),
30            body: body.to_string(),
31            updated_at: None,
32        }
33    }
34
35    /// Sends the request to create a comment on an issue.
36    pub async fn send(self, client: &Client) -> Result<Comment> {
37        let owner = &self.owner;
38        let repo = &self.repo;
39        let issue = self.issue;
40        let req = client
41            .post(format!("repos/{owner}/{repo}/issues/{issue}/comments"))
42            .json(&self)
43            .build()?;
44        let res = client.make_request(req).await?;
45        client.parse_response(res).await
46    }
47}