11use std:: { future:: Future , pin:: Pin } ;
22
3- use bencher_client:: types:: { Adapter , JsonAverage , JsonFold , JsonNewReport , JsonReportSettings } ;
3+ use bencher_client:: types:: { Adapter , JsonAverage , JsonFold , JsonNewRun , JsonReportSettings } ;
44use bencher_comment:: ReportComment ;
5- use bencher_json:: { DateTime , JsonReport , NameId , ResourceId } ;
5+ use bencher_json:: { DateTime , JsonReport , NameId , ResourceId , RunContext } ;
66
77use crate :: {
8- bencher:: backend:: AuthBackend ,
8+ bencher:: backend:: PubBackend ,
99 cli_eprintln_quietable, cli_println, cli_println_quietable,
1010 parser:: run:: { CliRun , CliRunOutput } ,
1111 CliError ,
@@ -32,9 +32,9 @@ use super::project::report::Thresholds;
3232#[ derive( Debug ) ]
3333#[ allow( clippy:: struct_excessive_bools) ]
3434pub struct Run {
35- project : ResourceId ,
35+ project : Option < ResourceId > ,
3636 branch : Branch ,
37- testbed : NameId ,
37+ testbed : Option < NameId > ,
3838 adapter : Adapter ,
3939 sub_adapter : SubAdapter ,
4040 average : Option < JsonAverage > ,
@@ -50,7 +50,7 @@ pub struct Run {
5050 runner : Runner ,
5151 #[ allow( clippy:: struct_field_names) ]
5252 dry_run : bool ,
53- backend : AuthBackend ,
53+ backend : PubBackend ,
5454}
5555
5656impl TryFrom < CliRun > for Run {
@@ -76,9 +76,9 @@ impl TryFrom<CliRun> for Run {
7676 backend,
7777 } = run;
7878 Ok ( Self {
79- project,
79+ project : project . map ( Into :: into ) ,
8080 branch : branch. try_into ( ) . map_err ( RunError :: Branch ) ?,
81- testbed,
81+ testbed : testbed . map ( Into :: into ) ,
8282 adapter : adapter. into ( ) ,
8383 sub_adapter : ( & cmd) . into ( ) ,
8484 average : average. map ( Into :: into) ,
@@ -93,7 +93,7 @@ impl TryFrom<CliRun> for Run {
9393 ci : ci. try_into ( ) . map_err ( RunError :: Ci ) ?,
9494 runner : cmd. try_into ( ) ?,
9595 dry_run,
96- backend : AuthBackend :: try_from ( backend) ?. log ( false ) ,
96+ backend : PubBackend :: try_from ( backend) ?. log ( false ) ,
9797 } )
9898 }
9999}
@@ -119,23 +119,23 @@ impl Run {
119119 ci. safety_check ( self . log ) ?;
120120 }
121121
122- let Some ( json_new_report ) = self . generate_report ( ) . await ? else {
122+ let Some ( json_new_run ) = self . generate_report ( ) . await ? else {
123123 return Ok ( ( ) ) ;
124124 } ;
125125
126126 cli_println_quietable ! ( self . log, "\n Bencher New Report:" ) ;
127127 cli_println_quietable ! (
128128 self . log,
129129 "{}" ,
130- serde_json:: to_string_pretty( & json_new_report ) . map_err( RunError :: SerializeReport ) ?
130+ serde_json:: to_string_pretty( & json_new_run ) . map_err( RunError :: SerializeReport ) ?
131131 ) ;
132132
133133 // If performing a dry run, don't actually send the report
134134 if self . dry_run {
135135 return Ok ( ( ) ) ;
136136 }
137137
138- let sender = report_sender ( self . project . clone ( ) , json_new_report ) ;
138+ let sender = run_sender ( json_new_run ) ;
139139 let json_report: JsonReport = self
140140 . backend
141141 . send_with ( sender)
@@ -152,7 +152,7 @@ impl Run {
152152 }
153153 }
154154
155- async fn generate_report ( & self ) -> Result < Option < JsonNewReport > , RunError > {
155+ async fn generate_report ( & self ) -> Result < Option < JsonNewRun > , RunError > {
156156 let start_time = DateTime :: now ( ) ;
157157 let mut results = Vec :: with_capacity ( self . iter ) ;
158158 for _ in 0 ..self . iter {
@@ -184,11 +184,12 @@ impl Run {
184184 } ;
185185
186186 let ( branch, hash, start_point) = self . branch . clone ( ) . into ( ) ;
187- Ok ( Some ( JsonNewReport {
187+ Ok ( Some ( JsonNewRun {
188+ project : self . project . clone ( ) . map ( Into :: into) ,
188189 branch,
189190 hash,
190191 start_point,
191- testbed : self . testbed . clone ( ) . into ( ) ,
192+ testbed : self . testbed . clone ( ) . map ( Into :: into ) ,
192193 thresholds : self . thresholds . clone ( ) . into ( ) ,
193194 start_time : start_time. into ( ) ,
194195 end_time : end_time. into ( ) ,
@@ -198,8 +199,7 @@ impl Run {
198199 average : self . average ,
199200 fold : self . fold ,
200201 } ) ,
201- // TODO add context when we move over to JsonNewRun
202- // context: Some(RunContext::current().into()),
202+ context : Some ( RunContext :: current ( ) . into ( ) ) ,
203203 } ) )
204204 }
205205
@@ -242,20 +242,11 @@ type ReportResult = Pin<
242242 > + Send ,
243243 > ,
244244> ;
245- fn report_sender (
246- project : ResourceId ,
247- json_new_report : JsonNewReport ,
245+ fn run_sender (
246+ json_new_run : JsonNewRun ,
248247) -> Box < dyn Fn ( bencher_client:: Client ) -> ReportResult + Send > {
249248 Box :: new ( move |client : bencher_client:: Client | {
250- let project = project. clone ( ) ;
251- let json_new_report = json_new_report. clone ( ) ;
252- Box :: pin ( async move {
253- client
254- . proj_report_post ( )
255- . project ( project. clone ( ) )
256- . body ( json_new_report. clone ( ) )
257- . send ( )
258- . await
259- } )
249+ let json_new_run = json_new_run. clone ( ) ;
250+ Box :: pin ( async move { client. run_post ( ) . body ( json_new_run. clone ( ) ) . send ( ) . await } )
260251 } )
261252}
0 commit comments