@@ -7,34 +7,18 @@ use crate::comparison::{
7
7
} ;
8
8
use crate :: load:: { SiteCtxt , TryCommit } ;
9
9
10
- use anyhow:: Context as _;
11
10
use database:: { ArtifactId , QueuedCommit } ;
12
11
use serde:: Deserialize ;
13
12
14
13
use std:: collections:: HashSet ;
15
-
16
- use std:: { fmt:: Write , sync:: Arc , time:: Duration } ;
14
+ use std:: fmt:: Write ;
17
15
18
16
type BoxedError = Box < dyn std:: error:: Error + Send + Sync > ;
19
17
20
- pub async fn get_authorized_users ( ) -> Result < Vec < usize > , String > {
21
- let url = format ! ( "{}/permissions/perf.json" , :: rust_team_data:: v1:: BASE_URL ) ;
22
- let client = reqwest:: Client :: new ( ) ;
23
- client
24
- . get ( & url)
25
- . send ( )
26
- . await
27
- . map_err ( |err| format ! ( "failed to fetch authorized users: {}" , err) ) ?
28
- . error_for_status ( )
29
- . map_err ( |err| format ! ( "failed to fetch authorized users: {}" , err) ) ?
30
- . json :: < rust_team_data:: v1:: Permission > ( )
31
- . await
32
- . map_err ( |err| format ! ( "failed to fetch authorized users: {}" , err) )
33
- . map ( |perms| perms. github_ids )
34
- }
35
-
36
18
/// Enqueues try builds on the try-perf branch for every rollup merge in `rollup_merges`.
37
19
/// Returns a mapping between the rollup merge commit and the try build sha.
20
+ ///
21
+ /// `rollup_merges` must only include actual rollup merge commits.
38
22
pub async fn enqueue_unrolled_try_builds < ' a > (
39
23
client : client:: Client ,
40
24
rollup_merges : impl Iterator < Item = & ' a Commit > ,
@@ -90,7 +74,10 @@ lazy_static::lazy_static! {
90
74
}
91
75
92
76
// Gets the pr number for the associated rollup PR message. Returns None if this is not a rollup PR
93
- pub async fn rollup_pr ( client : & client:: Client , message : & str ) -> Result < Option < u32 > , String > {
77
+ pub async fn rollup_pr_number (
78
+ client : & client:: Client ,
79
+ message : & str ,
80
+ ) -> Result < Option < u32 > , String > {
94
81
if !message. starts_with ( "Auto merge of" ) {
95
82
return Ok ( None ) ;
96
83
}
@@ -119,169 +106,6 @@ pub async fn rollup_pr(client: &client::Client, message: &str) -> Result<Option<
119
106
. then ( || issue. number ) )
120
107
}
121
108
122
- // Returns the PR number
123
- pub async fn pr_and_try_for_rollup (
124
- ctxt : Arc < SiteCtxt > ,
125
- repository_url : & str ,
126
- rollup_merge_sha : & str ,
127
- origin_url : & str ,
128
- ) -> anyhow:: Result < u32 > {
129
- let client = client:: Client :: from_ctxt ( & ctxt, repository_url. to_owned ( ) ) ;
130
- log:: trace!(
131
- "creating PR for {:?} {:?}" ,
132
- repository_url,
133
- rollup_merge_sha
134
- ) ;
135
- let branch = branch_for_rollup ( & ctxt, repository_url, rollup_merge_sha) . await ?;
136
-
137
- let pr = client
138
- . create_pr (
139
- & format ! (
140
- "[DO NOT MERGE] perf-test for #{}" ,
141
- branch. rolled_up_pr_number
142
- ) ,
143
- & format ! ( "rust-timer:{}" , branch. name) ,
144
- "master" ,
145
- & format ! (
146
- "This is an automatically generated pull request (from [here]({})) to \
147
- run perf tests for #{} which merged in a rollup.
148
-
149
- r? @ghost" ,
150
- origin_url, branch. rolled_up_pr_number
151
- ) ,
152
- true ,
153
- )
154
- . await
155
- . context ( "Created PR" ) ?;
156
-
157
- let pr_number = pr. number ;
158
- let rollup_merge_sha = rollup_merge_sha. to_owned ( ) ;
159
- tokio:: task:: spawn ( async move {
160
- // Give github time to create the merge commit reference
161
- tokio:: time:: sleep ( Duration :: from_secs ( 30 ) ) . await ;
162
- // This provides the master SHA so that we can check that we only queue
163
- // an appropriate try build. If there's ever a race condition, i.e.,
164
- // master was pushed while this command was running, the user will have to
165
- // take manual action to detect it.
166
- //
167
- // Eventually we'll want to handle this automatically, but that's a ways
168
- // off: we'd need to store the state in the database and handle the try
169
- // build starting and generally that's a lot of work for not too much gain.
170
- client
171
- . post_comment (
172
- pr. number ,
173
- & format ! (
174
- "@bors try @rust-timer queue
175
-
176
- The try commit's (master) parent should be {master}. If it isn't, \
177
- then please:
178
-
179
- * Stop this try build (`try-`).
180
- * Run `@rust-timer update-pr-for {merge}`.
181
- * Rerun `bors try`.
182
-
183
- You do not need to reinvoke the queue command as long as the perf \
184
- build hasn't yet started.",
185
- master = branch. master_base_sha,
186
- merge = rollup_merge_sha,
187
- ) ,
188
- )
189
- . await ;
190
- } ) ;
191
-
192
- Ok ( pr_number)
193
- }
194
-
195
- pub struct RollupBranch {
196
- pub master_base_sha : String ,
197
- pub rolled_up_pr_number : u32 ,
198
- pub name : String ,
199
- }
200
-
201
- pub async fn branch_for_rollup (
202
- ctxt : & SiteCtxt ,
203
- repository_url : & str ,
204
- rollup_merge_sha : & str ,
205
- ) -> anyhow:: Result < RollupBranch > {
206
- let client = client:: Client :: from_ctxt ( ctxt, repository_url. to_owned ( ) ) ;
207
- let timer = "https://api.github.com/repos/rust-timer/rust" ;
208
- let timer_client = client:: Client :: from_ctxt ( ctxt, timer. to_owned ( ) ) ;
209
- let rollup_merge = client
210
- . get_commit ( rollup_merge_sha)
211
- . await
212
- . context ( "got rollup merge" ) ?;
213
-
214
- let mut current = rollup_merge. clone ( ) ;
215
- loop {
216
- log:: trace!( "searching for auto branch, at {:?}" , current. sha) ;
217
- if current. commit . message . starts_with ( "Auto merge" ) {
218
- break ;
219
- }
220
- assert_eq ! ( current. parents. len( ) , 2 ) ;
221
- current = client
222
- . get_commit ( & current. parents [ 0 ] . sha )
223
- . await
224
- . context ( "success master get" ) ?;
225
- }
226
- let old_master_commit = current;
227
-
228
- let current_master_commit = client
229
- . get_commit ( "master" )
230
- . await
231
- . context ( "success master get" ) ?;
232
-
233
- let revert_sha = timer_client
234
- . create_commit (
235
- & format ! ( "Revert to {}" , old_master_commit. sha) ,
236
- & old_master_commit. commit . tree . sha ,
237
- & [ & current_master_commit. sha ] ,
238
- )
239
- . await
240
- . context ( "create revert" ) ?;
241
-
242
- let merge_sha = timer_client
243
- . create_commit (
244
- & format ! (
245
- "rust-timer simulated merge of {}\n \n Original message:\n {}" ,
246
- rollup_merge. sha, rollup_merge. commit. message
247
- ) ,
248
- & rollup_merge. commit . tree . sha ,
249
- & [ & revert_sha] ,
250
- )
251
- . await
252
- . context ( "create merge commit" ) ?;
253
-
254
- let rolled_up_pr_number = if let Some ( stripped) = rollup_merge
255
- . commit
256
- . message
257
- . strip_prefix ( "Rollup merge of #" )
258
- {
259
- stripped
260
- . split_whitespace ( )
261
- . next ( )
262
- . unwrap ( )
263
- . parse :: < u32 > ( )
264
- . unwrap ( )
265
- } else {
266
- anyhow:: bail!(
267
- "not a rollup merge commit: {:?}" ,
268
- rollup_merge. commit. message
269
- )
270
- } ;
271
-
272
- let branch = format ! ( "try-for-{}" , rolled_up_pr_number) ;
273
- timer_client
274
- . create_ref ( & format ! ( "refs/heads/{}" , branch) , & merge_sha)
275
- . await
276
- . context ( "created branch" ) ?;
277
-
278
- Ok ( RollupBranch {
279
- rolled_up_pr_number,
280
- master_base_sha : current_master_commit. sha ,
281
- name : branch,
282
- } )
283
- }
284
-
285
109
pub async fn enqueue_sha ( issue : Issue , ctxt : & SiteCtxt , commit : String ) -> Result < ( ) , String > {
286
110
let client = client:: Client :: from_ctxt ( ctxt, issue. repository_url . clone ( ) ) ;
287
111
let commit_response = client
0 commit comments