Skip to content

Commit cddaafa

Browse files
committed
generate LLM prompts to summarize updates
1 parent a9b88d3 commit cddaafa

File tree

2 files changed

+42
-37
lines changed

2 files changed

+42
-37
lines changed

mdbook-goals/src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ enum Command {
8989
/// Milestone for which we generate tracking issue data (e.g., `2024h2`).
9090
milestone: String,
9191

92+
/// Directory where we will write the output markdown files.
93+
output_directory: PathBuf,
94+
9295
/// Start date for comments.
9396
/// If not given, defaults to 1 week before the start of this month.
9497
start_date: Option<chrono::NaiveDate>,
@@ -147,10 +150,17 @@ fn main() -> anyhow::Result<()> {
147150
}
148151
Command::Updates {
149152
milestone,
153+
output_directory,
150154
start_date,
151155
end_date,
152156
} => {
153-
updates::updates(&opt.repository, milestone, start_date, end_date)?;
157+
updates::updates(
158+
&opt.repository,
159+
milestone,
160+
output_directory,
161+
start_date,
162+
end_date,
163+
)?;
154164
}
155165
}
156166

mdbook-goals/src/updates.rs

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use std::path::Path;
2+
3+
use anyhow::Context;
14
use chrono::{Datelike, NaiveDate};
25

36
use crate::{
@@ -11,9 +14,12 @@ use crate::{
1114
pub fn updates(
1215
repository: &Repository,
1316
milestone: &str,
17+
output_directory: &Path,
1418
start_date: &Option<NaiveDate>,
1519
end_date: &Option<NaiveDate>,
1620
) -> anyhow::Result<()> {
21+
use std::fmt::Write;
22+
1723
let issues = list_issue_titles_in_milestone(repository, milestone)?;
1824

1925
let filter = Filter {
@@ -24,54 +30,43 @@ pub fn updates(
2430
end_date,
2531
};
2632

27-
for (title, issue) in issues {
28-
let total_updates = issue
29-
.comments
30-
.iter()
31-
.filter(|c| !c.is_automated_comment())
32-
.count();
33+
std::fs::create_dir_all(output_directory)
34+
.with_context(|| format!("creating directory `{}`", output_directory.display()))?;
3335

34-
println!(
35-
"# {title} (#{number})",
36-
title = title,
37-
number = issue.number
38-
);
39-
println!("");
40-
println!("| Metadata | |");
41-
println!("| --- | --- |");
42-
println!(
43-
"| Assigned to | {assignees} |",
36+
for (title, issue) in issues {
37+
let mut output_text = String::new();
38+
writeln!(
39+
output_text,
40+
"What follows is a series of updates related to a project goal entitled {title}. \
41+
The goal is assigned to {people} ({assignees}). \
42+
Please create a short 1-2 paragraph summary of these updates suitable for inclusion in a blog post.
43+
Write the update in the third person. \
44+
UPDATES START HERE:",
45+
people = if issue.assignees.len() == 1 { "1 person".to_string() } else { format!("{} people", issue.assignees.len()) },
4446
assignees = comma(&issue.assignees),
45-
);
46-
println!("| State | {state} |", state = issue.state);
47-
println!("| Total updates | {total_updates} |");
48-
println!(
49-
"| Date of most recent update | {date} |",
50-
date = issue
51-
.comments
52-
.last()
53-
.map(|c| c.created_at_date().to_string())
54-
.unwrap_or("none".to_string())
55-
);
47+
)?;
5648

5749
let mut comments = issue.comments;
5850
comments.sort_by_key(|c| c.created_at.clone());
5951
comments.retain(|c| filter.matches(c));
6052

61-
println!();
53+
writeln!(output_text)?;
6254
if comments.len() == 0 {
63-
println!("No updates since {date}.", date = filter.start_date);
55+
writeln!(
56+
output_text,
57+
"No updates since {date}.",
58+
date = filter.start_date
59+
)?;
6460
} else {
6561
for comment in comments {
66-
println!(
67-
"## Update by {author} from {created} ([link]({url}))",
68-
author = comment.author,
69-
created = comment.created_at_date(),
70-
url = comment.url,
71-
);
72-
println!("\n{body}\n", body = comment.body);
62+
writeln!(output_text, "\n{body}\n", body = comment.body)?;
7363
}
7464
}
65+
let output_file = output_directory
66+
.join(issue.number.to_string())
67+
.with_extension("md");
68+
std::fs::write(&output_file, output_text)
69+
.with_context(|| format!("writing to `{}`", output_file.display()))?;
7570
}
7671

7772
Ok(())

0 commit comments

Comments
 (0)