From 4f5871dfeb8433346cda0ecc250047d45f0fc2c2 Mon Sep 17 00:00:00 2001 From: simon busch Date: Mon, 20 Mar 2023 13:03:01 +0100 Subject: [PATCH] update cargo.toml + split logic --- Cargo.toml | 7 +++++++ src/main.rs | 33 ++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1c6157b..024b7ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,13 @@ name = "rust-github-assistant" version = "0.1.0" edition = "2021" +authors = ["simon Busch "] +description = "Keep track of your github assignments" +license = "MIT OR Apache-2.0" +homepage = "https://github.com/Simon-Busch/rust-github-assistant" +repository = "https://github.com/Simon-Busch/rust-github-assistant" +categories = ["command-line-utilities"] +keywords = ["github", "assistant", "cli", "rust"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index 6bc1d38..fc57583 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,16 +85,8 @@ async fn main() -> Result<(), Box> { render_waiting_screen(&mut terminal)?; let (username, access_token) = init_variables(); - let issues_list_response_open = get_github_response(&username, &access_token, "open").await?; - let issues_list_response_closed = get_github_response(&username, &access_token, "closed").await?; - let mut issues_list_open = issues_list_response_open.items.to_owned(); - //sort alphabetically by repository - issues_list_open.sort_by_key(|i| i.repository.clone().unwrap_or_default()); - - let mut issues_list_closed = issues_list_response_closed.items.to_owned(); - //sort alphabetically by repository - issues_list_closed.sort_by_key(|i| i.repository.clone().unwrap_or_default()); + let (issues_list_open, issues_list_closed, issues_list_open_len, issues_list_closed_len) = init_gh_data(&username, &access_token).await?; let menu_titles = vec!["Home","Assignments", "Closed", "Quit"]; // Add "Refresh", let mut active_menu_item = MenuItem::Home; @@ -161,7 +153,7 @@ async fn main() -> Result<(), Box> { rect.render_widget(tabs, chunks[0]); match active_menu_item { - MenuItem::Home => rect.render_widget(render_home(&issues_list_response_open.total_count, &issues_list_response_closed.total_count), chunks[1]), + MenuItem::Home => rect.render_widget(render_home(&issues_list_open_len, &issues_list_closed_len), chunks[1]), MenuItem::Assignments => { let data_chunck = Layout::default() .direction(Direction::Horizontal) @@ -285,10 +277,29 @@ async fn main() -> Result<(), Box> { }, Event::Tick => {} } - } + } Ok(()) } +async fn init_gh_data(username: &str, access_token: &str) -> Result<(Vec, Vec, i32, i32), Box> { + // Get list of open issues + let issues_list_response_open = get_github_response(username, access_token, "open").await?; + let mut issues_list_open = issues_list_response_open.items.to_owned(); + issues_list_open.sort_by_key(|i| i.repository.clone().unwrap_or_default()); + + // Get list of closed issues + let issues_list_response_closed = get_github_response(username, access_token, "closed").await?; + let mut issues_list_closed = issues_list_response_closed.items.to_owned(); + issues_list_closed.sort_by_key(|i| i.repository.clone().unwrap_or_default()); + + // Convert the lengths of the issue lists to i32 + let issues_list_open_len = issues_list_open.len() as i32; + let issues_list_closed_len = issues_list_closed.len() as i32; + + Ok((issues_list_open, issues_list_closed, issues_list_open_len, issues_list_closed_len)) +} + + fn render_waiting_screen( terminal: &mut Terminal, ) -> Result<(), Box> {