Skip to content

Commit f874681

Browse files
committed
Extend automatic rendered link to the blog.rust-lang.org repo
1 parent c35ff9f commit f874681

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/handlers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ mod relabel;
4646
mod relnotes;
4747
mod review_requested;
4848
mod review_submitted;
49-
mod rfc_helper;
49+
mod rendered_link;
5050
pub mod rustc_commits;
5151
mod shortcut;
5252
mod transfer;
@@ -100,9 +100,9 @@ pub async fn handle(ctx: &Context, event: &Event) -> Vec<HandlerError> {
100100
);
101101
}
102102

103-
if let Err(e) = rfc_helper::handle(ctx, event).await {
103+
if let Err(e) = rendered_link::handle(ctx, event).await {
104104
log::error!(
105-
"failed to process event {:?} with rfc_helper handler: {:?}",
105+
"failed to process event {:?} with rendered_link handler: {:?}",
106106
event,
107107
e
108108
);

src/handlers/rfc_helper.rs renamed to src/handlers/rendered_link.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,24 @@ pub async fn handle(ctx: &Context, event: &Event) -> anyhow::Result<()> {
1111
};
1212

1313
let repo = e.issue.repository();
14-
if !(repo.organization == "rust-lang" && repo.repository == "rfcs") {
15-
return Ok(());
16-
}
14+
let prefix = match (&*repo.organization, &*repo.repository) {
15+
("rust-lang", "rfcs") => "text/",
16+
("rust-lang", "blog.rust-lang.org") => "posts/",
17+
_ => return Ok(()),
18+
};
1719

18-
if let Err(e) = add_rendered_link(&ctx, &e).await {
20+
if let Err(e) = add_rendered_link(&ctx, &e, prefix).await {
1921
tracing::error!("Error adding rendered link: {:?}", e);
2022
}
2123

2224
Ok(())
2325
}
2426

25-
async fn add_rendered_link(ctx: &Context, e: &IssuesEvent) -> anyhow::Result<()> {
27+
async fn add_rendered_link(ctx: &Context, e: &IssuesEvent, prefix: &str) -> anyhow::Result<()> {
2628
if e.action == IssuesAction::Opened {
2729
let files = e.issue.files(&ctx.github).await?;
2830

29-
if let Some(file) = files.iter().find(|f| f.filename.starts_with("text/")) {
31+
if let Some(file) = files.iter().find(|f| f.filename.starts_with(prefix)) {
3032
if !e.issue.body.contains("[Rendered]") {
3133
// This URL should be stable while the PR is open, even if the
3234
// user pushes new commits.

0 commit comments

Comments
 (0)