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
extern crate serde_json;
use self::super::{Github, Result};
use rep::{Deployment, DeploymentOptions, DeploymentListOptions, DeploymentStatus,
DeploymentStatusOptions};
pub struct Deployments<'a> {
github: &'a Github<'a>,
owner: String,
repo: String,
}
pub struct DeploymentStatuses<'a> {
github: &'a Github<'a>,
owner: String,
repo: String,
id: u64,
}
impl<'a> DeploymentStatuses<'a> {
pub fn new<O, R>(github: &'a Github<'a>, owner: O, repo: R, id: u64) -> DeploymentStatuses<'a>
where O: Into<String>,
R: Into<String>
{
DeploymentStatuses {
github: github,
owner: owner.into(),
repo: repo.into(),
id: id,
}
}
fn path(&self, more: &str) -> String {
format!("/repos/{}/{}/deployments/{}/statuses{}",
self.owner,
self.repo,
self.id,
more)
}
pub fn list(&self) -> Result<Vec<DeploymentStatus>> {
self.github.get::<Vec<DeploymentStatus>>(&self.path(""))
}
pub fn create(&self, status: &DeploymentStatusOptions) -> Result<DeploymentStatus> {
let data = try!(serde_json::to_string(&status));
self.github.post::<DeploymentStatus>(&self.path(""), &data.as_bytes())
}
}
impl<'a> Deployments<'a> {
pub fn new<O, R>(github: &'a Github<'a>, owner: O, repo: R) -> Deployments<'a>
where O: Into<String>,
R: Into<String>
{
Deployments {
github: github,
owner: owner.into(),
repo: repo.into(),
}
}
fn path(&self, more: &str) -> String {
format!("/repos/{}/{}/deployments{}", self.owner, self.repo, more)
}
pub fn list(&self, opts: &DeploymentListOptions) -> Result<Vec<Deployment>> {
let mut uri = vec![self.path("")];
if let Some(query) = opts.serialize() {
uri.push(query);
}
self.github.get::<Vec<Deployment>>(&uri.join("?"))
}
pub fn create(&self, dep: &DeploymentOptions) -> Result<Deployment> {
let data = try!(serde_json::to_string(&dep));
self.github.post::<Deployment>(&self.path(""), data.as_bytes())
}
pub fn statuses(&self, id: u64) -> DeploymentStatuses {
DeploymentStatuses::new(self.github, self.owner.as_str(), self.repo.as_str(), id)
}
}