feat: add diff download
This commit is contained in:
parent
8ab1cac7b5
commit
41d5af895e
23
src/main.rs
23
src/main.rs
|
@ -1,3 +1,5 @@
|
|||
use std::fs;
|
||||
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use color_eyre::eyre::Result;
|
||||
use reqwest::Client;
|
||||
|
@ -13,6 +15,14 @@ struct Cli {
|
|||
#[derive(Subcommand)]
|
||||
enum CliCommands {
|
||||
Track(Track),
|
||||
GetDiff(GetDiff),
|
||||
}
|
||||
|
||||
#[derive(Args, Debug, Default)]
|
||||
struct GetDiff {
|
||||
pr: String,
|
||||
#[arg(long, default_value_t = ("./patches/PR".to_string()))]
|
||||
path: String,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug, Default)]
|
||||
|
@ -31,8 +41,10 @@ const BRANCHES: &[&str] = &[
|
|||
struct PR {
|
||||
title: String,
|
||||
state: String,
|
||||
merged: bool,
|
||||
merged_at: Option<String>,
|
||||
merge_commit_sha: String,
|
||||
mergeable: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -65,6 +77,14 @@ async fn contains(branch: &str, pr: &PR, client: &Client) -> Result<bool> {
|
|||
}
|
||||
Ok(false)
|
||||
}
|
||||
async fn get_diff(pr: &str, path: &str, client: &Client) -> Result<()> {
|
||||
let req = client
|
||||
.get(format!("https://github.com/nixos/nixpkgs/pull/{}.diff", pr))
|
||||
.send();
|
||||
let text = &req.await?.text().await?;
|
||||
fs::write(format!("{}/{}.diff", path, pr), text)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
|
@ -78,6 +98,9 @@ async fn main() -> Result<()> {
|
|||
println!("{}: {}", i, contains(i, &pr, &client).await?);
|
||||
}
|
||||
}
|
||||
CliCommands::GetDiff(opts) => {
|
||||
get_diff(&opts.pr, &opts.path, &client).await?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue