just/bin/update-contributors/src/main.rs
Casey Rodarmor a81b094441
Downgrade to TLS 1.2 in install script (#1536)
Revert "Update install script and readmes to use tls v1.3 (#1481)"

This reverts commit 9b6b0b7fac.
2023-01-27 02:49:03 +00:00

45 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 {pr} --json author | jq -r .author.login"),
])
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
str::from_utf8(&output.stdout).unwrap().trim().to_owned()
}
fn main() {
fs::write(
"CHANGELOG.md",
&*Regex::new(r"\(#(\d+)( by @[a-z]+)?\)")
.unwrap()
.replace_all(
&fs::read_to_string("CHANGELOG.md").unwrap(),
|captures: &Captures| {
let pr = captures[1].parse().unwrap();
match author(pr).as_str() {
"casey" => format!("([#{pr}](https://github.com/casey/just/pull/{pr}))"),
contributor => {
format!("([#{pr}](https://github.com/casey/just/pull/{pr}) by [{contributor}](https://github.com/{contributor}))")
}
}
},
),
)
.unwrap();
}