hubcaps_ex/
labels.rs

1//! Labels interface
2use serde::{Deserialize, Serialize};
3
4use crate::{Future, Github, Stream};
5
6pub struct Labels {
7    github: Github,
8    owner: String,
9    repo: String,
10}
11
12impl Labels {
13    #[doc(hidden)]
14    pub fn new<O, R>(github: Github, owner: O, repo: R) -> Self
15    where
16        O: Into<String>,
17        R: Into<String>,
18    {
19        Labels {
20            github,
21            owner: owner.into(),
22            repo: repo.into(),
23        }
24    }
25
26    fn path(&self, more: &str) -> String {
27        format!("/repos/{}/{}/labels{}", self.owner, self.repo, more)
28    }
29
30    pub fn create(&self, lab: &LabelOptions) -> Future<Label> {
31        self.github.post(&self.path(""), json!(lab))
32    }
33
34    pub fn update(&self, prevname: &str, lab: &LabelOptions) -> Future<Label> {
35        self.github
36            .patch(&self.path(&format!("/{}", prevname)), json!(lab))
37    }
38
39    pub fn delete(&self, name: &str) -> Future<()> {
40        self.github.delete(&self.path(&format!("/{}", name)))
41    }
42
43    pub fn list(&self) -> Future<Vec<Label>> {
44        self.github.get(&self.path(""))
45    }
46
47    /// provides a stream over all pages of this repo's labels
48    pub fn iter(&self) -> Stream<Label> {
49        self.github.get_stream(&self.path(""))
50    }
51}
52
53// representations
54
55#[derive(Debug, Serialize)]
56pub struct LabelOptions {
57    pub name: String,
58    pub color: String,
59    pub description: String,
60}
61
62impl LabelOptions {
63    pub fn new<N, C, D>(name: N, color: C, description: D) -> LabelOptions
64    where
65        N: Into<String>,
66        C: Into<String>,
67        D: Into<String>,
68    {
69        LabelOptions {
70            name: name.into(),
71            color: color.into(),
72            description: description.into(),
73        }
74    }
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
78pub struct Label {
79    pub url: String,
80    pub name: String,
81    pub color: String,
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub description: Option<String>,
84}