-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
content.rs
42 lines (36 loc) · 1.03 KB
/
content.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use futures::prelude::*;
use hubcaps::{Credentials, Github};
use std::env;
use std::error::Error;
use std::str;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
pretty_env_logger::init();
let token = env::var("GITHUB_TOKEN")?;
let github = Github::new(
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
Credentials::Token(token),
)?;
let repo = github.repo("softprops", "hubcaps");
println!("License file:");
let license = repo.content().file("master", "LICENSE").await?;
println!("{}", str::from_utf8(&license.content).unwrap());
println!("Directory contents stream:");
repo.content()
.iter("master", "/examples")
.try_for_each(|item| async move {
println!(" {}", item.path);
Ok(())
})
.await?;
println!("Root directory:");
for item in repo
.content()
.root("master")
.try_collect::<Vec<_>>()
.await?
{
println!(" {}", item.path)
}
Ok(())
}