feat: remove tracking file
This commit is contained in:
parent
b6a6a87179
commit
6cdabd1b61
|
@ -13,8 +13,8 @@ Using `nixp-meta track <pr>` on can see which nixpkgs branches a pull requests h
|
|||
|
||||
If you cannot wait for a PR to be merged, or just want to test it while it's still being worked on, this module is for you.
|
||||
|
||||
`nixp-meta add-pr <pr>` Downloads the diff for the specified PR to a folder (default `./patches/PR`) and updates a tracking file(default `pr.txt`).
|
||||
`nixp-meta update-prs` then uses that tracking file to update all prs contained.
|
||||
`nixp-meta add-pr <pr>` Downloads the diff for the specified PR to a folder (default `./patches/PR`)
|
||||
`nixp-meta update-prs` updates all prs.
|
||||
|
||||
Then using below module one can alter nixpkgs to use these patches
|
||||
|
||||
|
|
85
src/main.rs
85
src/main.rs
|
@ -1,8 +1,7 @@
|
|||
use std::{
|
||||
env,
|
||||
fmt::Write,
|
||||
fs::{self, File, OpenOptions},
|
||||
io::{self, BufRead, BufReader},
|
||||
fs::{self, read_dir, File, OpenOptions},
|
||||
io::BufReader,
|
||||
};
|
||||
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
|
@ -22,8 +21,6 @@ struct Cli {
|
|||
enum CliCommands {
|
||||
/// Track how far a PR has made it in the nix pipeline
|
||||
Track(Track),
|
||||
/// Download a diff without touching the tracking file
|
||||
GetDiff(GetDiff),
|
||||
/// Update all PR, removing them if they are contained in your local nixpkgs
|
||||
UpdatePrs(UpdatePRs),
|
||||
/// Unconditionally add a new PR
|
||||
|
@ -32,23 +29,14 @@ enum CliCommands {
|
|||
|
||||
#[derive(Args, Debug, Default)]
|
||||
struct UpdatePRs {
|
||||
#[arg(long, default_value_t = ("./pr.txt".to_string()))]
|
||||
pr_file: String,
|
||||
#[arg(long, default_value_t = ("./patches/PR".to_string()))]
|
||||
path: String,
|
||||
#[arg(long)]
|
||||
pr: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug, Default)]
|
||||
struct AddPR {
|
||||
pr: String,
|
||||
#[arg(long, default_value_t = ("./pr.txt".to_string()))]
|
||||
pr_file: String,
|
||||
#[arg(long, default_value_t = ("./patches/PR".to_string()))]
|
||||
path: String,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug, Default)]
|
||||
struct GetDiff {
|
||||
pr: String,
|
||||
#[arg(long, default_value_t = ("./patches/PR".to_string()))]
|
||||
path: String,
|
||||
|
@ -176,51 +164,42 @@ async fn main() -> Result<()> {
|
|||
println!("{}: {}", i, contains(i, &pr, &client).await?);
|
||||
}
|
||||
}
|
||||
CliCommands::GetDiff(opts) => {
|
||||
let pr = parse_pr(&opts.pr)?;
|
||||
get_diff(pr, &opts.path, &client).await?;
|
||||
}
|
||||
CliCommands::UpdatePrs(opts) => {
|
||||
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?;
|
||||
let l = if let Some((pr, _)) = l.split_once("#") {
|
||||
let pr = pr.trim();
|
||||
pr.parse::<u32>()?
|
||||
} else {
|
||||
let l = l.trim();
|
||||
l.parse::<u32>()?
|
||||
};
|
||||
let pr = get_pr(l, &client).await?;
|
||||
println!("Fetching diff for PR #{}: {}", l, pr.title);
|
||||
let branch = get_local_nixp_rev()?;
|
||||
if contains(&branch, &pr, &client).await? {
|
||||
println!("PR is contained in your local nixpkgs, removing diff");
|
||||
fs::remove_file(format!("{}/{}.diff", opts.path, l))?;
|
||||
} else {
|
||||
get_diff(l, &opts.path, &client).await?;
|
||||
trackable.push((l, pr.title));
|
||||
}
|
||||
let re = Regex::new(r"^[0-9]*.diff$")?;
|
||||
let prs = read_dir(&opts.path)?.filter(|x| {
|
||||
x.as_ref().is_ok_and(|x| {
|
||||
x.metadata().is_ok_and(|x| x.file_type().is_file())
|
||||
&& x.file_name().to_str().is_some_and(|x| re.is_match(x))
|
||||
})
|
||||
});
|
||||
for l in prs {
|
||||
let l = l?.file_name();
|
||||
let l = l
|
||||
.to_str()
|
||||
.to_owned()
|
||||
.and_then(|x| x.strip_suffix(".diff").to_owned());
|
||||
let l = if let Some(pr) = l {
|
||||
let pr = pr.trim();
|
||||
pr.parse::<u32>()?
|
||||
} else {
|
||||
bail!("This shouldn't happen")
|
||||
};
|
||||
let pr = get_pr(l, &client).await?;
|
||||
println!("Fetching diff for PR #{}: {}", l, pr.title);
|
||||
let branch = get_local_nixp_rev()?;
|
||||
if contains(&branch, &pr, &client).await? {
|
||||
println!("PR is contained in your local nixpkgs, removing diff");
|
||||
fs::remove_file(format!("{}/{}.diff", opts.path, l))?;
|
||||
} else {
|
||||
get_diff(l, &opts.path, &client).await?;
|
||||
trackable.push((l, pr.title));
|
||||
}
|
||||
}
|
||||
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)?;
|
||||
}
|
||||
CliCommands::AddPr(opts) => {
|
||||
let pr = parse_pr(&opts.pr)?;
|
||||
get_diff(pr, &opts.path, &client).await?;
|
||||
let pr = get_pr(pr, &client).await?;
|
||||
let title = pr.title.replace("\n", "//");
|
||||
let mut file = OpenOptions::new().append(true).open(&opts.pr_file)?;
|
||||
use std::io::Write;
|
||||
writeln!(file, "{} # {}", pr.number, title)?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue