Skip to content

Commit 4208203

Browse files
author
Niko Matsakis
committed
rework to be more uniform
1 parent eadcd96 commit 4208203

File tree

3 files changed

+46
-65
lines changed

3 files changed

+46
-65
lines changed

mdbook-goals/src/templates.rs

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ handlebars::handlebars_helper!(is_complete: |p: Progress| match p {
4343
#[derive(Serialize, Debug)]
4444
pub struct Updates {
4545
pub milestone: String,
46-
pub flagship_goals: Vec<UpdatesFlagshipGoal>,
47-
pub other_goals_with_updates: Vec<UpdatesOtherGoal>,
48-
pub other_goals_without_updates: Vec<UpdatesOtherGoal>,
46+
pub flagship_goals: Vec<UpdatesGoal>,
47+
pub other_goals_with_updates: Vec<UpdatesGoal>,
48+
pub other_goals_without_updates: Vec<UpdatesGoal>,
4949
}
5050

5151
impl Updates {
@@ -57,48 +57,7 @@ impl Updates {
5757

5858
/// Part of the parameters expected by the `updates.md` template.
5959
#[derive(Serialize, Debug)]
60-
pub struct UpdatesFlagshipGoal {
61-
/// Title of the tracking issue
62-
pub title: String,
63-
64-
/// Tracking issue number on the project goals repository
65-
pub issue_number: u64,
66-
67-
/// Comma-separated list of assignees
68-
pub issue_assignees: String,
69-
70-
/// URL of the tracking issue
71-
pub issue_url: String,
72-
73-
/// True if the issue is closed.
74-
pub is_closed: bool,
75-
76-
/// Progress towards the goal
77-
pub progress: Progress,
78-
79-
/// Updates provided towards the goal
80-
pub updates: Vec<UpdatesFlagshipGoalUpdate>,
81-
}
82-
83-
/// Part of the parameters expected by the `updates.md` template.
84-
#[derive(Serialize, Debug)]
85-
pub struct UpdatesFlagshipGoalUpdate {
86-
/// Username of the person who wrote the update
87-
pub author: String,
88-
89-
/// Formatted like "Oct 26"
90-
pub date: String,
91-
92-
/// Text of the update
93-
pub update: String,
94-
95-
/// URL of the comment
96-
pub url: String,
97-
}
98-
99-
/// Part of the parameters expected by the `updates.md` template.
100-
#[derive(Serialize, Debug)]
101-
pub struct UpdatesOtherGoal {
60+
pub struct UpdatesGoal {
10261
/// Title of the tracking issue
10362
pub title: String,
10463

mdbook-goals/src/updates.rs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use std::path::Path;
66
use std::process::{Command, Stdio};
77

88
use crate::gh::issues::ExistingGithubIssue;
9-
use crate::templates::Updates;
9+
use crate::templates::{Updates, UpdatesGoal};
1010
use crate::{
1111
gh::{
1212
issue_id::{IssueId, Repository},
1313
issues::{list_issue_titles_in_milestone, ExistingGithubComment, ExistingIssueState},
1414
},
1515
json::checkboxes,
1616
llm::LargeLanguageModel,
17-
templates::{self, UpdatesFlagshipGoal, UpdatesFlagshipGoalUpdate, UpdatesOtherGoal},
17+
templates,
1818
util::comma,
1919
};
2020

@@ -114,8 +114,8 @@ async fn prepare_flagship_goals(
114114
repository: &Repository,
115115
issues: &BTreeMap<String, ExistingGithubIssue>,
116116
filter: &Filter<'_>,
117-
_llm: &LargeLanguageModel,
118-
_quick: bool,
117+
llm: &LargeLanguageModel,
118+
quick: bool,
119119
updates: &mut Updates,
120120
) -> anyhow::Result<()> {
121121
// First process the flagship goals, for which we capture the full text of comments.
@@ -133,7 +133,36 @@ async fn prepare_flagship_goals(
133133

134134
let progress = checkboxes(&issue);
135135

136-
updates.flagship_goals.push(UpdatesFlagshipGoal {
136+
let mut comments = issue.comments.clone();
137+
comments.sort_by_key(|c| c.created_at.clone());
138+
comments.retain(|c| filter.matches(c));
139+
140+
let summary: String = if comments.len() == 0 {
141+
format!("No updates in this period.")
142+
} else if quick {
143+
QUICK_UPDATES.iter().copied().collect()
144+
} else {
145+
let prompt = format!(
146+
"The following comments are updates to a project goal entitled '{title}'. \
147+
The goal is assigned to {people} ({assignees}). \
148+
Summarize the major developments, writing for general Rust users. \
149+
Write the update in the third person and do not use pronouns when referring to people. \
150+
Do not respond with anything but the summary paragraphs. \
151+
",
152+
people = if issue.assignees.len() == 1 {
153+
"1 person".to_string()
154+
} else {
155+
format!("{} people", issue.assignees.len())
156+
},
157+
assignees = comma(&issue.assignees),
158+
);
159+
let updates: String = comments.iter().map(|c| format!("\n{}\n", c.body)).collect();
160+
llm.query(&prompt, &updates)
161+
.await
162+
.with_context(|| format!("making request to LLM failed"))?
163+
};
164+
165+
updates.flagship_goals.push(UpdatesGoal {
137166
title: title.clone(),
138167
issue_number: issue.number,
139168
issue_assignees: comma(&issue.assignees),
@@ -144,17 +173,7 @@ async fn prepare_flagship_goals(
144173
.url(),
145174
progress,
146175
is_closed: issue.state == ExistingIssueState::Closed,
147-
updates: issue
148-
.comments
149-
.iter()
150-
.filter(|c| filter.matches(c))
151-
.map(|c| UpdatesFlagshipGoalUpdate {
152-
author: c.author.clone(),
153-
date: c.created_at_date().format("%m %d").to_string(),
154-
update: c.body.clone(),
155-
url: c.url.clone(),
156-
})
157-
.collect(),
176+
updates_markdown: summary,
158177
});
159178

160179
progress_bar::inc_progress_bar();
@@ -219,7 +238,7 @@ async fn prepare_other_goals(
219238
llm.query(&prompt, &updates).await?
220239
};
221240

222-
let goal = UpdatesOtherGoal {
241+
let goal = UpdatesGoal {
223242
title: title.clone(),
224243
issue_number: issue.number,
225244
issue_assignees: comma(&issue.assignees),

templates/updates.hbs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ repository](https://github.com/rust-lang/rust-project-goals/milestone/2).
1212

1313
{{!-- some spacing is required to ensure that markdown is recognized as markdown and not html --}}
1414

15-
{{#each updates}}
16-
{{{update}}}
17-
{{/each}}
15+
{{{updates_markdown}}}
16+
17+
{{!-- some spacing is required to ensure that markdown is recognized as markdown and not html --}}
18+
1819
{{/each}}
1920

2021
## Goals with updates
@@ -26,6 +27,8 @@ repository](https://github.com/rust-lang/rust-project-goals/milestone/2).
2627

2728
{{{updates_markdown}}}
2829

30+
{{!-- some spacing is required to ensure that markdown is recognized as markdown and not html --}}
31+
2932
{{/each}}
3033

3134
## Goals without updates

0 commit comments

Comments
 (0)