gitea_sdk/api/issues/comments/
list.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use build_it::Builder;
use serde::Serialize;

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

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

    /// If provided, only comments updated since the provided time are returned.
    since: Option<String>,
    /// If provided, only comments updated before the provided time are returned.
    before: Option<String>,
    /// Page number of results to return (1-based).
    page: Option<i64>,
    /// Page size of results
    limit: Option<i64>,
}

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

    /// If provided, only comments updated since the provided time are returned.
    since: Option<String>,
    /// If provided, only comments updated before the provided time are returned.
    before: Option<String>,
    /// Page number of results to return (1-based).
    page: Option<i64>,
    /// Page size of results
    limit: Option<i64>,
}

impl ListAllCommentsBuilder {
    pub fn new(owner: &str, repo: &str) -> Self {
        Self {
            owner: owner.to_string(),
            repo: repo.to_string(),
            since: None,
            before: None,
            page: None,
            limit: None,
        }
    }

    /// Sends the request to list a repository's comments.
    pub async fn send(&self, client: &Client) -> Result<Vec<Comment>> {
        let owner = &self.owner;
        let repo = &self.repo;
        let req = client
            .get(format!("repos/{owner}/{repo}/issues/comments"))
            .query(self)
            .build()?;
        let res = client.make_request(req).await?;
        client.parse_response(res).await
    }
}

impl ListCommentsBuilder {
    pub fn new(owner: &str, repo: &str, issue: i64) -> Self {
        Self {
            owner: owner.to_string(),
            repo: repo.to_string(),
            issue,
            since: None,
            before: None,
            page: None,
            limit: None,
        }
    }

    /// Sends the request to list an issue's comments.
    pub async fn send(&self, client: &Client) -> Result<Vec<Comment>> {
        let owner = &self.owner;
        let repo = &self.repo;
        let issue = self.issue;
        let req = client
            .get(format!("repos/{owner}/{repo}/issues/{issue}/comments"))
            .query(self)
            .build()?;
        let res = client.make_request(req).await?;
        client.parse_response(res).await
    }
}