Skip to content

Commit

Permalink
Merge pull request #110 from softprops/label_iter
Browse files Browse the repository at this point in the history
iter stream for repo labels
  • Loading branch information
softprops authored Mar 5, 2018
2 parents 88b4697 + 4b3ff92 commit 6d059fd
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ matrix:
- rust: beta

script:
- RUSTFLAGS="$RUSTFLAGS -C link-dead-code" cargo test
# https://github.com/rust-lang/rust/issues/47309#issuecomment-359166547
#- RUSTFLAGS="$RUSTFLAGS -C link-dead-code" cargo test
- cargo test


before_cache:
Expand Down Expand Up @@ -53,7 +55,7 @@ after_success:
[ $TRAVIS_BRANCH = master ] &&
[ $TRAVIS_PULL_REQUEST = false ] &&
(ls target/debug &&
RUSTFLAGS="-C link-dead-code" cargo test --no-run &&
cargo test --no-run &&
for file in target/debug/hubcaps-*; do
if [[ "${file: -2}" != ".d" ]]; then
mkdir -p "target/cov/$(basename $file)";
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.4.5

* fix issue with stream pagination [#108](https://github.com/softprops/hubcaps/pull/108)
* implement stream iter for repo labels [#110](https://github.com/softprops/hubcaps/pull/110)

# 0.4.4

* issue body is now an `Option<String>` type [#107](https://github.com/softprops/hubcaps/pull/107)
Expand Down
9 changes: 4 additions & 5 deletions examples/comments.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
extern crate env_logger;
extern crate hyper;
extern crate hubcaps;
extern crate futures;
extern crate tokio_core;
#[macro_use(quick_main)]
extern crate error_chain;
extern crate futures;
extern crate hubcaps;
extern crate hyper;
extern crate tokio_core;

use std::env;

use futures::Future;
use tokio_core::reactor::Core;

use hubcaps::{Credentials, Github, Result};
Expand Down
39 changes: 39 additions & 0 deletions examples/labels.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
extern crate env_logger;
#[macro_use(quick_main)]
extern crate error_chain;
extern crate futures;
extern crate hubcaps;
extern crate hyper;
extern crate tokio_core;

use std::env;

use futures::Stream;
use tokio_core::reactor::Core;

use hubcaps::{Credentials, Github, Result};

quick_main!(run);

fn run() -> 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")),
Some(Credentials::Token(token)),
&core.handle(),
);
core.run(
github
.repo("rust-lang", "cargo")
.labels()
.iter()
.for_each(move |label| Ok(println!("{}", label.name))),
)?;
Ok(())
}
_ => Err("example missing GITHUB_TOKEN".into()),
}
}
24 changes: 17 additions & 7 deletions src/labels/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
//! Labels interface

extern crate serde_json;

use serde_json;
use futures::future;
use hyper::client::Connect;

use {Github, Future};
use {unfold, Future, Github, Stream};

fn identity<T>(x: T) -> T {
x
}

pub struct Labels<C>
where
Expand Down Expand Up @@ -39,10 +42,8 @@ impl<C: Connect + Clone> Labels<C> {
}

pub fn update(&self, prevname: &str, lab: &LabelOptions) -> Future<Label> {
self.github.patch(
&self.path(&format!("/{}", prevname)),
json!(lab),
)
self.github
.patch(&self.path(&format!("/{}", prevname)), json!(lab))
}

pub fn delete(&self, name: &str) -> Future<()> {
Expand All @@ -52,6 +53,15 @@ impl<C: Connect + Clone> Labels<C> {
pub fn list(&self) -> Future<Vec<Label>> {
self.github.get(&self.path(""))
}

/// provides a stream over all pages of this repo's labels
pub fn iter(&self) -> Stream<Label> {
unfold(
self.github.clone(),
self.github.get_pages(&self.path("")),
identity,
)
}
}

// representations
Expand Down

0 comments on commit 6d059fd

Please sign in to comment.