feat: allow comments in tracking file

This commit is contained in:
Patrick 2024-11-13 19:13:38 +01:00
parent 070f5b2d49
commit 95eaf0190c
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F

View file

@ -1,4 +1,5 @@
use std::{
fmt::Write,
fs::{self, File},
io::{self, BufRead},
};
@ -134,11 +135,16 @@ async fn main() -> Result<()> {
get_diff(pr, &opts.path, &client).await?;
}
CliCommands::UpdatePrs(opts) => {
let mut trackable: Vec<u32> = Vec::new();
let mut trackable: Vec<(u32, String)> = Vec::new();
{
let file = File::open(opts.pr_file.clone())?;
for l in io::BufReader::new(file).lines() {
let l = l?.parse::<u32>()?;
let l = l?;
let l = if let Some((pr, _)) = l.split_once("#") {
pr.parse::<u32>()?
} else {
bail!("Could not parse line")
};
let pr = get_pr(l, &client).await?;
println!("Fetching diff for PR #{}: {}", l, pr.title);
if contains(&opts.branch, &pr, &client).await? {
@ -146,17 +152,17 @@ async fn main() -> Result<()> {
fs::remove_file(format!("{}/{}.diff", opts.path, l))?;
} else {
get_diff(l, &opts.path, &client).await?;
trackable.push(l.clone());
trackable.push((l, pr.title));
}
}
}
fs::write(
&opts.pr_file,
trackable
.iter()
.map(|x| format!("{}\n", x))
.collect::<String>(),
)?;
let mut str = String::new();
for (pr, title) in trackable {
let title = title.replace("\n", "//");
writeln!(&mut str, "{} # {}", pr, title)?;
}
fs::write(&opts.pr_file, str)?;
}
};
Ok(())