feat: add diff download

This commit is contained in:
Patrick 2024-11-11 20:33:33 +01:00
parent 8ab1cac7b5
commit 41d5af895e
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F

View file

@ -1,3 +1,5 @@
use std::fs;
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
use color_eyre::eyre::Result; use color_eyre::eyre::Result;
use reqwest::Client; use reqwest::Client;
@ -13,6 +15,14 @@ struct Cli {
#[derive(Subcommand)] #[derive(Subcommand)]
enum CliCommands { enum CliCommands {
Track(Track), 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)] #[derive(Args, Debug, Default)]
@ -31,8 +41,10 @@ const BRANCHES: &[&str] = &[
struct PR { struct PR {
title: String, title: String,
state: String, state: String,
merged: bool,
merged_at: Option<String>, merged_at: Option<String>,
merge_commit_sha: String, merge_commit_sha: String,
mergeable: bool,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -65,6 +77,14 @@ async fn contains(branch: &str, pr: &PR, client: &Client) -> Result<bool> {
} }
Ok(false) 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] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
@ -78,6 +98,9 @@ async fn main() -> Result<()> {
println!("{}: {}", i, contains(i, &pr, &client).await?); println!("{}: {}", i, contains(i, &pr, &client).await?);
} }
} }
CliCommands::GetDiff(opts) => {
get_diff(&opts.pr, &opts.path, &client).await?;
}
}; };
Ok(()) Ok(())
} }