diff --git a/tools/automator/src/blog/release.rs b/tools/automator/src/blog/release.rs index d1c11975d..554d7c87f 100644 --- a/tools/automator/src/blog/release.rs +++ b/tools/automator/src/blog/release.rs @@ -1,12 +1,8 @@ -use std::{collections::HashSet, fmt::Write, path::PathBuf}; +use std::{collections::HashSet, fmt::Write}; -use anyhow::Context; use map_macro::hash_set; use octocrab::Octocrab; -use tokio::{ - fs::{self, File}, - io::AsyncWriteExt, -}; +use tokio::{fs::File, io::AsyncWriteExt}; use crate::{ pull_requests::{Author, PullRequest, PullRequestsSinceLastRelease}, @@ -40,34 +36,13 @@ pub async fn create_release_announcement( .await? .as_markdown(min_dollars, for_readme)?; - let mut file = create_blog_post_file("release", &version).await?; + let mut file = util::create_blog_post_file("release", &version).await?; generate_announcement(date, version, sponsors, pull_requests, &mut file) .await?; Ok(()) } -async fn create_blog_post_file( - category: &str, - version: &str, -) -> anyhow::Result { - let dir = PathBuf::from(format!("content/blog/{category}/{version}")); - let file = dir.join("index.md"); - - // VS Code (and probably other editors/IDEs) renders the path in the output - // as a clickable link, so the user can open the file easily. - println!("Generating `{category}` blog post at {}", file.display()); - - fs::create_dir_all(&dir).await.with_context(|| { - format!("Failed to create directory `{}`", dir.display()) - })?; - let file = File::create(&file).await.with_context(|| { - format!("Failed to create file `{}`", file.display()) - })?; - - Ok(file) -} - async fn generate_announcement( date: String, version: String, diff --git a/tools/automator/src/blog/util.rs b/tools/automator/src/blog/util.rs index d93201ad7..e25a89165 100644 --- a/tools/automator/src/blog/util.rs +++ b/tools/automator/src/blog/util.rs @@ -1,7 +1,32 @@ +use std::path::PathBuf; + +use anyhow::Context; use chrono::{Datelike, Utc}; +use tokio::fs::{self, File}; pub fn date() -> String { let now = Utc::now(); let year = now.year(); format!("{year}-{:02}-{:02}", now.month(), now.day()) } + +pub async fn create_blog_post_file( + category: &str, + version: &str, +) -> anyhow::Result { + let dir = PathBuf::from(format!("content/blog/{category}/{version}")); + let file = dir.join("index.md"); + + // VS Code (and probably other editors/IDEs) renders the path in the output + // as a clickable link, so the user can open the file easily. + println!("Generating `{category}` blog post at {}", file.display()); + + fs::create_dir_all(&dir).await.with_context(|| { + format!("Failed to create directory `{}`", dir.display()) + })?; + let file = File::create(&file).await.with_context(|| { + format!("Failed to create file `{}`", file.display()) + })?; + + Ok(file) +}