-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
collaborators.rs
50 lines (45 loc) · 1.36 KB
/
collaborators.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
43
44
45
46
47
48
49
50
use hubcaps::{self, Credentials, Github};
use std::env;
use std::error::Error;
#[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),
)?;
println!("My organizations:");
println!();
for org in github.orgs().list().await? {
println!("{}", org.login);
println!("=============");
println!("Repos:");
for repo in github
.org_repos(&org.login[..])
.list(&Default::default())
.await?
{
println!("* {}", repo.name);
// If you have push permissions on an org, you can list collaborators.
// Otherwise, don't print them.
if let Ok(collabs) = github
.repo(&org.login[..], &repo.name[..])
.collaborators()
.list()
.await
{
println!(
" * Collaborators: {}",
collabs
.into_iter()
.map(|c| { c.login })
.collect::<Vec<_>>()
.join(", ")
);
}
}
println!()
}
Ok(())
}