Skip to content

Commit 8806d62

Browse files
authored
Merge pull request #426 from tomassedovic/recent-reports
Replace monthly reports with "recent updates"
2 parents c817d3f + ef3d99e commit 8806d62

File tree

4 files changed

+57
-44
lines changed

4 files changed

+57
-44
lines changed

crates/mdbook-goals/src/mdbook_preprocessor.rs

Lines changed: 34 additions & 43 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::{
@@ -611,7 +612,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {
611612
let team_virtual_path = format!("{}/index.md", team_name_str);
612613
let team_path = Path::new(&team_virtual_path);
613614

614-
let team_content = format!("# {} Team Champion Reports\n\nThis section contains monthly champion reports for the {} team.", team_name_str, team_name_str);
615+
let team_content = format!("# {} Team Champion Reports\n\nThis section contains champion reports for the {} team.", team_name_str, team_name_str);
615616
let mut team_chapter = Chapter::new(
616617
&team_chapter_name,
617618
team_content,
@@ -627,36 +628,34 @@ impl<'c> GoalPreprocessorWithContext<'c> {
627628

628629
let mut team_parent_names = parent_names.clone();
629630
team_parent_names.push(team_chapter_name.clone());
630-
let mut team_sub_index = 1;
631-
632-
// Generate monthly reports for this team
633-
for (year, month, month_name) in months.iter().rev() {
634-
// Reverse to show newest first
635-
let champion_content =
636-
self.generate_champion_report_content(milestone, team_name_str, *year, *month)?;
637-
638-
let monthly_chapter_name = format!("{} {}", month_name, year);
639-
let monthly_virtual_path = format!("{}/{:04}-{:02}.md", team_name_str, year, month);
640-
let monthly_path = Path::new(&monthly_virtual_path);
641-
642-
let mut monthly_chapter = Chapter::new(
643-
&monthly_chapter_name,
644-
champion_content,
645-
monthly_path,
646-
team_parent_names.clone(),
647-
);
648-
649-
if let Some(mut number) = team_chapter.number.clone() {
650-
number.0.push(team_sub_index);
651-
monthly_chapter.number = Some(number);
652-
team_sub_index += 1;
653-
}
631+
let team_sub_index = 1;
632+
633+
// Generate the "recent updates" report for this team
634+
635+
// Reverse to show newest first
636+
let champion_content =
637+
self.generate_champion_report_content(milestone, team_name_str)?;
638+
639+
let report_name = format!("Recent updates");
640+
let report_virtual_path = format!("{team_name_str}/recent-updates.md");
641+
let report_path = Path::new(&report_virtual_path);
642+
643+
let mut report_chapter = Chapter::new(
644+
&report_name,
645+
champion_content,
646+
report_path,
647+
team_parent_names.clone(),
648+
);
654649

655-
team_chapter
656-
.sub_items
657-
.push(BookItem::Chapter(monthly_chapter));
650+
if let Some(mut number) = team_chapter.number.clone() {
651+
number.0.push(team_sub_index);
652+
report_chapter.number = Some(number);
658653
}
659654

655+
team_chapter
656+
.sub_items
657+
.push(BookItem::Chapter(report_chapter));
658+
660659
parent_chapter
661660
.sub_items
662661
.push(BookItem::Chapter(team_chapter));
@@ -704,6 +703,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {
704703
&Some(end_date),
705704
None,
706705
false,
706+
Order::OldestFirst,
707707
)
708708
.map_err(|e| anyhow::anyhow!("Failed to generate blog post content: {}", e))?;
709709

@@ -714,26 +714,16 @@ impl<'c> GoalPreprocessorWithContext<'c> {
714714
&mut self,
715715
milestone: &str,
716716
team_name: &str,
717-
year: i32,
718-
month: u32,
719717
) -> anyhow::Result<String> {
720-
use chrono::NaiveDate;
718+
// Look at the updates for the last ~three months
719+
let end_date = chrono::Utc::now().date_naive();
720+
let start_date = end_date - chrono::TimeDelta::days(90);
721721

722722
eprintln!(
723-
"👥 Generating champion report for {} team, {}-{:02} (milestone: {})",
724-
team_name, year, month, milestone
723+
"👥 Generating champion report for {} team, {start_date} - {end_date} (milestone: {})",
724+
team_name, milestone
725725
);
726726

727-
// Calculate start and end dates for the month
728-
let start_date = NaiveDate::from_ymd_opt(year, month, 1)
729-
.ok_or_else(|| anyhow::anyhow!("Invalid date: {}-{:02}-01", year, month))?;
730-
let end_date = if month == 12 {
731-
NaiveDate::from_ymd_opt(year + 1, 1, 1)
732-
} else {
733-
NaiveDate::from_ymd_opt(year, month + 1, 1)
734-
}
735-
.ok_or_else(|| anyhow::anyhow!("Invalid end date calculation for {}-{:02}", year, month))?;
736-
737727
// Get repository from context - assuming rust-lang/rust-project-goals as default
738728
let repository =
739729
rust_project_goals::gh::issue_id::Repository::new("rust-lang", "rust-project-goals");
@@ -750,6 +740,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {
750740
&Some(end_date),
751741
Some(team_name),
752742
false,
743+
Order::NewestFirst,
753744
)
754745
.map_err(|e| anyhow::anyhow!("Failed to generate champion report content: {}", e))?;
755746

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)