Skip to content

Commit

Permalink
refactor(general): fetch external data only in comment and twios cont…
Browse files Browse the repository at this point in the history
…exts
  • Loading branch information
BobrImperator committed Mar 2, 2024
1 parent b4c17c8 commit be5753e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::io::prelude::*;
use std::{collections::HashSet, io};

mod cli;
use cli::{args, AppParams};
use cli::{args, AppParams, FileConfig};

const VERSION: &str = env!("CARGO_PKG_VERSION");

Expand Down Expand Up @@ -39,7 +39,7 @@ struct Item {
}

#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
#[derive(Debug, Clone)]
struct LabelledItem {
name: String,
repos: Vec<String>,
Expand Down Expand Up @@ -282,15 +282,10 @@ fn write_twios_comment_contents(
content.push("Change repo category to `EXCLUDED` in order to permantently ignore it from TWIOS from now on.".to_string());
}

#[tokio::main]
async fn main() -> octocrab::Result<()> {
println!("Using this-week-in-open-source v{}", VERSION);
println!("");

async fn fetch_data(
app_params: &AppParams,
) -> octocrab::Result<(Vec<LabelledItem>, Vec<Item>, Vec<String>)> {
let octocrab = initialize_octocrab().await?;

let (app_params, file_config) = args();

let mut items = get_user_items(&octocrab, &app_params).await;
items = items
.into_iter()
Expand All @@ -315,8 +310,19 @@ async fn main() -> octocrab::Result<()> {
.collect::<Vec<LabelledItem>>();
let (labels, unknown_items) = match_items_with_labels(&mut labelled_items, &items);

Ok((labels.clone().to_vec(), unknown_items, markdown_definitions))
}

#[tokio::main]
async fn main() -> octocrab::Result<()> {
println!("Using this-week-in-open-source v{}", VERSION);
println!("");

let (app_params, file_config) = args();

match app_params.context {
cli::CliContext::TWIOS => {
let (labels, unknown_items, markdown_definitions) = fetch_data(&app_params).await?;
let mut file = File::create(app_params.file_name()).unwrap();
let mut file_content: Vec<String> = vec![];
write_twios_file_contents(&mut file_content, &labels, &unknown_items);
Expand All @@ -331,6 +337,7 @@ async fn main() -> octocrab::Result<()> {
println!("Done! :)");
}
cli::CliContext::COMMENT => {
let (_labels, unknown_items, _markdown_definitions) = fetch_data(&app_params).await?;
let mut comment_content: Vec<String> = vec![];
write_twios_comment_contents(&mut comment_content, &app_params, &unknown_items);
let twios_comment = cli::TwiosComment {
Expand Down

0 comments on commit be5753e

Please sign in to comment.