feat: allow pr tracking

This commit is contained in:
Patrick 2024-11-11 20:05:59 +01:00
parent 73b4b6401f
commit 8ab1cac7b5
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F
5 changed files with 1930 additions and 5 deletions

1752
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,3 +4,9 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
clap = { version = "4.5.20", features = ["derive"] }
color-eyre = "0.6.3"
reqwest = "0.12.9"
serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.132"
tokio = { version = "1.41.1", features = ["full"] }

View file

@ -19,6 +19,7 @@
inputs.nci.flakeModule inputs.nci.flakeModule
inputs.pre-commit-hooks.flakeModule inputs.pre-commit-hooks.flakeModule
inputs.treefmt-nix.flakeModule inputs.treefmt-nix.flakeModule
./nic.nix
]; ];
systems = [ systems = [
@ -59,8 +60,12 @@
]; ];
env = [ env = [
{ {
name = ""; name = "LELE";
value = ""; prefix = "lolo";
}
{
name = "LELE";
prefix = "lolo";
} }
]; ];
devshell.startup.pre-commit.text = config.pre-commit.installationScript; devshell.startup.pre-commit.text = config.pre-commit.installationScript;
@ -82,7 +87,23 @@
# Rust # Rust
nci.projects.nixp-meta.path = ./.; nci.projects.nixp-meta.path = ./.;
nci.crates.nixp-meta = { }; nci.crates.nixp-meta = rec {
numtideDevshell = "default";
depsDrvConfig = {
mkDerivation = {
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = with pkgs; [
openssl
];
};
};
drvConfig = {
mkDerivation = {
nativeBuildInputs = [ pkgs.pkg-config ];
inherit (depsDrvConfig.mkDerivation) buildInputs;
};
};
};
# devShells.default = config.nci.outputs.main.devShell.overrideAttrs (old: { # devShells.default = config.nci.outputs.main.devShell.overrideAttrs (old: {
# nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.cargo-release ]; # nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.cargo-release ];

66
nic.nix Normal file
View file

@ -0,0 +1,66 @@
{
perSystem =
{
lib,
config,
...
}:
{
options.nci.crates = lib.mkOption {
type = lib.types.lazyAttrsOf (
lib.types.submoduleWith {
modules = [
{
options = {
numtideDevshell = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
If set, the given numtide devshell will be populated with
the required packages and environment variables for this crate.
'';
};
};
}
];
}
);
};
config.devshells = lib.mkMerge (
lib.flatten (
lib.flip lib.mapAttrsToList config.nci.crates (
project: cfg:
lib.optional (cfg.numtideDevshell != null) {
${cfg.numtideDevshell} = {
packagesFrom = [ config.nci.toolchains.shell ];
packages =
(lib.flatten (
map (f: [
(lib.getDev f)
f
]) config.nci.outputs.${project}.devShell.packages
))
++ [ config.nci.toolchains.shell ];
env =
(lib.mapAttrsToList (k: v: {
name = k;
value = v;
}) config.nci.outputs.${project}.devShell.env)
++ [
{
name = "PKG_CONFIG_PATH";
prefix = "$DEVSHELL_DIR/lib/pkgconfig";
}
{
name = "LD_LIBRARY_PATH";
prefix = "$DEVSHELL_DIR/lib";
}
];
};
}
)
)
);
};
}

View file

@ -1,3 +1,83 @@
fn main() { use clap::{Args, Parser, Subcommand};
println!("Hello, world!"); use color_eyre::eyre::Result;
use reqwest::Client;
use serde::Deserialize;
#[derive(Parser)]
#[command(version, about)]
struct Cli {
#[command(subcommand)]
command: CliCommands,
}
#[derive(Subcommand)]
enum CliCommands {
Track(Track),
}
#[derive(Args, Debug, Default)]
struct Track {
pr: String,
}
const BRANCHES: &[&str] = &[
"master",
"staging-next",
"nixos-unstable-small",
"nixos-unstable",
];
#[derive(Debug, Deserialize)]
struct PR {
title: String,
state: String,
merged_at: Option<String>,
merge_commit_sha: String,
}
#[derive(Debug, Deserialize)]
struct Compare {
status: String,
}
async fn get_pr(pr: &str, client: &Client) -> Result<PR> {
let request = client
.get(format!(
"https://api.github.com/repos/nixos/nixpkgs/pulls/{}",
pr
))
.send();
let text = request.await?.text().await?;
let v: PR = serde_json::from_str(&text)?;
Ok(v)
}
async fn contains(branch: &str, pr: &PR, client: &Client) -> Result<bool> {
let req = client
.get(format!(
"https://api.github.com/repos/nixos/nixpkgs/compare/{}...{}",
branch, pr.merge_commit_sha
))
.send();
let text = &req.await?.text().await?;
let v: Compare = serde_json::from_str(text)?;
if v.status == "identical" || v.status == "behind" {
return Ok(true);
}
Ok(false)
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
let client = Client::builder().user_agent("nixp-meta tool").build()?;
match &cli.command {
CliCommands::Track(track) => {
let pr = get_pr(&track.pr, &client).await?;
println!("{}", pr.title);
for &i in BRANCHES {
println!("{}: {}", i, contains(i, &pr, &client).await?);
}
}
};
Ok(())
} }