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>,
}