Skip to content

Commit a509563

Browse files
authored
Merge pull request #300 from lqd/monthly-post
More work on the monthly update post
2 parents 9c14e70 + 640368a commit a509563

File tree

16 files changed

+134
-222
lines changed

16 files changed

+134
-222
lines changed

crates/mdbook-goals/src/mdbook_preprocessor.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,19 @@ impl<'c> GoalPreprocessorWithContext<'c> {
270270
return Ok(());
271271
}
272272
let config = Configuration::get();
273-
let rows = std::iter::once(vec!["Ask".to_string(), "aka".to_string(), "Description".to_string()])
274-
.chain(config.team_asks.iter().map(|(name, details)| {
275-
vec![
276-
format!("{name:?}"),
277-
details.short.to_string(),
278-
details.about.to_string(),
279-
]
280-
}))
281-
.collect::<Vec<Vec<String>>>();
273+
let rows = std::iter::once(vec![
274+
"Ask".to_string(),
275+
"aka".to_string(),
276+
"Description".to_string(),
277+
])
278+
.chain(config.team_asks.iter().map(|(name, details)| {
279+
vec![
280+
format!("{name:?}"),
281+
details.short.to_string(),
282+
details.about.to_string(),
283+
]
284+
}))
285+
.collect::<Vec<Vec<String>>>();
282286
let table = util::format_table(&rows);
283287
let new_content = re::VALID_TEAM_ASKS.replace_all(&chapter.content, table);
284288
chapter.content = new_content.to_string();

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

Lines changed: 0 additions & 154 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use clap::Parser;
55
use rust_project_goals::gh::issue_id::Repository;
66
use rust_project_goals_llm::UpdateArgs;
77

8-
mod llm;
98
mod templates;
109
mod updates;
1110

crates/rust-project-goals-cli-llm/src/templates.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,24 @@ pub struct Updates {
4646
pub milestone: String,
4747
pub flagship_goals: Vec<UpdatesGoal>,
4848
pub other_goals: Vec<UpdatesGoal>,
49+
pub goal_count: usize,
50+
pub flagship_goal_count: usize,
4951
}
5052

5153
impl Updates {
54+
pub fn new(
55+
milestone: String,
56+
flagship_goals: Vec<UpdatesGoal>,
57+
other_goals: Vec<UpdatesGoal>,
58+
) -> Self {
59+
Updates {
60+
milestone,
61+
flagship_goal_count: flagship_goals.len(),
62+
goal_count: flagship_goals.len() + other_goals.len(),
63+
flagship_goals,
64+
other_goals,
65+
}
66+
}
5267
pub fn render(self) -> anyhow::Result<String> {
5368
let templates = Templates::new()?;
5469
Ok(templates.reg.render("updates", &self)?)
@@ -83,8 +98,8 @@ pub struct UpdatesGoal {
8398
/// Markdown with update text (bullet list)
8499
pub comments: Vec<ExistingGithubComment>,
85100

86-
/// Comments.len but accessible to the template
87-
pub num_comments: usize,
101+
/// The "<details>" summary, a prettified version of comments.len().
102+
pub details_summary: String,
88103

89104
/// Progress towards the goal
90105
pub progress: Progress,
@@ -94,6 +109,9 @@ pub struct UpdatesGoal {
94109

95110
/// Contents of a "Why this goal?" section in the tracking issue (empty string if not present)
96111
pub why_this_goal: String,
112+
113+
/// If this goal needs to be separated from its following sibling by an empty line.
114+
pub needs_separator: bool,
97115
}
98116

99117
#[derive(Serialize, Debug)]

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::io::Write;
88
use std::path::Path;
99
use std::process::{Command, Stdio};
1010

11-
use crate::templates::{self, HelpWanted, Updates, UpdatesGoal};
11+
use crate::templates::{self, HelpWanted, UpdatesGoal};
1212
use rust_project_goals::gh::issues::ExistingGithubIssue;
1313
use 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

Comments
 (0)