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.
|
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 add-pr <pr>` Downloads the diff for the specified PR to a folder (default `./patches/PR`)
|
||||||
`nixp-meta update-prs` then uses that tracking file to update all prs contained.
|
`nixp-meta update-prs` updates all prs.
|
||||||
|
|
||||||
Then using below module one can alter nixpkgs to use these patches
|
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::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
fmt::Write,
|
fs::{self, read_dir, File, OpenOptions},
|
||||||
fs::{self, File, OpenOptions},
|
io::BufReader,
|
||||||
io::{self, BufRead, BufReader},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::{Args, Parser, Subcommand};
|
use clap::{Args, Parser, Subcommand};
|
||||||
|
@ -22,8 +21,6 @@ struct Cli {
|
||||||
enum CliCommands {
|
enum CliCommands {
|
||||||
/// Track how far a PR has made it in the nix pipeline
|
/// Track how far a PR has made it in the nix pipeline
|
||||||
Track(Track),
|
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
|
/// Update all PR, removing them if they are contained in your local nixpkgs
|
||||||
UpdatePrs(UpdatePRs),
|
UpdatePrs(UpdatePRs),
|
||||||
/// Unconditionally add a new PR
|
/// Unconditionally add a new PR
|
||||||
|
@ -32,23 +29,14 @@ enum CliCommands {
|
||||||
|
|
||||||
#[derive(Args, Debug, Default)]
|
#[derive(Args, Debug, Default)]
|
||||||
struct UpdatePRs {
|
struct UpdatePRs {
|
||||||
#[arg(long, default_value_t = ("./pr.txt".to_string()))]
|
|
||||||
pr_file: String,
|
|
||||||
#[arg(long, default_value_t = ("./patches/PR".to_string()))]
|
#[arg(long, default_value_t = ("./patches/PR".to_string()))]
|
||||||
path: String,
|
path: String,
|
||||||
|
#[arg(long)]
|
||||||
|
pr: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Args, Debug, Default)]
|
#[derive(Args, Debug, Default)]
|
||||||
struct AddPR {
|
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,
|
pr: String,
|
||||||
#[arg(long, default_value_t = ("./patches/PR".to_string()))]
|
#[arg(long, default_value_t = ("./patches/PR".to_string()))]
|
||||||
path: String,
|
path: String,
|
||||||
|
@ -176,51 +164,42 @@ async fn main() -> Result<()> {
|
||||||
println!("{}: {}", i, contains(i, &pr, &client).await?);
|
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) => {
|
CliCommands::UpdatePrs(opts) => {
|
||||||
let mut trackable: Vec<(u32, String)> = Vec::new();
|
let mut trackable: Vec<(u32, String)> = Vec::new();
|
||||||
{
|
let re = Regex::new(r"^[0-9]*.diff$")?;
|
||||||
let file = File::open(opts.pr_file.clone())?;
|
let prs = read_dir(&opts.path)?.filter(|x| {
|
||||||
for l in io::BufReader::new(file).lines() {
|
x.as_ref().is_ok_and(|x| {
|
||||||
let l = l?;
|
x.metadata().is_ok_and(|x| x.file_type().is_file())
|
||||||
let l = if let Some((pr, _)) = l.split_once("#") {
|
&& x.file_name().to_str().is_some_and(|x| re.is_match(x))
|
||||||
let pr = pr.trim();
|
})
|
||||||
pr.parse::<u32>()?
|
});
|
||||||
} else {
|
for l in prs {
|
||||||
let l = l.trim();
|
let l = l?.file_name();
|
||||||
l.parse::<u32>()?
|
let l = l
|
||||||
};
|
.to_str()
|
||||||
let pr = get_pr(l, &client).await?;
|
.to_owned()
|
||||||
println!("Fetching diff for PR #{}: {}", l, pr.title);
|
.and_then(|x| x.strip_suffix(".diff").to_owned());
|
||||||
let branch = get_local_nixp_rev()?;
|
let l = if let Some(pr) = l {
|
||||||
if contains(&branch, &pr, &client).await? {
|
let pr = pr.trim();
|
||||||
println!("PR is contained in your local nixpkgs, removing diff");
|
pr.parse::<u32>()?
|
||||||
fs::remove_file(format!("{}/{}.diff", opts.path, l))?;
|
} else {
|
||||||
} else {
|
bail!("This shouldn't happen")
|
||||||
get_diff(l, &opts.path, &client).await?;
|
};
|
||||||
trackable.push((l, pr.title));
|
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) => {
|
CliCommands::AddPr(opts) => {
|
||||||
let pr = parse_pr(&opts.pr)?;
|
let pr = parse_pr(&opts.pr)?;
|
||||||
get_diff(pr, &opts.path, &client).await?;
|
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(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue