gitea_sdk/api/issues/comments/
edit.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 EditCommentBuilder {
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    comment: i64,
17
18    /// The content of the comment.
19    #[build_it(skip)]
20    body: String,
21    updated_at: Option<String>,
22}
23
24impl EditCommentBuilder {
25    pub fn new(
26        owner: impl ToString,
27        repo: impl ToString,
28        comment: i64,
29        body: impl ToString,
30    ) -> Self {
31        Self {
32            comment,
33            owner: owner.to_string(),
34            repo: repo.to_string(),
35            body: body.to_string(),
36            updated_at: None,
37        }
38    }
39
40    /// Sends the request to edit a comment on an issue.
41    /// NOTE: This is the only endpoint which returns an option. That's because the Gitea API
42    /// decided - in their infinite wisdom - to sometimes return a 204 No Content status code
43    /// when editing a comment, which means there's no response body to parse.
44    pub async fn send(self, client: &Client) -> Result<Option<Comment>> {
45        let owner = &self.owner;
46        let repo = &self.repo;
47        let comment = self.comment;
48        let req = client
49            .patch(format!("repos/{owner}/{repo}/issues/comments/{comment}"))
50            .json(&self)
51            .build()?;
52        let res = client.make_request(req).await?;
53        if res.status() == 204 {
54            return Ok(None);
55        }
56        client.parse_response(res).await
57    }
58}