@@ -8,7 +8,7 @@ use std::io::Write;
88use std:: path:: Path ;
99use std:: process:: { Command , Stdio } ;
1010
11- use crate :: templates:: { self , HelpWanted , Updates , UpdatesGoal } ;
11+ use crate :: templates:: { self , HelpWanted , UpdatesGoal } ;
1212use rust_project_goals:: gh:: issues:: ExistingGithubIssue ;
1313use rust_project_goals:: gh:: {
1414 issue_id:: { IssueId , Repository } ,
@@ -44,11 +44,9 @@ pub async fn updates(
4444 progress_bar:: Style :: Bold ,
4545 ) ;
4646
47- let mut updates = templates:: Updates {
48- milestone : milestone. to_string ( ) ,
49- flagship_goals : prepare_goals ( repository, & issues, & filter, true ) . await ?,
50- other_goals : prepare_goals ( repository, & issues, & filter, false ) . await ?,
51- } ;
47+ let flagship_goals = prepare_goals ( repository, & issues, & filter, true ) . await ?;
48+ let other_goals = prepare_goals ( repository, & issues, & filter, false ) . await ?;
49+ let updates = templates:: Updates :: new ( milestone. to_string ( ) , flagship_goals, other_goals) ;
5250
5351 progress_bar:: finalize_progress_bar ( ) ;
5452
@@ -113,13 +111,22 @@ async fn prepare_goals(
113111 let mut comments = issue. comments . clone ( ) ;
114112 comments. sort_by_key ( |c| c. created_at . clone ( ) ) ;
115113 comments. retain ( |c| !c. is_automated_comment ( ) && filter. matches ( c) ) ;
114+ // Prettify the comments' timestamp after using it for sorting.
115+ for comment in comments. iter_mut ( ) {
116+ comment. created_at = format ! ( "{}" , comment. created_at_date( ) ) ;
117+ }
116118
117119 let tldr = tldr ( & issue_id, & mut comments) ?;
118120
119121 let ( has_help_wanted, help_wanted) = help_wanted ( & issue_id, & tldr, & comments) ?;
120122
121123 let why_this_goal = why_this_goal ( & issue_id, issue) ?;
122124
125+ let details_summary = match comments. len ( ) {
126+ 0 => String :: from ( "No updates posted." ) ,
127+ 1 => String :: from ( "1 update posted." ) ,
128+ len => format ! ( "{len} updates posted." ) ,
129+ } ;
123130 result. push ( UpdatesGoal {
124131 title : title. clone ( ) ,
125132 issue_number : issue. number ,
@@ -129,14 +136,24 @@ async fn prepare_goals(
129136 has_help_wanted,
130137 help_wanted,
131138 is_closed : issue. state == GithubIssueState :: Closed ,
132- num_comments : comments . len ( ) ,
139+ details_summary ,
133140 comments,
134141 tldr,
135142 why_this_goal,
143+ needs_separator : true , // updated after sorting
136144 } ) ;
137145
138146 progress_bar:: inc_progress_bar ( ) ;
139147 }
148+
149+ // Updates are in a random order, sort them.
150+ result. sort_by_cached_key ( |update| update. title . to_lowercase ( ) ) ;
151+
152+ // Mark the last entry as not needing a separator from its following sibling, it has none.
153+ if let Some ( last) = result. last_mut ( ) {
154+ last. needs_separator = false ;
155+ }
156+
140157 Ok ( result)
141158}
142159
@@ -163,7 +180,11 @@ fn help_wanted(
163180
164181 let mut help_wanted = vec ! [ ] ;
165182
166- let tldr_has_help_wanted = tldr. as_deref ( ) . unwrap_or ( "" ) . lines ( ) . any ( |line| HELP_WANTED . is_match ( line) ) ;
183+ let tldr_has_help_wanted = tldr
184+ . as_deref ( )
185+ . unwrap_or ( "" )
186+ . lines ( )
187+ . any ( |line| HELP_WANTED . is_match ( line) ) ;
167188
168189 for comment in comments {
169190 let mut lines = comment. body . split ( '\n' ) . peekable ( ) ;
@@ -174,8 +195,8 @@ fn help_wanted(
174195 while let Some ( line) = lines. next ( ) {
175196 if let Some ( c) = HELP_WANTED . captures ( line) {
176197 help_wanted. push ( HelpWanted {
177- text : c[ "text" ] . to_string ( )
178- } ) ;
198+ text : c[ "text" ] . to_string ( ) ,
199+ } ) ;
179200 break ;
180201 }
181202 }
@@ -194,10 +215,7 @@ fn help_wanted(
194215 Ok ( ( tldr_has_help_wanted || !help_wanted. is_empty ( ) , help_wanted) )
195216}
196217
197- fn why_this_goal (
198- issue_id : & IssueId ,
199- issue : & ExistingGithubIssue ,
200- ) -> anyhow:: Result < String > {
218+ fn why_this_goal ( issue_id : & IssueId , issue : & ExistingGithubIssue ) -> anyhow:: Result < String > {
201219 let sections = markwaydown:: parse_text ( issue_id. url ( ) , & issue. body ) ?;
202220 for section in sections {
203221 if section. title == "Why this goal?" {
0 commit comments