Skip to content

Commit 3be1224

Browse files
author
Niko Matsakis
committed
extract tldr and include it
1 parent 4aea83e commit 3be1224

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Context;
22
use chrono::{Datelike, NaiveDate};
33
use rust_project_goals::markwaydown;
4-
use rust_project_goals::re::HELP_WANTED;
4+
use rust_project_goals::re::{HELP_WANTED, TLDR};
55
use rust_project_goals::util::comma;
66
use rust_project_goals_json::GithubIssueState;
77
use std::io::Write;
@@ -114,11 +114,19 @@ async fn prepare_goals(
114114
comments.sort_by_key(|c| c.created_at.clone());
115115
comments.retain(|c| !c.is_automated_comment() && filter.matches(c));
116116

117+
let tldr = tldr(&issue_id, &mut comments)?;
117118

118-
let help_wanted = help_wanted(&issue_id, issue)?;
119+
let help_wanted = help_wanted(&issue_id, &comments)?;
119120

120121
let why_this_goal = why_this_goal(&issue_id, issue)?;
121122

123+
progress_bar::print_progress_bar_info(
124+
&format!("Issue #{number}", number = issue.number),
125+
&format!("tldr={}, c={}", tldr.is_some(), comments.len()),
126+
progress_bar::Color::Green,
127+
progress_bar::Style::Bold,
128+
);
129+
122130
result.push(UpdatesGoal {
123131
title: title.clone(),
124132
issue_number: issue.number,
@@ -129,7 +137,7 @@ async fn prepare_goals(
129137
is_closed: issue.state == GithubIssueState::Closed,
130138
num_comments: comments.len(),
131139
comments,
132-
tldr: None, // FIXME
140+
tldr,
133141
why_this_goal,
134142
});
135143

@@ -138,15 +146,29 @@ async fn prepare_goals(
138146
Ok(result)
139147
}
140148

149+
/// Search for a TL;DR comment. If one is found, remove it and return the text.
150+
fn tldr(
151+
_issue_id: &IssueId,
152+
comments: &mut Vec<ExistingGithubComment>,
153+
) -> anyhow::Result<Option<String>> {
154+
let Some(index) = comments.iter().position(|c| c.body.starts_with(TLDR)) else {
155+
return Ok(None);
156+
};
157+
158+
let comment = comments.remove(index);
159+
Ok(Some(comment.body[TLDR.len()..].trim().to_string()))
160+
}
161+
162+
/// Search for comments that talk about help being wanted and extract that
141163
fn help_wanted(
142-
issue_id: &IssueId,
143-
issue: &ExistingGithubIssue,
164+
_issue_id: &IssueId,
165+
comments: &[ExistingGithubComment],
144166
) -> anyhow::Result<Vec<HelpWanted>> {
145167
use std::fmt::Write;
146168

147169
let mut help_wanted = vec![];
148170

149-
for comment in &issue.comments {
171+
for comment in comments {
150172
let mut lines = comment.body.split('\n').peekable();
151173

152174
// Look for a line that says "Help wanted" at the front.

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,5 @@ lazy_static! {
108108
.unwrap();
109109
}
110110

111-
lazy_static! {
112-
/// If a comment begins with this text, it will be considered a summary.
113-
pub static ref TLDR: Regex =
114-
Regex::new(r"^TLDR")
115-
.unwrap();
116-
}
111+
/// If a comment begins with this text, it will be considered a summary.
112+
pub const TLDR: &str = "TL;DR:";

templates/updates.hbs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ The Rust project is currently working towards a [slate of 26 project goals](http
99

1010
**Why this goal?** {{why_this_goal}}
1111

12-
{{#if tldr}}
13-
**What has happened?** {{tldr}}
14-
{{/if}}
12+
**What has happened?** {{{tldr}}}
1513

1614
<!-- markdown separator -->
1715

@@ -24,6 +22,10 @@ The Rust project is currently working towards a [slate of 26 project goals](http
2422
{{#if help_wanted}}
2523
{{>introduce_goal}}
2624

25+
<!-- markdown separator -->
26+
{{{tldr}}}
27+
<!-- markdown separator -->
28+
2729
{{#each help_wanted}}
2830

2931
<!-- markdown separator -->
@@ -32,10 +34,6 @@ The Rust project is currently working towards a [slate of 26 project goals](http
3234

3335
{{/each}}
3436

35-
{{#if tldr}}
36-
{{tldr}}
37-
{{/if}}
38-
3937
<!-- markdown separator -->
4038

4139
{{>goal_comments}}
@@ -48,11 +46,13 @@ The Rust project is currently working towards a [slate of 26 project goals](http
4846
{{#if help_wanted}}
4947
{{else}}
5048
{{>introduce_goal}}
49+
5150
<!-- markdown separator -->
52-
{{#if tldr}}
53-
{{tldr}}
54-
{{/if}}
51+
52+
{{{tldr}}}
53+
5554
<!-- markdown separator -->
55+
5656
{{>goal_comments}}
5757
{{/if}}
5858
{{/each}}

0 commit comments

Comments
 (0)