@@ -3,7 +3,9 @@ use std::{error::Error, fmt::Display, fs, path::PathBuf, process::Command};
3
3
use front_matter:: FrontMatter ;
4
4
use inquire:: { Confirm , Select , Text , validator:: Validation , Autocomplete , CustomUserError } ;
5
5
use 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/" ;
7
9
8
10
fn main ( ) -> Result < ( ) , Box < dyn Error > > {
9
11
println ! ( "\n Hi, thanks for writing a post for the Rust blog!\n " ) ;
@@ -91,8 +93,12 @@ fn main() -> Result<(), Box<dyn Error>> {
91
93
}
92
94
93
95
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
+
94
100
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 )
96
102
. prompt ( ) ?;
97
103
( Some ( team) , Some ( url) )
98
104
} ;
@@ -179,6 +185,24 @@ fn load_teams() -> Result<Teams, String> {
179
185
Ok ( teams)
180
186
}
181
187
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
+
182
206
#[ derive( Clone ) ]
183
207
struct TeamNames ( Vec < String > ) ;
184
208
0 commit comments