1
- use anyhow:: Result ;
2
1
use chrono:: { Duration , NaiveDateTime } ;
2
+ use color_eyre:: {
3
+ eyre:: { Result , WrapErr } ,
4
+ Section , SectionExt ,
5
+ } ;
3
6
use itertools:: Itertools ;
4
7
use reqwest:: header:: { AUTHORIZATION , USER_AGENT } ;
5
8
use serde:: de:: { DeserializeOwned , Deserializer } ;
@@ -124,6 +127,7 @@ impl Generator {
124
127
. labels ( & [ "T-libs-api" , "stable-nominated" ] )
125
128
. labels ( & [ "T-libs" , "beta-nominated" ] )
126
129
. labels ( & [ "T-libs-api" , "beta-nominated" ] )
130
+ . exclude_labels ( & [ "beta-accepted" ] )
127
131
. state ( State :: Any )
128
132
. repo ( "rust-lang/rust" )
129
133
. repo ( "rust-lang/rfcs" )
@@ -410,6 +414,7 @@ impl Sort {
410
414
struct GithubQuery {
411
415
name : & ' static str ,
412
416
labels : Vec < & ' static [ & ' static str ] > ,
417
+ excluded_labels : Vec < & ' static [ & ' static str ] > ,
413
418
repos : Vec < & ' static str > ,
414
419
sort : Option < Sort > ,
415
420
count : Option < usize > ,
@@ -446,6 +451,7 @@ impl GithubQuery {
446
451
Self {
447
452
name,
448
453
labels : vec ! [ ] ,
454
+ excluded_labels : vec ! [ ] ,
449
455
repos : vec ! [ ] ,
450
456
sort : None ,
451
457
count : None ,
@@ -458,6 +464,11 @@ impl GithubQuery {
458
464
self
459
465
}
460
466
467
+ fn exclude_labels ( & mut self , labels : & ' static [ & ' static str ] ) -> & mut Self {
468
+ self . excluded_labels . push ( labels) ;
469
+ self
470
+ }
471
+
461
472
fn repo ( & mut self , repo : & ' static str ) -> & mut Self {
462
473
self . repos . push ( repo) ;
463
474
self
@@ -497,6 +508,23 @@ impl GithubQuery {
497
508
498
509
let issues = github_api ( & endpoint) ?;
499
510
let issues = generator. dedup ( issues) ;
511
+
512
+ let excluded_labels: BTreeSet < _ > = self
513
+ . excluded_labels
514
+ . iter ( )
515
+ . flat_map ( |labels| labels. iter ( ) )
516
+ . map ( |s| s. to_string ( ) )
517
+ . collect ( ) ;
518
+ let issues = issues. filter ( |issue| {
519
+ for excluded_label in & excluded_labels {
520
+ if issue. labels . contains ( & excluded_label) {
521
+ return false ;
522
+ }
523
+ }
524
+
525
+ true
526
+ } ) ;
527
+
500
528
let issues: Vec < _ > = if let Some ( count) = self . count {
501
529
issues. take ( count) . collect ( )
502
530
} else {
@@ -585,7 +613,10 @@ fn github_api<T: DeserializeOwned>(endpoint: &str) -> Result<T> {
585
613
client = client. header ( AUTHORIZATION , format ! ( "token {}" , token) ) ;
586
614
}
587
615
let response = client. send ( ) ?;
588
- Ok ( response. json ( ) ?)
616
+ let response = response. text ( ) ?;
617
+ Ok ( serde_json:: from_str ( & response)
618
+ . wrap_err ( "response body cannot be deserialized" )
619
+ . with_section ( || response. header ( "Response:" ) ) ?)
589
620
}
590
621
591
622
fn deserialize_labels < ' de , D : Deserializer < ' de > > ( d : D ) -> Result < Vec < String > , D :: Error > {
0 commit comments