Skip to content

Commit

Permalink
Merge pull request #200 from nikomatsakis/poc
Browse files Browse the repository at this point in the history
require a single point-of-contact
  • Loading branch information
nikomatsakis authored Dec 19, 2024
2 parents 926d600 + ca2d265 commit 532ba38
Show file tree
Hide file tree
Showing 92 changed files with 668 additions and 383 deletions.
1 change: 1 addition & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ level = 0
"/2024h2/accepted.html" = "goals.html"
"/2024h2/flagship.html" = "goals.html"
"/introduction.html" = "index.html"
"/about/provisional_goals.html" = "about/invited_goals.html"

[output.markdown]
96 changes: 47 additions & 49 deletions crates/mdbook-goals/src/mdbook_preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ impl Preprocessor for GoalPreprocessor {

pub struct GoalPreprocessorWithContext<'c> {
team_asks: &'static Regex,
goal_list: &'static Regex,
goal_count: &'static Regex,
username: &'static Regex,
ctx: &'c PreprocessorContext,
Expand Down Expand Up @@ -116,7 +115,6 @@ impl<'c> GoalPreprocessorWithContext<'c> {
Ok(GoalPreprocessorWithContext {
ctx,
team_asks: &re::TEAM_ASKS,
goal_list: &re::GOAL_LIST,
goal_count: &re::GOAL_COUNT,
username: &re::USERNAME,
links,
Expand Down Expand Up @@ -163,7 +161,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {

let count = goals
.iter()
.filter(|g| g.metadata.status != Status::NotAccepted)
.filter(|g| g.metadata.status.is_not_not_accepted())
.count();

chapter.content = self
Expand All @@ -175,54 +173,54 @@ impl<'c> GoalPreprocessorWithContext<'c> {
}

fn replace_goal_lists(&mut self, chapter: &mut Chapter) -> anyhow::Result<()> {
let Some(m) = self.goal_list.captures(&chapter.content) else {
return Ok(());
};
let range = m.get(0).unwrap().range();
let statuses = m[1]
.split(',')
.map(|s| s.trim())
.map(Status::try_from)
.collect::<anyhow::Result<Vec<Status>>>()?;

let Some(chapter_path) = &chapter.path else {
anyhow::bail!("found `<!-- GOALS -->` but chapter has no path")
};

// Extract out the list of goals with the given status.
let goals = self.goal_documents(chapter_path)?;
let mut goals_with_status: Vec<&GoalDocument> = statuses
.iter()
.flat_map(|&status| goals.iter().filter(move |g| g.metadata.status == status))
.collect();

goals_with_status.sort_by_key(|g| &g.metadata.title);

// Format the list of goals and replace the `<!-- -->` comment with that.
let output = goal::format_goal_table(&goals_with_status)?;
chapter.content.replace_range(range, &output);

// Populate with children if this is not README
if chapter_path.file_stem() != Some("README".as_ref()) {
let mut parent_names = chapter.parent_names.clone();
parent_names.push(chapter.name.clone());
for (goal, index) in goals_with_status.iter().zip(0..) {
let content = std::fs::read_to_string(&goal.path)
.with_context(|| format!("reading `{}`", goal.path.display()))?;
let path = goal.path.strip_prefix(&self.ctx.config.book.src).unwrap();
let mut new_chapter =
Chapter::new(&goal.metadata.title, content, path, parent_names.clone());

if let Some(mut number) = chapter.number.clone() {
number.0.push(index + 1);
new_chapter.number = Some(number);
self.replace_goal_lists_helper(chapter, &re::FLAGSHIP_GOAL_LIST, |status| status.is_flagship && status.is_not_not_accepted())?;
self.replace_goal_lists_helper(chapter, &re::OTHER_GOAL_LIST, |status| !status.is_flagship && status.is_not_not_accepted())?;
self.replace_goal_lists_helper(chapter, &re::GOAL_LIST, |status| status.is_not_not_accepted())?;
self.replace_goal_lists_helper(chapter, &re::GOAL_NOT_ACCEPTED_LIST, |status| !status.is_not_not_accepted())?;
Ok(())
}

fn replace_goal_lists_helper(&mut self, chapter: &mut Chapter, regex: &Regex, filter: impl Fn(Status) -> bool) -> anyhow::Result<()> {
loop {
let Some(m) = regex.find(&chapter.content) else {
return Ok(());
};
let range = m.range();

let Some(chapter_path) = &chapter.path else {
anyhow::bail!("found `{regex}` but chapter has no path")
};

// Extract out the list of goals with the given status.
let goals = self.goal_documents(chapter_path)?;
let mut goals_with_status: Vec<&GoalDocument> = goals.iter().filter(|g| filter(g.metadata.status)).collect();

goals_with_status.sort_by_key(|g| &g.metadata.title);

// Format the list of goals and replace the `<!-- -->` comment with that.
let output = goal::format_goal_table(&goals_with_status)?;
chapter.content.replace_range(range, &output);

// Populate with children if this is not README
if chapter_path.file_stem() != Some("README".as_ref()) {
let mut parent_names = chapter.parent_names.clone();
parent_names.push(chapter.name.clone());
for (goal, index) in goals_with_status.iter().zip(0..) {
let content = std::fs::read_to_string(&goal.path)
.with_context(|| format!("reading `{}`", goal.path.display()))?;
let path = goal.path.strip_prefix(&self.ctx.config.book.src).unwrap();
let mut new_chapter =
Chapter::new(&goal.metadata.title, content, path, parent_names.clone());

if let Some(mut number) = chapter.number.clone() {
number.0.push(index + 1);
new_chapter.number = Some(number);
}

chapter.sub_items.push(BookItem::Chapter(new_chapter));
}

chapter.sub_items.push(BookItem::Chapter(new_chapter));
}
}

self.replace_goal_lists(chapter)
}

/// Look for `<!-- TEAM ASKS -->` in the chapter content and replace it with the team asks.
Expand All @@ -239,7 +237,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {
let goals = self.goal_documents(path)?;
let asks_of_any_team: Vec<&TeamAsk> = goals
.iter()
.filter(|g| g.metadata.status != Status::NotAccepted)
.filter(|g| g.metadata.status.is_not_not_accepted())
.flat_map(|g| &g.team_asks)
.collect();
let format_team_asks = format_team_asks(&asks_of_any_team)?;
Expand Down
16 changes: 8 additions & 8 deletions crates/rust-project-goals-cli/src/rfc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rust_project_goals::{
},
labels::GhLabel,
},
goal::{self, GoalDocument, GoalPlan, ParsedOwners, Status},
goal::{self, GoalDocument, GoalPlan, ParsedOwners},
team::{get_person_data, TeamName},
};

Expand Down Expand Up @@ -305,7 +305,7 @@ fn issue<'doc>(timeframe: &str, document: &'doc GoalDocument) -> anyhow::Result<
}

let mut labels = vec!["C-tracking-issue".to_string()];
if let Status::Flagship = document.metadata.status {
if document.metadata.status.is_flagship {
labels.push("Flagship Goal".to_string());
}
for team in document.teams_with_asks() {
Expand Down Expand Up @@ -338,11 +338,11 @@ fn issue_text(timeframe: &str, document: &GoalDocument) -> anyhow::Result<String

Ok(format!(
r##"
| Metadata | |
| -------- | --- |
| Owner(s) | {owners} |
| Team(s) | {teams} |
| Goal document | [{timeframe}/{goal_file}](https://rust-lang.github.io/rust-project-goals/{timeframe}/{goal_file}.html) |
| Metadata | |
| -------- | --- |
| Point of contact | {poc} |
| Team(s) | {teams} |
| Goal document | [{timeframe}/{goal_file}](https://rust-lang.github.io/rust-project-goals/{timeframe}/{goal_file}.html) |
## Summary
Expand All @@ -354,7 +354,7 @@ fn issue_text(timeframe: &str, document: &GoalDocument) -> anyhow::Result<String
[Team]: https://img.shields.io/badge/Team%20ask-red
"##,
owners = &document.metadata.owner_usernames().join(", "),
poc = &document.metadata.owner_usernames().join(", "),
teams = teams.join(", "),
summary = document.summary,
tasks = tasks.join("\n"),
Expand Down
Loading

0 comments on commit 532ba38

Please sign in to comment.