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
extern crate serde_json;
use futures::future;
use hyper::client::Connect;
use {Github, Future};
pub struct Labels<C>
where
C: Connect + Clone,
{
github: Github<C>,
owner: String,
repo: String,
}
impl<C: Connect + Clone> Labels<C> {
#[doc(hidden)]
pub fn new<O, R>(github: Github<C>, owner: O, repo: R) -> Self
where
O: Into<String>,
R: Into<String>,
{
Labels {
github: github,
owner: owner.into(),
repo: repo.into(),
}
}
fn path(&self, more: &str) -> String {
format!("/repos/{}/{}/labels{}", self.owner, self.repo, more)
}
pub fn create(&self, lab: &LabelOptions) -> Future<Label> {
self.github.post(&self.path(""), json!(lab))
}
pub fn update(&self, prevname: &str, lab: &LabelOptions) -> Future<Label> {
self.github.patch(
&self.path(&format!("/{}", prevname)),
json!(lab),
)
}
pub fn delete(&self, name: &str) -> Future<()> {
self.github.delete(&self.path(&format!("/{}", name)))
}
pub fn list(&self) -> Future<Vec<Label>> {
self.github.get(&self.path(""))
}
}
#[derive(Debug, Serialize)]
pub struct LabelOptions {
pub name: String,
pub color: String,
}
impl LabelOptions {
pub fn new<N, C>(name: N, color: C) -> LabelOptions
where
N: Into<String>,
C: Into<String>,
{
LabelOptions {
name: name.into(),
color: color.into(),
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Label {
pub url: String,
pub name: String,
pub color: String,
}