File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -762,6 +762,20 @@ pub struct Repository {
762
762
impl Repository {
763
763
const GITHUB_API_URL : & ' static str = "https://api.github.com" ;
764
764
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
+
765
779
pub async fn get_issues < ' a > (
766
780
& self ,
767
781
client : & GithubClient ,
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ impl fmt::Display for HandlerError {
25
25
26
26
mod assign;
27
27
mod autolabel;
28
+ mod beta_backport;
28
29
mod close;
29
30
mod github_releases;
30
31
mod glacier;
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments