From ff8046453c35324991e4422efed1dea4a0859ded Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 7 Sep 2024 00:03:27 +0200 Subject: [PATCH] Extend automatic rendered link to the blog.rust-lang.org repo --- src/handlers.rs | 6 +++--- src/handlers/{rfc_helper.rs => rendered_link.rs} | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) rename src/handlers/{rfc_helper.rs => rendered_link.rs} (81%) diff --git a/src/handlers.rs b/src/handlers.rs index f78cdf6c..7cad5439 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -44,9 +44,9 @@ pub mod project_goals; pub mod pull_requests_assignment_update; mod relabel; mod relnotes; +mod rendered_link; mod review_requested; mod review_submitted; -mod rfc_helper; pub mod rustc_commits; mod shortcut; mod transfer; @@ -100,9 +100,9 @@ pub async fn handle(ctx: &Context, event: &Event) -> Vec { ); } - if let Err(e) = rfc_helper::handle(ctx, event).await { + if let Err(e) = rendered_link::handle(ctx, event).await { log::error!( - "failed to process event {:?} with rfc_helper handler: {:?}", + "failed to process event {:?} with rendered_link handler: {:?}", event, e ); diff --git a/src/handlers/rfc_helper.rs b/src/handlers/rendered_link.rs similarity index 81% rename from src/handlers/rfc_helper.rs rename to src/handlers/rendered_link.rs index 9daab157..81547701 100644 --- a/src/handlers/rfc_helper.rs +++ b/src/handlers/rendered_link.rs @@ -11,22 +11,24 @@ pub async fn handle(ctx: &Context, event: &Event) -> anyhow::Result<()> { }; let repo = e.issue.repository(); - if !(repo.organization == "rust-lang" && repo.repository == "rfcs") { - return Ok(()); - } + let prefix = match (&*repo.organization, &*repo.repository) { + ("rust-lang", "rfcs") => "text/", + ("rust-lang", "blog.rust-lang.org") => "posts/", + _ => return Ok(()), + }; - if let Err(e) = add_rendered_link(&ctx, &e).await { + if let Err(e) = add_rendered_link(&ctx, &e, prefix).await { tracing::error!("Error adding rendered link: {:?}", e); } Ok(()) } -async fn add_rendered_link(ctx: &Context, e: &IssuesEvent) -> anyhow::Result<()> { +async fn add_rendered_link(ctx: &Context, e: &IssuesEvent, prefix: &str) -> anyhow::Result<()> { if e.action == IssuesAction::Opened { let files = e.issue.files(&ctx.github).await?; - if let Some(file) = files.iter().find(|f| f.filename.starts_with("text/")) { + if let Some(file) = files.iter().find(|f| f.filename.starts_with(prefix)) { if !e.issue.body.contains("[Rendered]") { // This URL should be stable while the PR is open, even if the // user pushes new commits.