Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iter stream for repo labels #110

Merged
merged 4 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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