Skip to content

Commit 4aea83e

Browse files
author
Niko Matsakis
committed
include goals looking for help
1 parent ad0ed06 commit 4aea83e

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ pub struct UpdatesGoal {
7373
/// True if the issue is closed.
7474
pub is_closed: bool,
7575

76+
/// If there are comments that include ["help wanted"](`rust_project_goals::re::HELP_WANTED`)
77+
/// comments, those comments are included here.
78+
pub help_wanted: Vec<HelpWanted>,
79+
7680
/// Markdown with update text (bullet list)
7781
pub comments: Vec<ExistingGithubComment>,
7882

@@ -88,3 +92,8 @@ pub struct UpdatesGoal {
8892
/// Contents of a "Why this goal?" section in the tracking issue (empty string if not present)
8993
pub why_this_goal: String,
9094
}
95+
96+
#[derive(Serialize, Debug)]
97+
pub struct HelpWanted {
98+
pub text: String,
99+
}

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use anyhow::Context;
22
use chrono::{Datelike, NaiveDate};
33
use rust_project_goals::markwaydown;
4+
use rust_project_goals::re::HELP_WANTED;
45
use rust_project_goals::util::comma;
56
use rust_project_goals_json::GithubIssueState;
67
use std::io::Write;
78
use std::path::Path;
89
use std::process::{Command, Stdio};
910

10-
use crate::templates::{self, Updates, UpdatesGoal};
11+
use crate::templates::{self, HelpWanted, Updates, UpdatesGoal};
1112
use rust_project_goals::gh::issues::ExistingGithubIssue;
1213
use rust_project_goals::gh::{
1314
issue_id::{IssueId, Repository},
@@ -113,6 +114,9 @@ async fn prepare_goals(
113114
comments.sort_by_key(|c| c.created_at.clone());
114115
comments.retain(|c| !c.is_automated_comment() && filter.matches(c));
115116

117+
118+
let help_wanted = help_wanted(&issue_id, issue)?;
119+
116120
let why_this_goal = why_this_goal(&issue_id, issue)?;
117121

118122
result.push(UpdatesGoal {
@@ -121,6 +125,7 @@ async fn prepare_goals(
121125
issue_assignees: comma(&issue.assignees),
122126
issue_url: issue_id.url(),
123127
progress,
128+
help_wanted,
124129
is_closed: issue.state == GithubIssueState::Closed,
125130
num_comments: comments.len(),
126131
comments,
@@ -133,6 +138,43 @@ async fn prepare_goals(
133138
Ok(result)
134139
}
135140

141+
fn help_wanted(
142+
issue_id: &IssueId,
143+
issue: &ExistingGithubIssue,
144+
) -> anyhow::Result<Vec<HelpWanted>> {
145+
use std::fmt::Write;
146+
147+
let mut help_wanted = vec![];
148+
149+
for comment in &issue.comments {
150+
let mut lines = comment.body.split('\n').peekable();
151+
152+
// Look for a line that says "Help wanted" at the front.
153+
// Then extract the rest of that line along with subsequent lines until we find a blank line.
154+
while lines.peek().is_some() {
155+
while let Some(line) = lines.next() {
156+
if let Some(c) = HELP_WANTED.captures(line) {
157+
help_wanted.push(HelpWanted {
158+
text: c["text"].to_string()
159+
});
160+
break;
161+
}
162+
}
163+
164+
while let Some(line) = lines.next() {
165+
if line.trim().is_empty() {
166+
break;
167+
} else {
168+
let last = help_wanted.len() - 1;
169+
writeln!(&mut help_wanted[last].text, "{line}")?;
170+
}
171+
}
172+
}
173+
}
174+
175+
Ok(help_wanted)
176+
}
177+
136178
fn why_this_goal(
137179
issue_id: &IssueId,
138180
issue: &ExistingGithubIssue,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,17 @@ pub fn is_just(re: &Regex, s: &str) -> bool {
100100
let output = re.replace(s, "X");
101101
output == "X"
102102
}
103+
104+
lazy_static! {
105+
/// If a line within a comment begins with this text, it will be considered a request for help
106+
pub static ref HELP_WANTED: Regex =
107+
Regex::new(r"^(Help wanted:|^**Help wanted:**) (?P<text>.*)")
108+
.unwrap();
109+
}
110+
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+
}

templates/updates.hbs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,41 @@ The Rust project is currently working towards a [slate of 26 project goals](http
1818
{{>goal_comments}}
1919
{{/each}}
2020

21-
## Other goals
21+
## Goals looking for help
2222

2323
{{#each other_goals}}
24+
{{#if help_wanted}}
2425
{{>introduce_goal}}
2526

27+
{{#each help_wanted}}
28+
29+
<!-- markdown separator -->
30+
![Help wanted](https://img.shields.io/badge/Help%20wanted-yellow) {{{text}}}
2631
<!-- markdown separator -->
2732

33+
{{/each}}
34+
2835
{{#if tldr}}
2936
{{tldr}}
3037
{{/if}}
3138

3239
<!-- markdown separator -->
3340

3441
{{>goal_comments}}
42+
{{/if}}
43+
{{/each}}
44+
45+
## Other goal updates
46+
47+
{{#each other_goals}}
48+
{{#if help_wanted}}
49+
{{else}}
50+
{{>introduce_goal}}
51+
<!-- markdown separator -->
52+
{{#if tldr}}
53+
{{tldr}}
54+
{{/if}}
55+
<!-- markdown separator -->
56+
{{>goal_comments}}
57+
{{/if}}
3558
{{/each}}

0 commit comments

Comments
 (0)