github_smoke/
github_smoke.rs1use std::sync::Arc;
8
9use subspace_client_github::Client;
10use subspace_client_github::model::{ItemKind, short_login};
11use subspace_core::config;
12use subspace_core::credentials::Credentials;
13
14fn main() {
15 let config = config::path()
16 .map(|path| config::load(&path).0)
17 .unwrap_or_default();
18 let client = Client::new(Arc::new(Credentials::from_system(&config)));
19 let login = active_login(&client);
20 let first_pr = print_sections(&client, &login);
21 print_diff(&client, &login, first_pr.as_deref());
22}
23
24fn active_login(client: &Client) -> String {
26 let accounts = match client.accounts() {
27 Ok(accounts) => accounts,
28 Err(error) => {
29 eprintln!("accounts: {error}");
30 std::process::exit(1);
31 }
32 };
33 println!("accounts: {}", accounts.logins.join(", "));
34 let Some(login) = accounts
35 .active
36 .clone()
37 .or_else(|| accounts.logins.first().cloned())
38 else {
39 eprintln!("no account");
40 std::process::exit(1);
41 };
42 println!("active: {login} (short: {})", short_login(&login));
43 login
44}
45
46fn print_sections(client: &Client, login: &str) -> Option<String> {
48 let mut first_pr = None;
49 for (id, result) in client.sections(login) {
50 match result {
51 Ok(section) => {
52 println!(
53 "section {id}: {} items of {}",
54 section.items.len(),
55 section.total
56 );
57 if first_pr.is_none() {
58 first_pr = section
59 .items
60 .iter()
61 .find(|item| item.kind == ItemKind::Pr)
62 .map(|item| item.key.clone());
63 }
64 }
65 Err(error) => println!("section {id}: error: {error}"),
66 }
67 }
68 first_pr
69}
70
71fn print_diff(client: &Client, login: &str, key: Option<&str>) {
72 let Some(key) = key else {
73 println!("diff: no pull request in any section");
74 return;
75 };
76 match client.diff(login, key) {
77 Ok(diff) => println!(
78 "diff: a pull request with {} files of {} (merge base {}…, head {}…)",
79 diff.files.len(),
80 diff.total,
81 &diff.base_sha[..7],
82 &diff.head_sha[..7]
83 ),
84 Err(error) => println!("diff: error: {error}"),
85 }
86}