Skip to content

Commit

Permalink
Merge pull request #1839 from Urgau/rendered_link-blog
Browse files Browse the repository at this point in the history
Extend automatic rendered link to the blog.rust-lang.org repo
  • Loading branch information
ehuss authored Sep 10, 2024
2 parents c35ff9f + ff80464 commit 31ab10c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,9 +100,9 @@ pub async fn handle(ctx: &Context, event: &Event) -> Vec<HandlerError> {
);
}

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
);
Expand Down
14 changes: 8 additions & 6 deletions src/handlers/rfc_helper.rs → src/handlers/rendered_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 31ab10c

Please sign in to comment.