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
use self::super::{Github, Result};
pub struct Git<'a> {
github: &'a Github,
owner: String,
repo: String,
}
impl<'a> Git<'a> {
pub fn new<O, R>(github: &'a Github, owner: O, repo: R) -> Self
where O: Into<String>,
R: Into<String>
{
Git {
github: github,
owner: owner.into(),
repo: repo.into(),
}
}
pub fn tree<S>(&self, sha: S, recursive: bool) -> Result<TreeData>
where S: Into<String>
{
self.github
.get::<TreeData>(&format!("/repos/{}/{}/git/trees/{}?recursive={}",
self.owner,
self.repo,
sha.into(),
if recursive { "1" } else { "0" }))
}
pub fn blob<S>(&self, sha: S) -> Result<Blob>
where S: Into<String>
{
self.github
.get::<Blob>(&format!("/repos/{}/{}/git/blobs/{}",
self.owner,
self.repo,
sha.into()))
}
}
#[derive(Debug, Deserialize)]
pub struct TreeData {
pub sha: String,
pub url: String,
pub tree: Vec<GitFile>,
pub truncated: bool,
}
#[derive(Debug, Deserialize)]
pub struct GitFile {
pub path: String,
pub mode: String,
#[serde(rename="type")]
pub content_type: String,
pub size: Option<usize>,
pub sha: String,
pub url: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct Blob {
pub content: String,
pub encoding: String,
pub url: String,
pub sha: String,
pub size: Option<usize>,
}