Skip to content

Commit e4b611a

Browse files
author
Niko Matsakis
committed
extract "why this goal" text from tracking issue
1 parent 0128b10 commit e4b611a

File tree

4 files changed

+65
-11
lines changed

4 files changed

+65
-11
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,10 @@ pub struct UpdatesGoal {
8181

8282
/// Progress towards the goal
8383
pub progress: Progress,
84+
85+
/// TL;DR comment (if any, empty string if none)
86+
pub tldr: Option<String>,
87+
88+
/// Contents of a "Why this goal?" section in the tracking issue (empty string if not present)
89+
pub why_this_goal: String,
8490
}

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anyhow::Context;
22
use chrono::{Datelike, NaiveDate};
3+
use rust_project_goals::markwaydown;
34
use rust_project_goals::util::comma;
45
use rust_project_goals_json::GithubIssueState;
56
use std::io::Write;
@@ -92,6 +93,11 @@ async fn prepare_goals(
9293
continue;
9394
}
9495

96+
let issue_id = IssueId {
97+
repository: repository.clone(),
98+
number: issue.number,
99+
};
100+
95101
let title = &issue.title;
96102

97103
progress_bar::print_progress_bar_info(
@@ -107,26 +113,39 @@ async fn prepare_goals(
107113
comments.sort_by_key(|c| c.created_at.clone());
108114
comments.retain(|c| !c.is_automated_comment() && filter.matches(c));
109115

116+
let why_this_goal = why_this_goal(&issue_id, issue)?;
117+
110118
result.push(UpdatesGoal {
111119
title: title.clone(),
112120
issue_number: issue.number,
113121
issue_assignees: comma(&issue.assignees),
114-
issue_url: IssueId {
115-
repository: repository.clone(),
116-
number: issue.number,
117-
}
118-
.url(),
122+
issue_url: issue_id.url(),
119123
progress,
120124
is_closed: issue.state == GithubIssueState::Closed,
121125
num_comments: comments.len(),
122126
comments,
127+
tldr: None, // FIXME
128+
why_this_goal,
123129
});
124130

125131
progress_bar::inc_progress_bar();
126132
}
127133
Ok(result)
128134
}
129135

136+
fn why_this_goal(
137+
issue_id: &IssueId,
138+
issue: &ExistingGithubIssue,
139+
) -> anyhow::Result<String> {
140+
let sections = markwaydown::parse_text(issue_id.url(), &issue.body)?;
141+
for section in sections {
142+
if section.title == "Why this goal?" {
143+
return Ok(section.text.trim().to_string());
144+
}
145+
}
146+
return Ok("".to_string());
147+
}
148+
130149
struct Filter<'f> {
131150
start_date: NaiveDate,
132151
end_date: &'f Option<NaiveDate>,

crates/rust-project-goals/src/markwaydown.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ pub struct Table {
3131
pub rows: Vec<Vec<String>>,
3232
}
3333

34-
pub fn parse(path: &Path) -> anyhow::Result<Vec<Section>> {
34+
pub fn parse(path: impl AsRef<Path>) -> anyhow::Result<Vec<Section>> {
35+
let path = path.as_ref();
3536
let text = std::fs::read_to_string(path)?;
37+
parse_text(path, &text)
38+
}
39+
40+
pub fn parse_text(path: impl AsRef<Path>, text: &str) -> anyhow::Result<Vec<Section>> {
41+
let path: &Path = path.as_ref();
3642
let mut result = vec![];
3743
let mut open_section = None;
3844
let mut open_table = None;
@@ -54,11 +60,14 @@ pub fn parse(path: &Path) -> anyhow::Result<Vec<Section>> {
5460
}
5561
CategorizeLine::TableRow(mut row) => {
5662
if open_section.is_none() {
57-
anyhow::bail!(
58-
"{}:{}: markdowwn table outside of any section",
59-
path.display(),
60-
line_num
61-
);
63+
// create an "anonymous" section to house the table
64+
open_section = Some(Section {
65+
line_num,
66+
level: 0,
67+
title: String::new(),
68+
text: String::new(),
69+
tables: vec![],
70+
});
6271
}
6372

6473
if let Some(table) = &mut open_table {

templates/updates.hbs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,32 @@ The Rust project is currently working towards a [slate of 26 project goals](http
44

55
{{#each flagship_goals}}
66
{{>introduce_goal}}
7+
8+
<!-- markdown separator -->
9+
10+
**Why this goal?** {{why_this_goal}}
11+
12+
{{#if tldr}}
13+
**What has happened?** {{tldr}}
14+
{{/if}}
15+
16+
<!-- markdown separator -->
17+
718
{{>goal_comments}}
819
{{/each}}
920

1021
## Other goals
1122

1223
{{#each other_goals}}
1324
{{>introduce_goal}}
25+
26+
<!-- markdown separator -->
27+
28+
{{#if tldr}}
29+
{{tldr}}
30+
{{/if}}
31+
32+
<!-- markdown separator -->
33+
1434
{{>goal_comments}}
1535
{{/each}}

0 commit comments

Comments
 (0)