1+ use std:: collections:: BTreeMap ;
12use std:: path:: Path ;
23use std:: sync:: Arc ;
34use std:: { collections:: BTreeSet , path:: PathBuf } ;
@@ -8,7 +9,7 @@ use spanned::{Error, Result, Spanned};
89use crate :: config:: { Configuration , TeamAskDetails } ;
910use crate :: gh:: issue_id:: { IssueId , Repository } ;
1011use crate :: markwaydown:: { self , Section , Table } ;
11- use crate :: re:: { self , TASK_OWNERS_STR , TEAMS_WITH_ASKS_STR } ;
12+ use crate :: re:: { self , CHAMPION_METADATA , TASK_OWNERS_STR , TEAMS_WITH_ASKS_STR } ;
1213use crate :: team:: { self , TeamName } ;
1314use crate :: util:: { self , commas, markdown_files} ;
1415
@@ -48,6 +49,9 @@ pub struct Metadata {
4849 pub status : Spanned < Status > ,
4950 pub tracking_issue : Option < IssueId > ,
5051 pub table : Spanned < Table > ,
52+
53+ /// For each table entry like `[T-lang] champion`, we create an entry in this map
54+ pub champions : BTreeMap < & ' static TeamName , Spanned < String > > ,
5155}
5256
5357pub const TRACKING_ISSUE_ROW : & str = "Tracking issue" ;
@@ -440,6 +444,39 @@ fn extract_metadata(sections: &[Section]) -> Result<Option<Metadata>> {
440444 verify_row ( & first_table. rows , "Teams" , TEAMS_WITH_ASKS_STR ) ?;
441445 verify_row ( & first_table. rows , "Task owners" , TASK_OWNERS_STR ) ?;
442446
447+ let mut champions = BTreeMap :: default ( ) ;
448+ for row in & first_table. rows {
449+ let row_name = & row[ 0 ] ;
450+ let row_value = & row[ 1 ] ;
451+
452+ if !row_name. to_lowercase ( ) . contains ( "champion" ) {
453+ continue ;
454+ }
455+
456+ if let Some ( m) = CHAMPION_METADATA . captures ( row_name) {
457+ let team_name = m. name ( "team" ) . unwrap ( ) . as_str ( ) . to_string ( ) ;
458+
459+ let Some ( team) = team:: get_team_name ( & team_name) ? else {
460+ spanned:: bail!( row_name, "team `{team_name}` is not recognized" )
461+ } ;
462+
463+ if champions. contains_key ( team) {
464+ spanned:: bail!(
465+ row_name,
466+ "multiple rows naming champions for team `{team_name}`"
467+ )
468+ } else {
469+ champions. insert ( team, row_value. clone ( ) ) ;
470+ }
471+ } else {
472+ spanned:: bail!(
473+ row_name,
474+ "metadata row `{}` talks about champions but is not of the form `[team-name] champion`" ,
475+ & * * row_name
476+ )
477+ }
478+ }
479+
443480 Ok ( Some ( Metadata {
444481 title : title. to_string ( ) ,
445482 short_title : if let Some ( row) = short_title_row {
@@ -451,6 +488,7 @@ fn extract_metadata(sections: &[Section]) -> Result<Option<Metadata>> {
451488 status,
452489 tracking_issue : issue,
453490 table : first_table. clone ( ) ,
491+ champions,
454492 } ) )
455493}
456494
0 commit comments