Skip to content

Commit 2cbdd42

Browse files
authored
Merge pull request #429 from rust-lang/2026-updates-rexeg
Use the new regex timespan format everywhere
2 parents c26603c + b3750a1 commit 2cbdd42

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

crates/rust-project-goals-cli/src/cfp.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use regex::Regex;
22
use rust_project_goals::spanned::{Error, Spanned};
33
use rust_project_goals::{spanned::Context as _, spanned::Result};
4+
use rust_project_goals::util::MILESTONE_REGEX;
45
use std::fs::{self, File};
56
use std::io::Write;
67
use std::path::{Path, PathBuf};
@@ -9,6 +10,8 @@ use std::path::{Path, PathBuf};
910
pub mod text_processing {
1011
use regex::Regex;
1112

13+
use super::MILESTONE_REGEX;
14+
1215
use crate::cfp::normalize_timeframe;
1316

1417
/// Process template content by replacing placeholders and removing notes
@@ -143,7 +146,7 @@ pub mod text_processing {
143146
// Find a good place to insert the new section
144147
// Look for the last timeframe section or insert after # Summary
145148
// Match both year-only (2027) and half-year (2026H1) formats
146-
let re = Regex::new(r"# ⏳ \d{4}([hH][12])? goal process").unwrap();
149+
let re = Regex::new(&format!(r"# ⏳ {MILESTONE_REGEX} goal process")).unwrap();
147150

148151
if let Some(last_match) = re.find_iter(&content).last() {
149152
// Find the end of this section (next section or end of file)
@@ -371,7 +374,7 @@ pub fn create_cfp(timeframe: &str, force: bool, dry_run: bool) -> Result<()> {
371374

372375
/// Validates that the timeframe is in the correct format (e.g., "2025h1" or "2025H1" or '2026')
373376
fn validate_timeframe(timeframe: &str) -> Result<()> {
374-
let re = Regex::new(r"^\d{4}([hH][12])?$").unwrap();
377+
let re = Regex::new(MILESTONE_REGEX).unwrap();
375378
if !re.is_match(timeframe) {
376379
return Err(Error::str("Invalid timeframe format. Expected format: YYYYhN or YYYYHN (e.g., 2025h1, 2025H1, 2025h2, or 2025H2"));
377380
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use chrono::{Datelike, NaiveDate};
22
use regex::Regex;
33
use rust_project_goals::re::{HELP_WANTED, TLDR};
44
use rust_project_goals::spanned::{Result, Span, Spanned};
5-
use rust_project_goals::util::comma;
5+
use rust_project_goals::util::{comma, MILESTONE_REGEX};
66
use rust_project_goals::{goal, markwaydown, spanned, team};
77
use rust_project_goals_json::GithubIssueState;
88
use std::path::PathBuf;
@@ -39,7 +39,7 @@ pub fn render_updates(
3939
use_progress_bar: bool,
4040
comment_order: Order,
4141
) -> Result<String> {
42-
let milestone_re = Regex::new(r"^\d{4}[hH][12]$").unwrap();
42+
let milestone_re = Regex::new(MILESTONE_REGEX).unwrap();
4343
if !milestone_re.is_match(milestone) {
4444
spanned::bail_here!(
4545
"the milestone `{}` does not follow the `$year$semester` format, where $semester is `h1` or `h2`",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use walkdir::WalkDir;
99

1010
pub const ARROW: &str = "↳";
1111

12+
pub const MILESTONE_REGEX: &'static str = r"^\d{4}([hH][12])?$";
13+
1214
/// Formats a table as markdown. The input should be a series of rows
1315
/// where each row has the same number of columns.
1416
/// The first row is the headers.

0 commit comments

Comments
 (0)