Skip to content

Commit 17e9a3e

Browse files
committed
Show comments in team reports in reverse chronological order
This introduces the `Order` enum which lets you choose between displaying GitHub comments ("detailed updates") in either chronological (oldest first i.e. what we used to do until now) or reverse chronological (newest first) order. The team reports now show updates in the reverse chronological order -- so that you can more easily look at the new stuff that was added. Everything else (e.g. the blog posts) still uses the regular chronological order.
1 parent c817d3f commit 17e9a3e

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

crates/mdbook-goals/src/mdbook_preprocessor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rust_project_goals::format_champions::format_champions;
1313
use rust_project_goals::format_team_ask::format_team_asks;
1414
use rust_project_goals::markdown_processor::{MarkdownProcessor, MarkdownProcessorState};
1515
use rust_project_goals::util;
16+
use rust_project_goals_cli::Order;
1617

1718
use rust_project_goals::spanned::Spanned;
1819
use rust_project_goals::{
@@ -704,6 +705,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {
704705
&Some(end_date),
705706
None,
706707
false,
708+
Order::OldestFirst,
707709
)
708710
.map_err(|e| anyhow::anyhow!("Failed to generate blog post content: {}", e))?;
709711

@@ -750,6 +752,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {
750752
&Some(end_date),
751753
Some(team_name),
752754
false,
755+
Order::NewestFirst,
753756
)
754757
.map_err(|e| anyhow::anyhow!("Failed to generate champion report content: {}", e))?;
755758

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod updates;
22

3-
pub use updates::render_updates;
3+
pub use updates::{Order, render_updates};

crates/rust-project-goals-cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ fn generate_updates(
238238
end_date,
239239
with_champion_from,
240240
true,
241+
updates::Order::default(),
241242
)?;
242243

243244
if let Some(output_file) = output_file {

crates/rust-project-goals-cli/src/updates.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ use rust_project_goals::gh::{
1515
};
1616
use templates::{HelpWanted, UpdatesGoal};
1717

18+
#[derive(Copy, Clone, Default)]
19+
/// Order in which GitHub comments for each goal are displayed.
20+
pub enum Order {
21+
#[default]
22+
/// Chronological order: the oldest comments show up first.
23+
/// Mirrors the order on the corresponding GitHub issue.
24+
OldestFirst,
25+
26+
/// Reverse chronological order: the most recent comments will show up first.
27+
NewestFirst,
28+
}
29+
1830
/// Library function that renders updates as a string without side effects.
1931
/// This is suitable for use from the mdbook preprocessor.
2032
pub fn render_updates(
@@ -25,6 +37,7 @@ pub fn render_updates(
2537
end_date: &Option<NaiveDate>,
2638
with_champion_from: Option<&str>,
2739
use_progress_bar: bool,
40+
comment_order: Order,
2841
) -> Result<String> {
2942
let milestone_re = Regex::new(r"^\d{4}[hH][12]$").unwrap();
3043
if !milestone_re.is_match(milestone) {
@@ -167,6 +180,7 @@ pub fn render_updates(
167180
&filter,
168181
true,
169182
use_progress_bar,
183+
comment_order,
170184
&issue_themes,
171185
&issue_point_of_contact,
172186
&issue_team_champions,
@@ -178,6 +192,7 @@ pub fn render_updates(
178192
&filter,
179193
false,
180194
use_progress_bar,
195+
comment_order,
181196
&issue_themes,
182197
&issue_point_of_contact,
183198
&issue_team_champions,
@@ -199,6 +214,7 @@ fn prepare_goals(
199214
filter: &Filter<'_>,
200215
flagship: bool,
201216
use_progress_bar: bool,
217+
comment_order: Order,
202218
issue_themes: &std::collections::HashMap<u64, String>,
203219
issue_point_of_contact: &std::collections::HashMap<u64, String>,
204220
issue_team_champions: &std::collections::HashMap<u64, String>,
@@ -233,6 +249,11 @@ fn prepare_goals(
233249
comments.sort_by_key(|c| c.created_at.clone());
234250
comments.retain(|c| !c.should_hide_from_reports() && filter.matches(c));
235251

252+
// We got the comments in the chronological order. Reverse it if desired.
253+
if matches!(comment_order, Order::NewestFirst) {
254+
comments.reverse();
255+
}
256+
236257
// Prettify the comments' timestamp after using it for sorting.
237258
for comment in comments.iter_mut() {
238259
comment.created_at = format!("{}", comment.created_at_date());

0 commit comments

Comments
 (0)