Skip to content

Commit

Permalink
Merge pull request #254 from Marwes/std_future
Browse files Browse the repository at this point in the history
feat: Update to std futures
  • Loading branch information
softprops committed Jun 6, 2020
2 parents 067063d + cb6e90c commit eb19395
Show file tree
Hide file tree
Showing 23 changed files with 298 additions and 250 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ coveralls = { repository = "softprops/hubcaps" }
maintenance = { status = "actively-developed" }

[dev-dependencies]
pretty_env_logger = "0.3"
tokio = "0.1"
pretty_env_logger = "0.4"
tokio = "0.2"

[dependencies]
data-encoding = "2"
dirs = { version = "2.0", optional = true }
futures = "0.1"
http = "0.1"
futures = "0.3"
http = "0.2"
hyperx = "1"
jsonwebtoken = "6"
jsonwebtoken = "7"
mime = "0.3"
log = "0.4"
url = "1.7"
reqwest = { version = "0.9.10", default-features = false }
url = "2"
reqwest = { version = "0.10", default-features = false }
serde = { version = "1.0.84", features = ['derive'] }
serde_derive = "1.0"
serde_json = "1.0"
error-chain = "0.12"
base64 = "0.11"
base64 = "0.12"
percent-encoding = "2"

[features]
Expand Down
4 changes: 2 additions & 2 deletions examples/branches.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use futures::Stream;
use futures::prelude::*;
use tokio::runtime::Runtime;

use hubcaps::branches::Protection;
Expand All @@ -21,7 +21,7 @@ fn main() -> Result<()> {
.repo("softprops", "hubcaps")
.branches()
.iter()
.for_each(|branch| {
.try_for_each(|branch| async move {
println!("{:#?}", branch);
Ok(())
}),
Expand Down
5 changes: 1 addition & 4 deletions examples/conditional_requests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#[cfg(feature = "httpcache")]
use {
reqwest::r#async::Client,
tokio::runtime::Runtime,
};
use {reqwest::Client, tokio::runtime::Runtime};

use hubcaps::Result;

Expand Down
16 changes: 10 additions & 6 deletions examples/content.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::env;
use std::str;

use futures::Stream;
use futures::prelude::*;
use tokio::runtime::Runtime;

use hubcaps::{Credentials, Github, Result};
Expand All @@ -23,13 +23,17 @@ fn main() -> Result<()> {
println!("{}", str::from_utf8(&license.content).unwrap());

println!("Directory contents stream:");
rt.block_on(repo.content().iter("/examples").for_each(|item| {
println!(" {}", item.path);
Ok(())
}))?;
rt.block_on(
repo.content()
.iter("/examples")
.try_for_each(|item| async move {
println!(" {}", item.path);
Ok(())
}),
)?;

println!("Root directory:");
for item in rt.block_on(repo.content().root().collect())? {
for item in rt.block_on(repo.content().root().try_collect::<Vec<_>>())? {
println!(" {}", item.path)
}

Expand Down
6 changes: 3 additions & 3 deletions examples/forks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use futures::Stream;
use futures::prelude::*;
use tokio::runtime::Runtime;

use hubcaps::repositories::ForkListOptions;
Expand All @@ -24,10 +24,10 @@ fn main() -> Result<()> {
.repo(owner, repo)
.forks()
.iter(&options)
.for_each(move |repo| {
.try_for_each(move |repo| async move {
println!("{}", repo.full_name);
Ok(())
})
}),
)?;

Ok(())
Expand Down
18 changes: 7 additions & 11 deletions examples/invitations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::env;
use std::fs::File;
use std::io::Read;

use futures::prelude::*;
use tokio::runtime::Runtime;

use futures::stream::Stream;
use hubcaps::{Credentials, Github, InstallationTokenGenerator, JWTCredentials, Result};

fn var(name: &str) -> Result<String> {
Expand Down Expand Up @@ -34,16 +34,12 @@ fn main() -> Result<()> {
InstallationTokenGenerator::new(installation_id.parse().unwrap(), cred),
));

rt.block_on(
github
.org("NixOS")
.membership()
.invitations()
.for_each(|invite| {
println!("{:#?}", invite);
Ok(())
}),
)?;
rt.block_on(github.org("NixOS").membership().invitations().try_for_each(
|invite| async move {
println!("{:#?}", invite);
Ok(())
},
))?;

Ok(())
}
4 changes: 2 additions & 2 deletions examples/issues.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use futures::Stream;
use futures::prelude::*;
use tokio::runtime::Runtime;

use hubcaps::issues::{IssueListOptions, State};
Expand All @@ -25,7 +25,7 @@ fn main() -> Result<()> {
.state(State::All)
.build(),
)
.for_each(move |issue| {
.try_for_each(move |issue| async move {
println!("{} ({})", issue.title, issue.state);
Ok(())
}),
Expand Down
18 changes: 11 additions & 7 deletions examples/labels.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use futures::Stream;
use futures::prelude::*;
use tokio::runtime::Runtime;

use hubcaps::{Credentials, Github, Result};
Expand All @@ -27,12 +27,16 @@ fn main() -> Result<()> {
)?
);
// stream over all labels defined for a repo
rt.block_on(github.repo("rust-lang", "cargo").labels().iter().for_each(
move |label| {
println!("{}", label.name);
Ok(())
},
))?;
rt.block_on(
github
.repo("rust-lang", "cargo")
.labels()
.iter()
.try_for_each(move |label| async move {
println!("{}", label.name);
Ok(())
}),
)?;
Ok(())
}
_ => Err("example missing GITHUB_TOKEN".into()),
Expand Down
36 changes: 21 additions & 15 deletions examples/pulls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use futures::Stream;
use futures::prelude::*;
use tokio::runtime::Runtime;

use hubcaps::{Credentials, Github, Result};
Expand All @@ -16,10 +16,14 @@ fn main() -> Result<()> {
)?;
let repo = github.repo("softprops", "hubcat");
let pulls = repo.pulls();
rt.block_on(pulls.iter(&Default::default()).for_each(|pull| {
println!("{:#?}", pull);
Ok(())
}))?;
rt.block_on(
pulls
.iter(&Default::default())
.try_for_each(|pull| async move {
println!("{:#?}", pull);
Ok(())
}),
)?;

println!("comments");
for c in rt.block_on(
Expand All @@ -41,22 +45,24 @@ fn main() -> Result<()> {
.get(28)
.commits()
.iter()
.for_each(|c| {
.try_for_each(|c| async move {
println!("{:#?}", c);
Ok(())
}),
)?;

println!("review requests");
println!("{:#?}",
rt.block_on(
github
.repo("softprops", "hubcaps")
.pulls()
.get(190)
.review_requests()
.get()
)?);
println!(
"{:#?}",
rt.block_on(
github
.repo("softprops", "hubcaps")
.pulls()
.get(190)
.review_requests()
.get()
)?
);
Ok(())
}
_ => Err("example missing GITHUB_TOKEN".into()),
Expand Down
11 changes: 5 additions & 6 deletions examples/repos.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use futures::{Future, Stream};
use futures::prelude::*;
use tokio::runtime::Runtime;

use hubcaps::{Credentials, Github, Result};
Expand All @@ -10,23 +10,22 @@ fn main() -> Result<()> {
match env::var("GITHUB_TOKEN").ok() {
Some(token) => {
let mut rt = Runtime::new()?;
let github = Github::new(
let github = &Github::new(
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
Credentials::Token(token),
)?;
let handle = rt.executor();
rt.block_on(
github
.user_repos("softprops")
.iter(&Default::default())
.for_each(move |repo| {
.try_for_each(move |repo| async move {
println!("{}", repo.name);
let f = repo.languages(github.clone()).map(|langs| {
let f = repo.languages(github.clone()).map_ok(|langs| {
for (language, bytes_of_code) in langs {
println!("{}: {} bytes", language, bytes_of_code)
}
});
handle.spawn(f.map_err(|_| ()));
tokio::spawn(f.map(|_| ()));
Ok(())
}),
)?;
Expand Down
4 changes: 2 additions & 2 deletions examples/search_issues.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use futures::Stream;
use futures::prelude::*;
use tokio::runtime::Runtime;

use hubcaps::search::SearchIssuesOptions;
Expand All @@ -25,7 +25,7 @@ fn main() -> Result<()> {
"user:softprops",
&SearchIssuesOptions::builder().per_page(100).build(),
)
.for_each(|issue| {
.try_for_each(|issue| async move {
println!("{}", issue.title);
Ok(())
}),
Expand Down
4 changes: 2 additions & 2 deletions examples/search_repos.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use futures::Stream;
use futures::prelude::*;
use tokio::runtime::Runtime;

use hubcaps::search::SearchReposOptions;
Expand All @@ -25,7 +25,7 @@ fn main() -> Result<()> {
"user:softprops hubcaps",
&SearchReposOptions::builder().per_page(100).build(),
)
.for_each(|repo| {
.try_for_each(|repo| async move {
println!("{}", repo.full_name);
Ok(())
}),
Expand Down
8 changes: 4 additions & 4 deletions examples/stars.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::env;

use futures::Future;
use tokio::runtime::Runtime;

use hubcaps::{Credentials, Github, Result};
Expand All @@ -15,9 +14,10 @@ fn main() -> Result<()> {
Credentials::Token(token),
)?;
let stars = github.activity().stars();
let f = stars
.star("softprops", "hubcaps")
.join(stars.is_starred("softprops", "hubcaps"));
let f = futures::future::try_join(
stars.star("softprops", "hubcaps"),
stars.is_starred("softprops", "hubcaps"),
);
match rt.block_on(f) {
Ok((_, starred)) => println!("starred? {:?}", starred),
Err(err) => println!("err {}", err),
Expand Down
28 changes: 18 additions & 10 deletions examples/teams.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use futures::Stream;
use futures::prelude::*;
use tokio::runtime::Runtime;

use hubcaps::teams::{TeamMemberOptions, TeamMemberRole, TeamOptions};
Expand All @@ -20,17 +20,25 @@ fn main() -> Result<()> {
let repo_name = "d18e3679-9830-40a9-8cf5-16602639b43e";

println!("org teams");
rt.block_on(github.org(org).teams().iter().for_each(|team| {
println!("{:#?}", team);
Ok(())
}))
rt.block_on(
github
.org(org)
.teams()
.iter()
.try_for_each(|team| async move {
println!("{:#?}", team);
Ok(())
}),
)
.unwrap_or_else(|e| println!("error: {:#?}", e));

println!("repo teams");
rt.block_on(github.repo(org, repo_name).teams().iter().for_each(|team| {
println!("{:#?}", team);
Ok(())
}))
rt.block_on(github.repo(org, repo_name).teams().iter().try_for_each(
|team| async move {
println!("{:#?}", team);
Ok(())
},
))
.unwrap_or_else(|e| println!("error: {:#?}", e));

let new_team = rt.block_on(github.org(org).teams().create(&TeamOptions {
Expand Down Expand Up @@ -62,7 +70,7 @@ fn main() -> Result<()> {
);

println!("members:");
rt.block_on(team.iter_members().for_each(|member| {
rt.block_on(team.iter_members().try_for_each(|member| async move {
println!("{:#?}", member);
Ok(())
}))
Expand Down
Loading

0 comments on commit eb19395

Please sign in to comment.