diff --git a/src/handlers/milestone_prs.rs b/src/handlers/milestone_prs.rs
index 35338501..f086d22d 100644
--- a/src/handlers/milestone_prs.rs
+++ b/src/handlers/milestone_prs.rs
@@ -3,6 +3,7 @@ use crate::{
handlers::Context,
};
use anyhow::Context as _;
+use reqwest::StatusCode;
pub async fn handle(ctx: &Context, event: &Event) -> anyhow::Result<()> {
let e = if let Event::Issue(e) = event {
@@ -39,8 +40,65 @@ pub async fn handle(ctx: &Context, event: &Event) -> anyhow::Result<()> {
return Ok(());
};
- // Fetch channel.rs from the upstream repository
+ // Fetch the version from the upstream repository.
+ let version = if let Some(version) = get_version_standalone(ctx, merge_sha).await? {
+ version
+ } else if let Some(version) = get_version_channelrs(ctx, merge_sha).await? {
+ version
+ } else {
+ log::error!("could not find the version of {:?}", merge_sha);
+ return Ok(());
+ };
+
+ if !version.starts_with("1.") && version.len() < 8 {
+ log::error!("Weird version {:?} for {:?}", version, merge_sha);
+ return Ok(());
+ }
+
+ // Associate this merged PR with the version it merged into.
+ //
+ // Note that this should work for rollup-merged PRs too. It will *not*
+ // auto-update when merging a beta-backport, for example, but that seems
+ // fine; we can manually update without too much trouble in that case, and
+ // eventually automate it separately.
+ e.issue.set_milestone(&ctx.github, &version).await?;
+
+ Ok(())
+}
+
+async fn get_version_standalone(ctx: &Context, merge_sha: &str) -> anyhow::Result