Skip to content

Commit f07a5db

Browse files
committed
Automatically add beta nominated to issues fixing regressions
... from stable to beta
1 parent 7276b14 commit f07a5db

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

src/github.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,20 @@ pub struct Repository {
762762
impl Repository {
763763
const GITHUB_API_URL: &'static str = "https://api.github.com";
764764

765+
pub async fn get_issue(&self, client: &GithubClient, id: u64) -> anyhow::Result<Issue> {
766+
let url = format!(
767+
"{}/repos/{}/issues/{}",
768+
Repository::GITHUB_API_URL,
769+
self.full_name,
770+
id
771+
);
772+
let result = client.get(&url);
773+
client
774+
.json(result)
775+
.await
776+
.with_context(|| format!("failed to get issue from {}", url))
777+
}
778+
765779
pub async fn get_issues<'a>(
766780
&self,
767781
client: &GithubClient,

src/handlers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl fmt::Display for HandlerError {
2525

2626
mod assign;
2727
mod autolabel;
28+
mod beta_backport;
2829
mod close;
2930
mod github_releases;
3031
mod glacier;

src/handlers/beta_backport.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use crate::github::{Event, IssuesAction, Label};
2+
use crate::handlers::Context;
3+
use regex::Regex;
4+
5+
lazy_static! {
6+
// See https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-issues/linking-a-pull-request-to-an-issue
7+
// Max 19 digits long to prevent u64 overflow
8+
static ref CLOSES_ISSUE: Regex = Regex::new("(close[sd]|fix(e[sd])?|resolve[sd]) #(\\d{1,19})").unwrap();
9+
}
10+
11+
pub(crate) async fn handle(
12+
ctx: &Context,
13+
event: &Event,
14+
) -> anyhow::Result<()> {
15+
let issue_event = if let Event::Issue(event) = event {
16+
event
17+
} else {
18+
return Ok(());
19+
};
20+
21+
if issue_event.action != IssuesAction::Opened {
22+
return Ok(());
23+
}
24+
25+
if issue_event.issue.pull_request.is_none() {
26+
return Ok(());
27+
}
28+
29+
for caps in CLOSES_ISSUE.captures_iter(&issue_event.issue.body) {
30+
// Should never fail due to the regex
31+
let issue_id = caps.get(1).unwrap().as_str().parse::<u64>().unwrap();
32+
let issue = issue_event
33+
.repository
34+
.get_issue(&ctx.github, issue_id)
35+
.await?;
36+
if issue.labels.contains(&Label {
37+
name: "regression-from-stable-to-beta".to_string(),
38+
}) {
39+
let mut labels = issue_event.issue.labels().to_owned();
40+
labels.push(Label {
41+
name: "beta-nominated".to_string(),
42+
});
43+
issue_event
44+
.issue
45+
.set_labels(&ctx.github, labels)
46+
.await?;
47+
break;
48+
}
49+
}
50+
51+
Ok(())
52+
}

0 commit comments

Comments
 (0)