@@ -3,7 +3,9 @@ use std::{error::Error, fmt::Display, fs, path::PathBuf, process::Command};
33use front_matter:: FrontMatter ;
44use inquire:: { Confirm , Select , Text , validator:: Validation , Autocomplete , CustomUserError } ;
55use inquire:: autocompletion:: Replacement ;
6- use rust_team_data:: v1:: Teams ;
6+ use rust_team_data:: v1:: { Team , Teams } ;
7+
8+ const BASE_TEAM_WEBSITE_URL : & str = "https://www.rust-lang.org/governance/teams/" ;
79
810fn main ( ) -> Result < ( ) , Box < dyn Error > > {
911 println ! ( "\n Hi, thanks for writing a post for the Rust blog!\n " ) ;
@@ -91,8 +93,12 @@ fn main() -> Result<(), Box<dyn Error>> {
9193 }
9294
9395 let team = team_prompt. prompt ( ) ?;
96+
97+ let prefilled_url = team_data. as_ref ( ) . and_then ( |teams| find_team_url ( teams, & team) )
98+ . unwrap_or_else ( || BASE_TEAM_WEBSITE_URL . to_string ( ) ) ;
99+
94100 let url = Text :: new ( "At what URL can people find the team?" )
95- . with_initial_value ( "https://www.rust-lang.org/governance/teams/" )
101+ . with_initial_value ( & prefilled_url )
96102 . prompt ( ) ?;
97103 ( Some ( team) , Some ( url) )
98104 } ;
@@ -179,6 +185,24 @@ fn load_teams() -> Result<Teams, String> {
179185 Ok ( teams)
180186}
181187
188+ fn find_team_url ( teams : & Teams , team_name : & str ) -> Option < String > {
189+ let Some ( team) = teams. teams . get ( team_name) else { return None ; } ;
190+ let top_level_team = find_top_level_team ( teams, team) ;
191+
192+ // E.g. <BASE>compiler#team-miri
193+ Some ( format ! ( "{}{}#team-{team_name}" , BASE_TEAM_WEBSITE_URL , top_level_team. name) )
194+ }
195+
196+ fn find_top_level_team < ' a > ( teams : & ' a Teams , team : & ' a Team ) -> & ' a Team {
197+ if team. top_level . unwrap_or ( false ) {
198+ return team;
199+ }
200+ if let Some ( parent) = team. subteam_of . as_ref ( ) . and_then ( |t| teams. teams . get ( t) ) {
201+ return find_top_level_team ( teams, parent) ;
202+ }
203+ team
204+ }
205+
182206#[ derive( Clone ) ]
183207struct TeamNames ( Vec < String > ) ;
184208
0 commit comments