From 59072de7fffa71c1bc050a4b9a74bd8812954d3e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Dec 2023 10:46:20 +0100 Subject: [PATCH 1/4] Improve error messages --- tools/automator/src/blog/release.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/automator/src/blog/release.rs b/tools/automator/src/blog/release.rs index 550c957fa..67e9e644e 100644 --- a/tools/automator/src/blog/release.rs +++ b/tools/automator/src/blog/release.rs @@ -1,5 +1,6 @@ use std::{collections::HashSet, fmt::Write}; +use anyhow::Context; use map_macro::hash_set; use octocrab::Octocrab; use tokio::{fs::File, io::AsyncWriteExt}; @@ -17,7 +18,9 @@ pub async fn create_release_announcement( let date = util::now_ymd(); let pull_requests_since_last_release = - PullRequestsSinceLastRelease::fetch(octocrab).await?; + PullRequestsSinceLastRelease::fetch(octocrab) + .await + .context("Failed to fetch pull requests since last release")?; let pull_requests = pull_requests_since_last_release.pull_requests.into_values(); @@ -33,12 +36,15 @@ pub async fn create_release_announcement( let min_dollars = 32; let for_readme = false; let sponsors = Sponsors::query(octocrab) - .await? - .as_markdown(min_dollars, for_readme)?; + .await + .context("Failed to query sponsors")? + .as_markdown(min_dollars, for_readme) + .context("Failed to convert sponsor data to Markdown")?; let mut file = util::create_blog_post_file("release", &version).await?; generate_announcement(date, version, sponsors, pull_requests, &mut file) - .await?; + .await + .context("Failed to generate release announcement")?; Ok(()) } From 8381a62566aec488bb6090462ec070ecd9bcb649 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Dec 2023 10:59:44 +0100 Subject: [PATCH 2/4] Add dependency on Tracing --- Cargo.lock | 2 ++ tools/automator/Cargo.toml | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 24c4e2c24..6701bb7d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,6 +267,8 @@ dependencies = [ "serde", "serde_json", "tokio", + "tracing", + "tracing-subscriber", "url", ] diff --git a/tools/automator/Cargo.toml b/tools/automator/Cargo.toml index e89b37370..4e6a6a4bc 100644 --- a/tools/automator/Cargo.toml +++ b/tools/automator/Cargo.toml @@ -12,6 +12,7 @@ octocrab = "0.32.0" semver = "1.0.20" serde = "1.0.193" serde_json = "1.0.108" +tracing = "0.1.40" url = "2.5.0" [dependencies.autolib] @@ -24,3 +25,7 @@ features = ["derive"] [dependencies.tokio] version = "1.35.0" features = ["full"] + +[dependencies.tracing-subscriber] +version = "0.3.18" +features = ["env-filter"] From 4acb8425329707b5c00e7a7f8e8a96f21cc97b2f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Dec 2023 10:59:58 +0100 Subject: [PATCH 3/4] Enable logging --- tools/automator/src/run.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/automator/src/run.rs b/tools/automator/src/run.rs index 6413ff6ef..cf111768b 100644 --- a/tools/automator/src/run.rs +++ b/tools/automator/src/run.rs @@ -2,6 +2,7 @@ use std::env; use anyhow::Context; use octocrab::Octocrab; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use crate::{ args::{Args, Blog}, @@ -10,6 +11,11 @@ use crate::{ }; pub async fn run() -> anyhow::Result<()> { + tracing_subscriber::registry() + .with(tracing_subscriber::fmt::layer()) + .with(tracing_subscriber::EnvFilter::from_default_env()) + .init(); + let token = env::var("GITHUB_TOKEN") .context("Loading env variable `GITHUB_TOKEN`")?; let octocrab = Octocrab::builder().personal_token(token).build()?; From 62ed24dbe0b46da09746b6923b86b3fdb6d1e2eb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Dec 2023 11:00:07 +0100 Subject: [PATCH 4/4] Add debug message --- tools/automator/src/sponsors.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/automator/src/sponsors.rs b/tools/automator/src/sponsors.rs index 138e68832..dd983110a 100644 --- a/tools/automator/src/sponsors.rs +++ b/tools/automator/src/sponsors.rs @@ -3,6 +3,7 @@ use std::{cmp::Ordering, collections::HashMap, fmt::Write}; use anyhow::Context; use chrono::{DateTime, Utc}; use octocrab::Octocrab; +use tracing::debug; #[derive(Debug)] pub struct Sponsors { @@ -45,11 +46,16 @@ impl Sponsors { let mut json_object = HashMap::new(); json_object.insert("query", graphql_query); - let response: QueryResult = octocrab + let response: serde_json::Value = octocrab .graphql(&json_object) .await .context("GraphQL query failed")?; + debug!("Response to GraphQL query for sponsors:\n{response}"); + + let response: QueryResult = serde_json::from_value(response) + .context("Failed to deserialize GraphQL query result")?; + let mut sponsors = response .data .viewer