feat: allow pr tracking
This commit is contained in:
parent
73b4b6401f
commit
8ab1cac7b5
1752
Cargo.lock
generated
Normal file
1752
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -4,3 +4,9 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[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"] }
|
||||
|
|
27
flake.nix
27
flake.nix
|
@ -19,6 +19,7 @@
|
|||
inputs.nci.flakeModule
|
||||
inputs.pre-commit-hooks.flakeModule
|
||||
inputs.treefmt-nix.flakeModule
|
||||
./nic.nix
|
||||
];
|
||||
|
||||
systems = [
|
||||
|
@ -59,8 +60,12 @@
|
|||
];
|
||||
env = [
|
||||
{
|
||||
name = "";
|
||||
value = "";
|
||||
name = "LELE";
|
||||
prefix = "lolo";
|
||||
}
|
||||
{
|
||||
name = "LELE";
|
||||
prefix = "lolo";
|
||||
}
|
||||
];
|
||||
devshell.startup.pre-commit.text = config.pre-commit.installationScript;
|
||||
|
@ -82,7 +87,23 @@
|
|||
|
||||
# Rust
|
||||
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: {
|
||||
# nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.cargo-release ];
|
||||
|
|
66
nic.nix
Normal file
66
nic.nix
Normal 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";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
84
src/main.rs
84
src/main.rs
|
@ -1,3 +1,83 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue