@@ -6,7 +6,6 @@ use crate::comparison::{
6
6
ArtifactComparisonSummary , Direction , Metric ,
7
7
} ;
8
8
use crate :: load:: { SiteCtxt , TryCommit } ;
9
- use client:: * ;
10
9
11
10
use anyhow:: Context as _;
12
11
use database:: { ArtifactId , QueuedCommit } ;
@@ -36,40 +35,38 @@ pub async fn get_authorized_users() -> Result<Vec<usize>, String> {
36
35
37
36
// Returns the PR number
38
37
pub async fn pr_and_try_for_rollup (
39
- client : & reqwest:: Client ,
40
38
ctxt : Arc < SiteCtxt > ,
41
39
repository_url : & str ,
42
40
rollup_merge_sha : & str ,
43
41
origin_url : & str ,
44
42
) -> anyhow:: Result < u32 > {
43
+ let client = client:: Client :: from_ctxt ( & ctxt, repository_url. to_owned ( ) ) ;
45
44
log:: trace!(
46
45
"creating PR for {:?} {:?}" ,
47
46
repository_url,
48
47
rollup_merge_sha
49
48
) ;
50
- let branch = branch_for_rollup ( client , & ctxt, repository_url, rollup_merge_sha) . await ?;
49
+ let branch = branch_for_rollup ( & ctxt, repository_url, rollup_merge_sha) . await ?;
51
50
52
- let pr = create_pr (
53
- client,
54
- & ctxt,
55
- repository_url,
56
- & format ! (
57
- "[DO NOT MERGE] perf-test for #{}" ,
58
- branch. rolled_up_pr_number
59
- ) ,
60
- & format ! ( "rust-timer:{}" , branch. name) ,
61
- "master" ,
62
- & format ! (
63
- "This is an automatically generated pull request (from [here]({})) to \
51
+ let pr = client
52
+ . create_pr (
53
+ & format ! (
54
+ "[DO NOT MERGE] perf-test for #{}" ,
55
+ branch. rolled_up_pr_number
56
+ ) ,
57
+ & format ! ( "rust-timer:{}" , branch. name) ,
58
+ "master" ,
59
+ & format ! (
60
+ "This is an automatically generated pull request (from [here]({})) to \
64
61
run perf tests for #{} which merged in a rollup.
65
62
66
63
r? @ghost" ,
67
- origin_url, branch. rolled_up_pr_number
68
- ) ,
69
- true ,
70
- )
71
- . await
72
- . context ( "Created PR" ) ?;
64
+ origin_url, branch. rolled_up_pr_number
65
+ ) ,
66
+ true ,
67
+ )
68
+ . await
69
+ . context ( "Created PR" ) ?;
73
70
74
71
let pr_number = pr. number ;
75
72
let rollup_merge_sha = rollup_merge_sha. to_owned ( ) ;
@@ -84,11 +81,11 @@ r? @ghost",
84
81
// Eventually we'll want to handle this automatically, but that's a ways
85
82
// off: we'd need to store the state in the database and handle the try
86
83
// build starting and generally that's a lot of work for not too much gain.
87
- post_comment (
88
- & ctxt . config ,
89
- pr. number ,
90
- & format ! (
91
- "@bors try @rust-timer queue
84
+ client
85
+ . post_comment (
86
+ pr. number ,
87
+ & format ! (
88
+ "@bors try @rust-timer queue
92
89
93
90
The try commit's (master) parent should be {master}. If it isn't, \
94
91
then please:
@@ -99,11 +96,11 @@ then please:
99
96
100
97
You do not need to reinvoke the queue command as long as the perf \
101
98
build hasn't yet started.",
102
- master = branch. master_base_sha,
103
- merge = rollup_merge_sha,
104
- ) ,
105
- )
106
- . await ;
99
+ master = branch. master_base_sha,
100
+ merge = rollup_merge_sha,
101
+ ) ,
102
+ )
103
+ . await ;
107
104
} ) ;
108
105
109
106
Ok ( pr_number)
@@ -116,12 +113,15 @@ pub struct RollupBranch {
116
113
}
117
114
118
115
pub async fn branch_for_rollup (
119
- client : & reqwest:: Client ,
120
116
ctxt : & SiteCtxt ,
121
117
repository_url : & str ,
122
118
rollup_merge_sha : & str ,
123
119
) -> anyhow:: Result < RollupBranch > {
124
- let rollup_merge = get_commit ( & client, & ctxt, repository_url, rollup_merge_sha)
120
+ let client = client:: Client :: from_ctxt ( ctxt, repository_url. to_owned ( ) ) ;
121
+ let timer = "https://api.github.com/repos/rust-timer/rust" ;
122
+ let timer_client = client:: Client :: from_ctxt ( ctxt, timer. to_owned ( ) ) ;
123
+ let rollup_merge = client
124
+ . get_commit ( rollup_merge_sha)
125
125
. await
126
126
. context ( "got rollup merge" ) ?;
127
127
@@ -132,40 +132,38 @@ pub async fn branch_for_rollup(
132
132
break ;
133
133
}
134
134
assert_eq ! ( current. parents. len( ) , 2 ) ;
135
- current = get_commit ( & client, & ctxt, repository_url, & current. parents [ 0 ] . sha )
135
+ current = client
136
+ . get_commit ( & current. parents [ 0 ] . sha )
136
137
. await
137
138
. context ( "success master get" ) ?;
138
139
}
139
140
let old_master_commit = current;
140
141
141
- let current_master_commit = get_commit ( & client, & ctxt, repository_url, "master" )
142
+ let current_master_commit = client
143
+ . get_commit ( "master" )
142
144
. await
143
145
. context ( "success master get" ) ?;
144
146
145
- let revert_sha = create_commit (
146
- & client,
147
- & ctxt,
148
- "https://api.github.com/repos/rust-timer/rust" ,
149
- & format ! ( "Revert to {}" , old_master_commit. sha) ,
150
- & old_master_commit. commit . tree . sha ,
151
- & [ & current_master_commit. sha ] ,
152
- )
153
- . await
154
- . context ( "create revert" ) ?;
155
-
156
- let merge_sha = create_commit (
157
- & client,
158
- & ctxt,
159
- "https://api.github.com/repos/rust-timer/rust" ,
160
- & format ! (
161
- "rust-timer simulated merge of {}\n \n Original message:\n {}" ,
162
- rollup_merge. sha, rollup_merge. commit. message
163
- ) ,
164
- & rollup_merge. commit . tree . sha ,
165
- & [ & revert_sha] ,
166
- )
167
- . await
168
- . context ( "create merge commit" ) ?;
147
+ let revert_sha = timer_client
148
+ . create_commit (
149
+ & format ! ( "Revert to {}" , old_master_commit. sha) ,
150
+ & old_master_commit. commit . tree . sha ,
151
+ & [ & current_master_commit. sha ] ,
152
+ )
153
+ . await
154
+ . context ( "create revert" ) ?;
155
+
156
+ let merge_sha = timer_client
157
+ . create_commit (
158
+ & format ! (
159
+ "rust-timer simulated merge of {}\n \n Original message:\n {}" ,
160
+ rollup_merge. sha, rollup_merge. commit. message
161
+ ) ,
162
+ & rollup_merge. commit . tree . sha ,
163
+ & [ & revert_sha] ,
164
+ )
165
+ . await
166
+ . context ( "create merge commit" ) ?;
169
167
170
168
let rolled_up_pr_number = if let Some ( stripped) = rollup_merge
171
169
. commit
@@ -186,15 +184,10 @@ pub async fn branch_for_rollup(
186
184
} ;
187
185
188
186
let branch = format ! ( "try-for-{}" , rolled_up_pr_number) ;
189
- create_ref (
190
- & client,
191
- & ctxt,
192
- "https://api.github.com/repos/rust-timer/rust" ,
193
- & format ! ( "refs/heads/{}" , branch) ,
194
- & merge_sha,
195
- )
196
- . await
197
- . context ( "created branch" ) ?;
187
+ timer_client
188
+ . create_ref ( & format ! ( "refs/heads/{}" , branch) , & merge_sha)
189
+ . await
190
+ . context ( "created branch" ) ?;
198
191
199
192
Ok ( RollupBranch {
200
193
rolled_up_pr_number,
@@ -204,8 +197,9 @@ pub async fn branch_for_rollup(
204
197
}
205
198
206
199
pub async fn enqueue_sha ( issue : Issue , ctxt : & SiteCtxt , commit : String ) -> Result < ( ) , String > {
207
- let client = reqwest:: Client :: new ( ) ;
208
- let commit_response = get_commit ( & client, ctxt, & issue. repository_url , & commit)
200
+ let client = client:: Client :: from_ctxt ( ctxt, issue. repository_url . clone ( ) ) ;
201
+ let commit_response = client
202
+ . get_commit ( & commit)
209
203
. await
210
204
. map_err ( |e| e. to_string ( ) ) ?;
211
205
if commit_response. parents . len ( ) != 2 {
@@ -237,7 +231,7 @@ pub async fn enqueue_sha(issue: Issue, ctxt: &SiteCtxt, commit: String) -> Resul
237
231
commit_response. parents[ 0 ] . sha,
238
232
try_commit. comparison_url( ) ,
239
233
) ;
240
- post_comment ( & ctxt . config , issue. number , msg) . await ;
234
+ client . post_comment ( issue. number , msg) . await ;
241
235
}
242
236
Ok ( ( ) )
243
237
}
@@ -331,13 +325,14 @@ pub async fn post_finished(ctxt: &SiteCtxt) {
331
325
///
332
326
/// `is_master_commit` is used to differentiate messages for try runs and post-merge runs.
333
327
async fn post_comparison_comment ( ctxt : & SiteCtxt , commit : QueuedCommit , is_master_commit : bool ) {
328
+ let client = client:: Client :: from_ctxt ( ctxt, "https://github.com/rust-lang/rust" . to_owned ( ) ) ;
334
329
let pr = commit. pr ;
335
330
let body = match summarize_run ( ctxt, commit, is_master_commit) . await {
336
331
Ok ( message) => message,
337
332
Err ( error) => error,
338
333
} ;
339
334
340
- post_comment ( & ctxt . config , pr, body) . await ;
335
+ client . post_comment ( pr, body) . await ;
341
336
}
342
337
343
338
fn make_comparison_url ( commit : & QueuedCommit , stat : Metric ) -> String {
0 commit comments