diff --git a/examples/releases.rs b/examples/releases.rs new file mode 100644 index 00000000..493d4c94 --- /dev/null +++ b/examples/releases.rs @@ -0,0 +1,38 @@ +extern crate env_logger; +extern crate hubcaps; +extern crate tokio_core; + +use std::env; + +use tokio_core::reactor::Core; + +use hubcaps::{Credentials, Github, Result}; + +fn main() -> Result<()> { + drop(env_logger::init()); + match env::var("GITHUB_TOKEN").ok() { + Some(token) => { + let mut core = Core::new()?; + let github = Github::new( + concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")), + Credentials::Token(token), + &core.handle(), + ); + let owner = "octokit"; + let repo = "rest.js"; + + for r in core.run(github.repo(owner, repo).releases().list())? { + println!("{:#?}", r.name); + } + + let latest = core.run(github.repo(owner, repo).releases().latest())?; + println!("{:#?}", latest); + + let release = core.run(github.repo(owner, repo).releases().by_tag("v11.0.0"))?; + println!("{:#?}", release); + + Ok(()) + } + _ => Err("example missing GITHUB_TOKEN".into()), + } +} diff --git a/src/releases/mod.rs b/src/releases/mod.rs index bc12be70..b46b3660 100644 --- a/src/releases/mod.rs +++ b/src/releases/mod.rs @@ -7,6 +7,9 @@ use hyper::client::Connect; use {Future, Github}; use users::User; +/// Provides access to assets for a release. +/// See the [github docs](https://developer.github.com/v3/repos/releases/) +/// for more information. pub struct Assets where C: Clone + Connect, @@ -43,14 +46,27 @@ impl Assets { } // todo: stream interface to download + + /// Get the asset information. + /// + /// See the [github docs](https://developer.github.com/v3/repos/releases/#get-a-single-release-asset) + /// for more information. pub fn get(&self, id: u64) -> Future { self.github.get(&self.path(&format!("/{}", id))) } + /// Delete an asset by id. + /// + /// See the [github docs](https://developer.github.com/v3/repos/releases/#delete-a-release-asset) + /// for more information. pub fn delete(&self, id: u64) -> Future<()> { self.github.delete(&self.path(&format!("/{}", id))) } + /// List assets for a release. + /// + /// See the [github docs](https://developer.github.com/v3/repos/releases/#list-assets-for-a-release) + /// for more information. pub fn list(&self) -> Future> { self.github.get(&self.path("")) } @@ -88,10 +104,15 @@ impl ReleaseRef { ) } + /// Get the release information. + /// + /// See the [github docs](https://developer.github.com/v3/repos/releases/#get-a-single-release) + /// for more information. pub fn get(&self) -> Future { self.github.get::(&self.path("")) } + /// Get a reference to asset operations for a release. pub fn assets(&self) -> Assets { Assets::new( self.github.clone(), @@ -102,6 +123,9 @@ impl ReleaseRef { } } +/// Provides access to published releases. +/// See the [github docs](https://developer.github.com/v3/repos/releases/) +/// for more information. pub struct Releases where C: Clone + Connect, @@ -129,23 +153,59 @@ impl Releases { format!("/repos/{}/{}/releases{}", self.owner, self.repo, more) } + /// Create new a release. + /// + /// See the [github docs](https://developer.github.com/v3/repos/releases/#create-a-release) + /// for more information. pub fn create(&self, rel: &ReleaseOptions) -> Future { self.github.post(&self.path(""), json!(rel)) } + /// Edit a release by id. + /// + /// See the [github docs](https://developer.github.com/v3/repos/releases/#edit-a-release) + /// for more information. pub fn edit(&self, id: u64, rel: &ReleaseOptions) -> Future { self.github .patch(&self.path(&format!("/{}", id)), json!(rel)) } + /// Delete a release by id. + /// + /// See the [github docs](https://developer.github.com/v3/repos/releases/#delete-a-release) + /// for more information. pub fn delete(&self, id: u64) -> Future<()> { self.github.delete(&self.path(&format!("/{}", id))) } + /// List published releases and draft releases for users with push access. + /// + /// See the [github docs](https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository) + /// for more information. pub fn list(&self) -> Future> { self.github.get(&self.path("")) } + /// Return the latest full release. Draft releases and prereleases are not returned. + /// + /// See the [github docs](https://developer.github.com/v3/repos/releases/#get-the-latest-release) + /// for more information. + pub fn latest(&self) -> Future { + self.github.get(&self.path("/latest")) + } + + /// Return a release by tag name. + /// + /// See the [github docs](https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name) + /// for more information. + pub fn by_tag(&self, tag_name: S) -> Future + where + S: Into, + { + self.github.get(&self.path(&format!("/tags/{}", tag_name.into()))) + } + + /// Get a reference to a specific release associated with a repository pub fn get(&self, id: u64) -> ReleaseRef { ReleaseRef::new( self.github.clone(),