Skip to content

Commit d9a8dd3

Browse files
authored
Merge pull request #173 from cuviper/draft
Add a `--draft` mode with 📝 edit links
2 parents 16329e6 + a8ae82e commit d9a8dd3

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/main.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ struct ReleaseNotes {
3838
}
3939

4040
fn main() {
41-
let mut args = env::args();
42-
let _ = args.next();
43-
let version = args
44-
.next()
45-
.expect("A version number (xx.yy.zz) for the Rust release is required.");
41+
let mut draft = false;
42+
let mut opt_version = None;
43+
for arg in env::args().skip(1) {
44+
match arg.as_bytes() {
45+
b"--draft" => draft = true,
46+
[b'1', b'.', ..] => opt_version = Some(arg),
47+
_ => panic!("unrecognized argument: {arg:?}"),
48+
}
49+
}
50+
let version =
51+
opt_version.expect("A version number (xx.yy.zz) for the Rust release is required.");
4652
let today = Utc::now().date_naive();
4753

4854
// A known rust release date. (1.42.0)
@@ -86,7 +92,7 @@ fn main() {
8692
compat_relnotes,
8793
internal_changes_relnotes,
8894
other_relnotes,
89-
} = to_sections(relnotes, &mut tracking_rust);
95+
} = to_sections(relnotes, &mut tracking_rust, draft);
9096

9197
let cargo_issues = get_issues_by_milestone(&version, "cargo");
9298

@@ -357,6 +363,7 @@ fn map_to_line_items<'a>(
357363
iter: impl IntoIterator<Item = &'a json::Value>,
358364
tracking_issues: &mut TrackingIssues,
359365
by_section: &mut HashMap<&'static str, String>,
366+
draft: bool,
360367
) {
361368
for o in iter {
362369
let title = o["title"].as_str().unwrap();
@@ -381,6 +388,12 @@ fn map_to_line_items<'a>(
381388
contents.push_str(line);
382389
contents.push('\n');
383390
}
391+
if draft {
392+
contents.push_str(&format!(
393+
" [:pencil:]({})\n",
394+
issue.raw["url"].as_str().unwrap(),
395+
));
396+
}
384397
}
385398
}
386399

@@ -435,6 +448,7 @@ struct Sections {
435448
fn to_sections<'a>(
436449
iter: impl IntoIterator<Item = &'a json::Value>,
437450
mut tracking: &mut TrackingIssues,
451+
draft: bool,
438452
) -> Sections {
439453
let mut by_section = HashMap::new();
440454
by_section.insert("Language", String::new());
@@ -448,7 +462,7 @@ fn to_sections<'a>(
448462
by_section.insert("Platform Support", String::new());
449463
by_section.insert("Other", String::new());
450464

451-
map_to_line_items(iter, &mut tracking, &mut by_section);
465+
map_to_line_items(iter, &mut tracking, &mut by_section, draft);
452466

453467
Sections {
454468
language_relnotes: by_section.remove("Language").unwrap(),

0 commit comments

Comments
 (0)