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"] 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(()) } 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()?; 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