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

Extend automatic rendered link to the blog.rust-lang.org repo #1839

Merged
merged 1 commit into from
Sep 10, 2024
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
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
Loading