From f254286a22f73af1f4f086adf93a9fe61cd286b5 Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Wed, 4 May 2022 14:51:39 -0500 Subject: [PATCH 1/5] Add defaults for potentially null datetimes --- cio/src/repos.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cio/src/repos.rs b/cio/src/repos.rs index a43c236b8..a1bc7a4f2 100644 --- a/cio/src/repos.rs +++ b/cio/src/repos.rs @@ -285,9 +285,9 @@ impl NewRepo { has_pages: r.has_pages, has_downloads: r.has_downloads, archived: r.archived, - pushed_at: r.pushed_at.unwrap(), - created_at: r.created_at.unwrap(), - updated_at: r.updated_at.unwrap(), + pushed_at: r.pushed_at.unwrap_or_else(Utc::now), + created_at: r.created_at.unwrap_or_else(Utc::now), + updated_at: r.updated_at.unwrap_or_else(Utc::now), cio_company_id, } } @@ -357,9 +357,9 @@ impl NewRepo { has_pages: r.has_pages, has_downloads: r.has_downloads, archived: r.archived, - pushed_at: r.pushed_at.unwrap(), - created_at: r.created_at.unwrap(), - updated_at: r.updated_at.unwrap(), + pushed_at: r.pushed_at.unwrap_or_else(Utc::now), + created_at: r.created_at.unwrap_or_else(Utc::now), + updated_at: r.updated_at.unwrap_or_else(Utc::now), cio_company_id, } } From a22968c1bfe5213b0ab9c1096cfb5f06f129c58d Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Wed, 4 May 2022 14:52:05 -0500 Subject: [PATCH 2/5] Capture arbitrary repo names in Repo enum --- webhooky/src/repos.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/webhooky/src/repos.rs b/webhooky/src/repos.rs index d8a35de04..f93c89002 100644 --- a/webhooky/src/repos.rs +++ b/webhooky/src/repos.rs @@ -2,22 +2,21 @@ use std::{fmt, str::FromStr}; /// GitHub repos. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] pub enum Repo { - /// (Special repo.) Any repo. - Wildcard, - Configs, RFD, + /// Any repo non-predefined repo + Other(String) } impl Repo { - /// Returns a static string for the repo name. - pub fn name(self) -> &'static str { + /// Returns a string for the repo name. + pub fn name(&self) -> &str { match self { - Repo::Wildcard => "*", Repo::Configs => "configs", Repo::RFD => "rfd", + Repo::Other(repo_name) => repo_name.as_str() } } } @@ -27,12 +26,11 @@ impl FromStr for Repo { fn from_str(s: &str) -> Result { match s { - "*" => Ok(Repo::Wildcard), "configs" => Ok(Repo::Configs), "rfd" => Ok(Repo::RFD), _ => { println!("invalid GitHub repo: `{}`", s); - Ok(Repo::Wildcard) + Ok(Repo::Other(s.to_string())) } } } From 6c3b13fb447d9b1624d99dc52508624533ab616c Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Wed, 4 May 2022 14:52:49 -0500 Subject: [PATCH 3/5] Run sync tasks in order instead of racing to ensure new repos get settings updated --- webhooky/src/main.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/webhooky/src/main.rs b/webhooky/src/main.rs index 0f49d3933..86ca43a69 100644 --- a/webhooky/src/main.rs +++ b/webhooky/src/main.rs @@ -309,22 +309,21 @@ async fn run_cmd(opts: crate::core::Opts, logger: slog::Logger) -> Result<()> { .into_iter() .map(|company| { tokio::spawn(enclose! { (db) async move { - tokio::join!( - cio_api::repos::sync_all_repo_settings(&db, &company), - cio_api::repos::refresh_db_github_repos(&db, &company), - ) + cio_api::repos::refresh_db_github_repos(&db, &company).await?; + cio_api::repos::sync_all_repo_settings(&db, &company).await?; + + Ok(()) }}) }) .collect(); - let mut results: Vec<(Result<()>, Result<()>)> = Default::default(); + let mut results: Vec> = Default::default(); for task in tasks { results.push(task.await?); } - for (refresh_result, cleanup_result) in results { - refresh_result?; - cleanup_result?; + for result in results { + result? } } crate::core::SubCommand::SyncRFDs(_) => { From 1106318c304ae6eccf9a0d984b0cf86cdb21dfc5 Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Wed, 4 May 2022 14:53:47 -0500 Subject: [PATCH 4/5] Fix comment --- webhooky/src/repos.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webhooky/src/repos.rs b/webhooky/src/repos.rs index f93c89002..63543087c 100644 --- a/webhooky/src/repos.rs +++ b/webhooky/src/repos.rs @@ -6,7 +6,7 @@ use std::{fmt, str::FromStr}; pub enum Repo { Configs, RFD, - /// Any repo non-predefined repo + /// Any non-predefined repo Other(String) } From 3f1a04467c3de0a28af7fee7779ac80ffff8fb4c Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Wed, 4 May 2022 15:12:26 -0500 Subject: [PATCH 5/5] Fix formatting --- webhooky/src/repos.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webhooky/src/repos.rs b/webhooky/src/repos.rs index 63543087c..fdc0752df 100644 --- a/webhooky/src/repos.rs +++ b/webhooky/src/repos.rs @@ -7,7 +7,7 @@ pub enum Repo { Configs, RFD, /// Any non-predefined repo - Other(String) + Other(String), } impl Repo { @@ -16,7 +16,7 @@ impl Repo { match self { Repo::Configs => "configs", Repo::RFD => "rfd", - Repo::Other(repo_name) => repo_name.as_str() + Repo::Other(repo_name) => repo_name.as_str(), } } }