2022-10-26 22:48:39 -07:00
|
|
|
use {
|
|
|
|
regex::{Captures, Regex},
|
|
|
|
std::{fs, process::Command, str},
|
|
|
|
};
|
|
|
|
|
|
|
|
fn author(pr: u64) -> String {
|
|
|
|
eprintln!("#{}", pr);
|
|
|
|
let output = Command::new("sh")
|
2022-11-22 16:36:23 -08:00
|
|
|
.args([
|
2022-10-26 22:48:39 -07:00
|
|
|
"-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() {
|
|
|
|
fs::write(
|
|
|
|
"CHANGELOG.md",
|
2022-10-26 23:02:27 -07:00
|
|
|
&*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() {
|
2023-01-01 17:53:53 -08:00
|
|
|
"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}))")
|
|
|
|
}
|
2022-10-26 23:02:27 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2022-10-26 22:48:39 -07:00
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
}
|