Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages and logging in automator #2142

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tools/automator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -24,3 +25,7 @@ features = ["derive"]
[dependencies.tokio]
version = "1.35.0"
features = ["full"]

[dependencies.tracing-subscriber]
version = "0.3.18"
features = ["env-filter"]
14 changes: 10 additions & 4 deletions tools/automator/src/blog/release.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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();
Expand All @@ -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(())
}
Expand Down
6 changes: 6 additions & 0 deletions tools/automator/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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()?;
Expand Down
8 changes: 7 additions & 1 deletion tools/automator/src/sponsors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down