diff --git a/src/main.rs b/src/main.rs index e0789db..76bfae3 100644 --- a/src/main.rs +++ b/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, merge_commit_sha: String, + mergeable: bool, } #[derive(Debug, Deserialize)] @@ -65,6 +77,14 @@ async fn contains(branch: &str, pr: &PR, client: &Client) -> Result { } 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(()) }