From 0da013b9079646bb70b20a427336638f0f511e00 Mon Sep 17 00:00:00 2001 From: Richard Fortescue-Webb Date: Sat, 28 May 2016 23:18:11 +0100 Subject: [PATCH 1/5] Add support for creating repositories --- src/rep.rs.in | 61 +++++++++++++++++++++++++++++++++++++++++++++ src/repositories.rs | 10 +++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/rep.rs.in b/src/rep.rs.in index 52b4c89f..c290b205 100644 --- a/src/rep.rs.in +++ b/src/rep.rs.in @@ -450,6 +450,67 @@ impl Repo { } } + +#[derive(Debug, Serialize)] +pub struct RepoOptions { + pub name: String, + #[serde(skip_serializing_if="Option::is_none")] + pub description: Option, + #[serde(skip_serializing_if="Option::is_none")] + pub homepage: Option, + #[serde(skip_serializing_if="Option::is_none")] + pub private: Option, + #[serde(skip_serializing_if="Option::is_none")] + pub has_issues: Option, + #[serde(skip_serializing_if="Option::is_none")] + pub has_wiki: Option, + #[serde(skip_serializing_if="Option::is_none")] + pub has_downloads: Option, + #[serde(skip_serializing_if="Option::is_none")] + pub team_id: Option, + #[serde(skip_serializing_if="Option::is_none")] + pub auto_init: Option, + #[serde(skip_serializing_if="Option::is_none")] + pub gitignore_template: Option, + #[serde(skip_serializing_if="Option::is_none")] + pub license_template: Option, +} + +impl RepoOptions { + pub fn new(name: N, + description: Option, + homepage: Option, + private: Option, + has_issues: Option, + has_wiki: Option, + has_downloads: Option, + team_id: Option, + auto_init: Option, + gitignore_template: Option, + license_template: Option) + -> RepoOptions + where N: Into, + D: Into, + H: Into, + GI: Into, + L: Into + { + RepoOptions { + name: name.into(), + description: description.map(|h| h.into()), + homepage: homepage.map(|h| h.into()), + private: private, + has_issues: has_issues, + has_wiki: has_wiki, + has_downloads: has_downloads, + team_id: team_id, + auto_init: auto_init, + gitignore_template: gitignore_template.map(|gi| gi.into()), + license_template: license_template.map(|l| l.into()), + } + } +} + #[derive(Debug, Deserialize)] pub struct RepoDetails { pub id: u64, diff --git a/src/repositories.rs b/src/repositories.rs index 85a56e13..f95f13f5 100644 --- a/src/repositories.rs +++ b/src/repositories.rs @@ -1,4 +1,5 @@ //! Repository interface +extern crate serde_json; use self::super::{Github, Result}; use deployments::Deployments; @@ -7,7 +8,7 @@ use issues::{IssueRef, Issues}; use labels::Labels; use pulls::PullRequests; use releases::Releases; -use rep::{Repo, RepoListOptions, UserRepoListOptions, OrganizationRepoListOptions}; +use rep::{Repo, RepoOptions, RepoListOptions, UserRepoListOptions, OrganizationRepoListOptions}; use statuses::Statuses; use std::fmt; @@ -136,6 +137,13 @@ impl<'a> Repositories<'a> { format!("/user/repos{}", more) } + /// Create a new repository + /// https://developer.github.com/v3/repos/#create + pub fn create(&self, repo: &RepoOptions) -> Result { + let data = try!(serde_json::to_string(&repo)); + self.github.post::(&self.path(""), data.as_bytes()) + } + /// list the authenticated users repositories /// https://developer.github.com/v3/repos/#list-your-repositories pub fn list(&self, options: &RepoListOptions) -> Result> { From 2e3a34b60bfb8785fac5acedc466ee4b2e34fa24 Mon Sep 17 00:00:00 2001 From: Richard Fortescue-Webb Date: Sun, 29 May 2016 14:25:58 +0100 Subject: [PATCH 2/5] Add private repo field to the Repo struct --- src/rep.rs.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rep.rs.in b/src/rep.rs.in index c290b205..65f47d59 100644 --- a/src/rep.rs.in +++ b/src/rep.rs.in @@ -374,7 +374,7 @@ pub struct Repo { pub name: String, pub full_name: String, pub description: String, - // private (keyword) + pub private: bool, pub fork: bool, pub url: String, pub html_url: String, From 20d589e31975c7da923e9c8a07af62ae395f9fcd Mon Sep 17 00:00:00 2001 From: Richard Fortescue-Webb Date: Sun, 29 May 2016 14:26:24 +0100 Subject: [PATCH 3/5] Add a Builder for RepoOptions --- src/rep.rs.in | 127 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 116 insertions(+), 11 deletions(-) diff --git a/src/rep.rs.in b/src/rep.rs.in index 65f47d59..f462fae4 100644 --- a/src/rep.rs.in +++ b/src/rep.rs.in @@ -476,19 +476,120 @@ pub struct RepoOptions { pub license_template: Option, } +#[derive(Default)] +pub struct RepoOptionsBuilder { + name: String, + description: Option, + homepage: Option, + private: Option, + has_issues: Option, + has_wiki: Option, + has_downloads: Option, + team_id: Option, + auto_init: Option, + gitignore_template: Option, + license_template: Option, +} + +impl RepoOptionsBuilder { + pub fn new(name: N) -> RepoOptionsBuilder + where N: Into + { + RepoOptionsBuilder { name: name.into(), ..Default::default() } + } + + pub fn description(&mut self, description: D) -> &mut RepoOptionsBuilder + where D: Into + { + self.description = Some(description.into()); + self + } + + pub fn homepage(&mut self, homepage: H) -> &mut RepoOptionsBuilder + where H: Into + { + self.homepage = Some(homepage.into()); + self + } + + pub fn private(&mut self, private: bool) -> &mut RepoOptionsBuilder + { + self.private = Some(private); + self + } + + pub fn has_issues(&mut self, has_issues: bool) -> &mut RepoOptionsBuilder + { + self.has_issues = Some(has_issues); + self + } + + pub fn has_wiki(&mut self, has_wiki: bool) -> &mut RepoOptionsBuilder + { + self.has_wiki = Some(has_wiki); + self + } + + pub fn has_downloads(&mut self, has_downloads: bool) -> &mut RepoOptionsBuilder + { + self.has_downloads = Some(has_downloads); + self + } + + pub fn team_id(&mut self, team_id: i32) -> &mut RepoOptionsBuilder + { + self.team_id = Some(team_id); + self + } + + pub fn auto_init(&mut self, auto_init: bool) -> &mut RepoOptionsBuilder + { + self.auto_init = Some(auto_init); + self + } + + pub fn gitignore_template(&mut self, gitignore_template: GI) -> &mut RepoOptionsBuilder + where GI: Into + { + self.gitignore_template = Some(gitignore_template.into()); + self + } + + pub fn license_template(&mut self, license_template: L) -> &mut RepoOptionsBuilder + where L: Into + { + self.license_template = Some(license_template.into()); + self + } + + pub fn build(&self) -> RepoOptions { + RepoOptions::new(self.name.as_ref(), + self.description.clone(), + self.homepage.clone(), + self.private, + self.has_issues, + self.has_wiki, + self.has_downloads, + self.team_id, + self.auto_init, + self.gitignore_template.clone(), + self.license_template.clone()) + } +} + impl RepoOptions { pub fn new(name: N, - description: Option, - homepage: Option, - private: Option, - has_issues: Option, - has_wiki: Option, - has_downloads: Option, - team_id: Option, - auto_init: Option, - gitignore_template: Option, - license_template: Option) - -> RepoOptions + description: Option, + homepage: Option, + private: Option, + has_issues: Option, + has_wiki: Option, + has_downloads: Option, + team_id: Option, + auto_init: Option, + gitignore_template: Option, + license_template: Option) + -> RepoOptions where N: Into, D: Into, H: Into, @@ -509,6 +610,10 @@ impl RepoOptions { license_template: license_template.map(|l| l.into()), } } + + pub fn builder>(name: N) -> RepoOptionsBuilder { + RepoOptionsBuilder::new(name) + } } #[derive(Debug, Deserialize)] From dc3611480e3556d3cca85075abe52080aad572c4 Mon Sep 17 00:00:00 2001 From: Richard Fortescue-Webb Date: Tue, 31 May 2016 19:59:39 +0100 Subject: [PATCH 4/5] u32 not i32 for team_id --- src/rep.rs.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rep.rs.in b/src/rep.rs.in index f462fae4..20dfb19b 100644 --- a/src/rep.rs.in +++ b/src/rep.rs.in @@ -467,7 +467,7 @@ pub struct RepoOptions { #[serde(skip_serializing_if="Option::is_none")] pub has_downloads: Option, #[serde(skip_serializing_if="Option::is_none")] - pub team_id: Option, + pub team_id: Option, #[serde(skip_serializing_if="Option::is_none")] pub auto_init: Option, #[serde(skip_serializing_if="Option::is_none")] @@ -485,7 +485,7 @@ pub struct RepoOptionsBuilder { has_issues: Option, has_wiki: Option, has_downloads: Option, - team_id: Option, + team_id: Option, auto_init: Option, gitignore_template: Option, license_template: Option, From 2df8a4b9cfca173f20dbc3e664bf5c92dc9f46b6 Mon Sep 17 00:00:00 2001 From: Richard Fortescue-Webb Date: Sat, 11 Jun 2016 19:06:39 +0100 Subject: [PATCH 5/5] Fix a few u32s on team_id --- src/rep.rs.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rep.rs.in b/src/rep.rs.in index 20dfb19b..f462fae4 100644 --- a/src/rep.rs.in +++ b/src/rep.rs.in @@ -467,7 +467,7 @@ pub struct RepoOptions { #[serde(skip_serializing_if="Option::is_none")] pub has_downloads: Option, #[serde(skip_serializing_if="Option::is_none")] - pub team_id: Option, + pub team_id: Option, #[serde(skip_serializing_if="Option::is_none")] pub auto_init: Option, #[serde(skip_serializing_if="Option::is_none")] @@ -485,7 +485,7 @@ pub struct RepoOptionsBuilder { has_issues: Option, has_wiki: Option, has_downloads: Option, - team_id: Option, + team_id: Option, auto_init: Option, gitignore_template: Option, license_template: Option,