just/bin/update-contributors/src/main.rs
Casey Rodarmor c834fb1e4e
Release 1.7.0 (#1386)
- Bump version: 1.6.0 → 1.7.0
- Update changelog
- Update changelog contributor credits
- Update dependencies
- Update man page
- Update version references in readme
2022-10-27 06:02:27 +00:00

52 lines
1.1 KiB
Rust

use {
regex::{Captures, Regex},
std::{fs, process::Command, str},
};
fn author(pr: u64) -> String {
eprintln!("#{}", pr);
let output = Command::new("sh")
.args(&[
"-c",
&format!("gh pr view {} --json author | jq -r .author.login", pr),
])
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
str::from_utf8(&output.stdout).unwrap().trim().to_owned()
}
fn main() {
let mut done = false;
fs::write(
"CHANGELOG.md",
&*Regex::new(r"\(#(\d+)( by @[a-z]+)?\)")
.unwrap()
.replace_all(
&fs::read_to_string("CHANGELOG.md").unwrap(),
|captures: &Captures| {
if captures.get(2).is_some() {
done = true;
}
if done {
captures[0].to_owned()
} else {
let pr = captures[1].parse().unwrap();
match author(pr).as_str() {
"casey" => format!("(#{})", pr),
contributor => format!("(#{} by @{})", pr, contributor),
}
}
},
),
)
.unwrap();
}