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 self::super::{Iter, MediaType, Github, Result};
fn identity<T>(x: T) -> T {
x
}
pub struct Branches<'a> {
github: &'a Github,
owner: String,
repo: String,
}
impl<'a> Branches<'a> {
pub fn new<U, R>(github: &'a Github, owner: U, repo: R) -> Self
where U: Into<String>,
R: Into<String>
{
Branches {
github: github,
owner: owner.into(),
repo: repo.into(),
}
}
pub fn list(&self) -> Result<Vec<Branch>> {
self.github
.get_media::<Vec<Branch>>(&format!("/repos/{owner}/{repo}/branches",
owner = self.owner,
repo = self.repo),
MediaType::Preview("loki"))
}
pub fn iter(&self) -> Result<Iter<Vec<Branch>, Branch>> {
self.github
.iter_media(format!("/repos/{owner}/{repo}/branches",
owner = self.owner,
repo = self.repo),
identity,
MediaType::Preview("loki"))
}
pub fn get<B>(&self, branch: B) -> Result<Branch>
where B: Into<String>
{
self.github
.get_media(&format!("/repos/{owner}/{repo}/branches/{branch}",
owner = self.owner,
repo = self.repo,
branch = branch.into()),
MediaType::Preview("loki"))
}
}
#[derive(Debug, Deserialize)]
pub struct Branch {
pub name: String,
pub protected: bool,
pub protection_url: String,
pub protection: Protection,
}
#[derive(Debug, Deserialize)]
pub struct Protection {
pub enabled: bool,
pub required_status_checks: StatusChecks,
}
#[derive(Debug, Deserialize)]
pub struct StatusChecks {
pub enforcement_level: String,
pub contexts: Vec<String>,
}