@@ -8,7 +8,7 @@ use std::io::Write;
8
8
use std:: path:: Path ;
9
9
use std:: process:: { Command , Stdio } ;
10
10
11
- use crate :: templates:: { self , HelpWanted , Updates , UpdatesGoal } ;
11
+ use crate :: templates:: { self , HelpWanted , UpdatesGoal } ;
12
12
use rust_project_goals:: gh:: issues:: ExistingGithubIssue ;
13
13
use rust_project_goals:: gh:: {
14
14
issue_id:: { IssueId , Repository } ,
@@ -44,11 +44,9 @@ pub async fn updates(
44
44
progress_bar:: Style :: Bold ,
45
45
) ;
46
46
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) ;
52
50
53
51
progress_bar:: finalize_progress_bar ( ) ;
54
52
@@ -113,13 +111,22 @@ async fn prepare_goals(
113
111
let mut comments = issue. comments . clone ( ) ;
114
112
comments. sort_by_key ( |c| c. created_at . clone ( ) ) ;
115
113
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
+ }
116
118
117
119
let tldr = tldr ( & issue_id, & mut comments) ?;
118
120
119
121
let ( has_help_wanted, help_wanted) = help_wanted ( & issue_id, & tldr, & comments) ?;
120
122
121
123
let why_this_goal = why_this_goal ( & issue_id, issue) ?;
122
124
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
+ } ;
123
130
result. push ( UpdatesGoal {
124
131
title : title. clone ( ) ,
125
132
issue_number : issue. number ,
@@ -129,14 +136,24 @@ async fn prepare_goals(
129
136
has_help_wanted,
130
137
help_wanted,
131
138
is_closed : issue. state == GithubIssueState :: Closed ,
132
- num_comments : comments . len ( ) ,
139
+ details_summary ,
133
140
comments,
134
141
tldr,
135
142
why_this_goal,
143
+ needs_separator : true , // updated after sorting
136
144
} ) ;
137
145
138
146
progress_bar:: inc_progress_bar ( ) ;
139
147
}
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
+
140
157
Ok ( result)
141
158
}
142
159
@@ -163,7 +180,11 @@ fn help_wanted(
163
180
164
181
let mut help_wanted = vec ! [ ] ;
165
182
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) ) ;
167
188
168
189
for comment in comments {
169
190
let mut lines = comment. body . split ( '\n' ) . peekable ( ) ;
@@ -174,8 +195,8 @@ fn help_wanted(
174
195
while let Some ( line) = lines. next ( ) {
175
196
if let Some ( c) = HELP_WANTED . captures ( line) {
176
197
help_wanted. push ( HelpWanted {
177
- text : c[ "text" ] . to_string ( )
178
- } ) ;
198
+ text : c[ "text" ] . to_string ( ) ,
199
+ } ) ;
179
200
break ;
180
201
}
181
202
}
@@ -194,10 +215,7 @@ fn help_wanted(
194
215
Ok ( ( tldr_has_help_wanted || !help_wanted. is_empty ( ) , help_wanted) )
195
216
}
196
217
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 > {
201
219
let sections = markwaydown:: parse_text ( issue_id. url ( ) , & issue. body ) ?;
202
220
for section in sections {
203
221
if section. title == "Why this goal?" {
0 commit comments