@@ -12,6 +12,8 @@ use regex::{Captures, Regex};
12
12
lazy_static:: lazy_static! {
13
13
static ref ROLLUP_PR_NUMBER : Regex =
14
14
Regex :: new( r#"^Auto merge of #(\d+)"# ) . unwrap( ) ;
15
+ static ref ROLLUPED_PR_NUMBER : Regex =
16
+ Regex :: new( r#"^Rollup merge of #(\d+)"# ) . unwrap( ) ;
15
17
static ref BODY_TRY_COMMIT : Regex =
16
18
Regex :: new( r#"(?:\W|^)@rust-timer\s+build\s+(\w+)(?:\W|$)(?:include=(\S+))?\s*(?:exclude=(\S+))?\s*(?:runs=(\d+))?"# ) . unwrap( ) ;
17
19
static ref BODY_QUEUE : Regex =
@@ -36,32 +38,50 @@ pub async fn handle_github(
36
38
async fn handle_push ( ctxt : Arc < SiteCtxt > , push : github:: Push ) -> ServerResult < github:: Response > {
37
39
let client = reqwest:: Client :: new ( ) ;
38
40
let repository_url = "https://github.com/rust-lang-ci/rust" ;
39
- if push. r#ref != "refs/heads/master"
40
- || !is_rollup ( & client, & ctxt, repository_url, & push) . await ?
41
- {
41
+ if push. r#ref != "refs/heads/master" {
42
42
return Ok ( github:: Response ) ;
43
43
}
44
+ let pr = rollup_pr ( & client, & ctxt, repository_url, & push) . await ?;
45
+ let pr = match pr {
46
+ Some ( pr) => pr,
47
+ None => return Ok ( github:: Response ) ,
48
+ } ;
44
49
45
50
let previous_master = & push. before ;
46
51
let rollup_merges = push
47
52
. commits
48
53
. iter ( )
49
54
. rev ( )
50
55
. skip ( 1 ) // skip the head commit
51
- . take_while ( |c| c. message . starts_with ( "Rollup merge of " ) )
52
- . map ( |c| & c. sha ) ;
56
+ . take_while ( |c| c. message . starts_with ( "Rollup merge of " ) ) ;
53
57
58
+ let mut prs = Vec :: new ( ) ;
54
59
for rollup_merge in rollup_merges {
60
+ let pr_num = ROLLUPED_PR_NUMBER
61
+ . captures ( & rollup_merge. message )
62
+ . and_then ( |c| c. get ( 0 ) )
63
+ . map ( |m| m. as_str ( ) )
64
+ . ok_or_else ( || {
65
+ format ! (
66
+ "Could not get PR number from message: '{}'" ,
67
+ rollup_merge. message
68
+ )
69
+ } ) ?;
55
70
// Fetch the rollup merge commit which should have two parents.
56
71
// The first parent is in the chain of rollup merge commits all the way back to `previous_master`.
57
72
// The second parent is the head of the PR that was rolled up. We want the second parent.
58
- let commit = get_commit ( & client, & ctxt, repository_url, & rollup_merge)
73
+ let commit = get_commit ( & client, & ctxt, repository_url, & rollup_merge. sha )
59
74
. await
60
- . map_err ( |e| format ! ( "Error getting rollup merge commit '{rollup_merge}': {e:?}" ) ) ?;
75
+ . map_err ( |e| {
76
+ format ! (
77
+ "Error getting rollup merge commit '{}': {e:?}" ,
78
+ rollup_merge. sha
79
+ )
80
+ } ) ?;
61
81
assert ! (
62
82
commit. parents. len( ) == 2 ,
63
83
"What we thought was a merge commit was not a merge commit. sha: {}" ,
64
- rollup_merge
84
+ rollup_merge. sha
65
85
) ;
66
86
let rolled_up_head = & commit. parents [ 1 ] . sha ;
67
87
@@ -87,31 +107,45 @@ async fn handle_push(ctxt: Arc<SiteCtxt>, push: github::Push) -> ServerResult<gi
87
107
. await
88
108
. map_err ( |e| format ! ( "Error updating the try-perf branch: {e:?}" ) ) ?;
89
109
110
+ prs. push ( ( pr_num, sha) ) ;
90
111
// Wait to ensure there's enough time for GitHub to checkout these changes before they are overwritten
91
112
tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 15 ) ) . await
92
113
}
114
+
115
+ // Post comment to the rollup PR with the mapping between individual PRs and the new try commits
116
+ let mapping = prs
117
+ . into_iter ( )
118
+ . fold ( String :: new ( ) , |mut string, ( pr, commit) | {
119
+ use std:: fmt:: Write ;
120
+ write ! ( & mut string, "#{pr}: {commit}\n " ) . unwrap ( ) ;
121
+ string
122
+ } ) ;
123
+ let msg =
124
+ format ! ( "Try perf builds for each individual rolled up PR have been enqueued:\n {mapping}" ) ;
125
+ post_comment ( & ctxt. config , pr, msg) . await ;
93
126
Ok ( github:: Response )
94
127
}
95
128
96
- async fn is_rollup (
129
+ // Gets the pr number for the associated rollup PR. Returns None if this is not a rollup PR
130
+ async fn rollup_pr (
97
131
client : & reqwest:: Client ,
98
132
ctxt : & SiteCtxt ,
99
133
repository_url : & str ,
100
134
push : & github:: Push ,
101
- ) -> ServerResult < bool > {
135
+ ) -> ServerResult < Option < u32 > > {
102
136
macro_rules! get {
103
137
( $x: expr) => {
104
138
match $x {
105
139
Some ( x) => x,
106
- None => return Ok ( false ) ,
140
+ None => return Ok ( None ) ,
107
141
}
108
142
} ;
109
143
}
110
144
let is_bors =
111
145
push. sender . login == "bors" && push. head_commit . message . starts_with ( "Auto merge of" ) ;
112
146
113
147
if !is_bors {
114
- return Ok ( false ) ;
148
+ return Ok ( None ) ;
115
149
}
116
150
let captures = get ! ( ROLLUP_PR_NUMBER . captures( & push. head_commit. message) ) ;
117
151
let number = get ! ( get!( captures. get( 0 ) ) . as_str( ) . parse:: <u64 >( ) . ok( ) ) ;
@@ -120,7 +154,11 @@ async fn is_rollup(
120
154
. await
121
155
. map_err ( |e| format ! ( "Error fetching PR #{number} {e:?}" ) ) ?;
122
156
123
- Ok ( issue. labels . iter ( ) . any ( |l| l. name == "rollup" ) )
157
+ Ok ( issue
158
+ . labels
159
+ . iter ( )
160
+ . any ( |l| l. name == "rollup" )
161
+ . then ( || issue. number ) )
124
162
}
125
163
126
164
async fn handle_issue (
0 commit comments