summaryrefslogtreecommitdiff
path: root/src/api/repos/branches.rs
blob: d2637b43964ee383dcda8ddba751c301ae6b7cf4 (plain)
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
use super::*;

#[derive(serde::Serialize)]
pub struct ListBranchesBuilder<'octo, 'r> {
    #[serde(skip)]
    handler: &'r RepoHandler<'octo>,
    #[serde(skip_serializing_if = "Option::is_none")]
    protected: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    per_page: Option<u8>,
    #[serde(skip_serializing_if = "Option::is_none")]
    page: Option<u32>,
}

impl<'octo, 'r> ListBranchesBuilder<'octo, 'r> {
    pub fn new(handler: &'r RepoHandler<'octo>) -> Self {
        Self {
            handler,
            protected: None,
            per_page: None,
            page: None,
        }
    }

    /// Setting to true returns only protected branches. When set to false, only
    /// unprotected branches are returned. Omitting this parameter returns all
    /// branches.
    pub fn protected(mut self, protected: impl Into<bool>) -> Self {
        self.protected = Some(protected.into());
        self
    }

    /// Results per page (max 100).
    pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
        self.per_page = Some(per_page.into());
        self
    }

    /// Page number of the results to fetch.
    pub fn page(mut self, page: impl Into<u32>) -> Self {
        self.page = Some(page.into());
        self
    }

    /// Sends the actual request.
    pub async fn send(self) -> Result<crate::Page<models::repos::Branch>> {
        let route = format!("/{}/branches", self.handler.repo);
        self.handler.crab.get(route, Some(&self)).await
    }
}