This commit is contained in:
Aaron Bieber 2023-05-22 19:12:52 -06:00
commit aa16335095
No known key found for this signature in database
7 changed files with 264 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.direnv
*.bak
result
.pls_cache

15
LICENSE Normal file
View File

@ -0,0 +1,15 @@
/*
* Copyright (c) 2023 Aaron Bieber <aaron@bolddaemon.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

24
Makefile.PL Normal file
View File

@ -0,0 +1,24 @@
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'pr-status',
VERSION_FROM => 'pr-status.pl',
EXE_FILES => [qw(pr-status.pl)],
LICENSE => 'ISC',
MIN_PERL_VERSION => '5.006',
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
repository => {
type => 'git',
url => 'https://github.com/qbit/pr-status.git',
web => 'https://github.com/qbit/pr-status',
},
},
},
PREREQ_PM => {
'JSON' => '0',
'Mojolicious' => '0',
'Git' => '0',
},
);

26
flake.lock generated Normal file
View File

@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1684580438,
"narHash": "sha256-LUPswmDn6fXP3lEBJFA2Id8PkcYDgzUilevWackYVvQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "7dc71aef32e8faf065cb171700792cf8a65c152d",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-22.11",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

55
flake.nix Normal file
View File

@ -0,0 +1,55 @@
{
description = "pr-status: a tool to query NixOS/nixpkgs pull request status as they move along the build chain";
inputs.nixpkgs.url = "nixpkgs/nixos-22.11";
outputs = { self, nixpkgs }:
let
supportedSystems =
[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in {
packages = forAllSystems (system:
let pkgs = nixpkgsFor.${system};
in {
pr-status = pkgs.stdenv.mkDerivation {
pname = "pr-status";
version = "v0.0.1";
src = ./.;
buildInputs = with pkgs.perlPackages; [ PerlTidy ];
nativeBuildInputs = with pkgs.perlPackages; [ perl ];
propagatedBuildInputs = with pkgs.perlPackages; [
Mojolicious
JSON
Git
];
outputs = [ "out" "dev" ];
};
});
defaultPackage = forAllSystems (system: self.packages.${system}.pr-status);
devShells = forAllSystems (system:
let pkgs = nixpkgsFor.${system};
in {
default = pkgs.mkShell {
shellHook = ''
PS1='\u@\h:\@; '
nix flake run github:qbit/xin#flake-warn
echo "Perl `${pkgs.perl}/bin/perl --version`"
'';
buildInputs = with pkgs.perlPackages; [
Git
JSON
Mojolicious
perl
PerlCritic
PerlTidy
];
};
});
};
}

139
pr-status.pl Executable file
View File

@ -0,0 +1,139 @@
#!/usr/bin/env perl
# vim: set ts=4 sw=4 tw=0:
# vim: set expandtab:
use strict;
use warnings;
use v5.32;
use Git;
use JSON qw( from_json );
use Mojolicious::Lite -signatures;
use Time::HiRes qw( time );
my $VERSION = 'v0.0.1';
my $repo_dir = "/home/qbit/gostart_nixpkgs";
$ENV{"GIT_CONFIG_SYSTEM"} = ""; # Ignore insteadOf rules
$ENV{"HOME"} = "/tmp"; # Ignore ~/.netrc
Git::command( 'clone', 'https://github.com/nixos/nixpkgs', $repo_dir )
if !-e $repo_dir;
my $repo = Git->repository( Directory => $repo_dir );
my $lock = 0;
sub get_commit {
my $pr = shift;
$repo->command( 'fetch', 'origin', "pull/${pr}/head:pr-status-${pr}" );
$repo->command( 'checkout', "pr-status-$pr" );
my $commit = $repo->command( 'rev-parse', 'HEAD' );
$repo->command( 'checkout', 'master' );
chomp $commit;
return $commit;
}
sub check_nixpkg_branches {
my $commit = shift;
my $list = [];
return $list if $commit eq "";
my $branches = $repo->command( 'branch', '-r', '--contains', $commit );
foreach my $b ( split( '\n', $branches ) ) {
$b =~ s/^\s+origin\///g;
push( @$list, $b ) if $b =~ m/nixos|nixpkgs|staging|master/;
}
return $list;
}
sub figure_status {
my $list = shift;
my $release = shift;
my $status = {
state => "complete",
info => {}
};
my @unstable =
qw/ nixos-unstable nixos-unstable-small nixpkgs-unstable staging staging-next /;
my @stable = qw/ release-22.11 nixos-22.11-small nixos-22.11 /;
my @other = qw / master /;
if ( $release eq "stable" ) {
foreach my $s (@stable) {
$status->{info}->{$s} = grep /$s/, @{$list};
}
}
if ( $release eq "unstable" ) {
foreach my $s (@unstable) {
$status->{info}->{$s} = grep /^$s$/, @{$list};
}
}
foreach my $b ( keys %{ $status->{info} } ) {
if ( !$status->{info}->{$b} ) {
$status->{state} = "open";
last;
}
}
return $status;
}
get '/gc' => sub ($c) {
my $start = time;
$repo->command('gc');
my $end = time;
$c->render(
json => {
updateTime => sprintf( "%2f", $end - $start ),
action => 'gc'
}
);
};
get '/update' => sub ($c) {
my $start = time;
$repo->command('fetch');
my $end = time;
$c->render(
json => {
updateTime => sprintf( "%2f", $end - $start ),
action => 'update'
}
);
};
get '/:release/:pr' => sub ($c) {
my $pr = $c->param('pr');
my $release = $c->param('release');
return unless $pr =~ m/^\d+$/;
my $commit = get_commit($pr);
my $start = time;
my $list = check_nixpkg_branches $commit;
my $end = time;
my $status = figure_status( $list, $release );
my $result = {
branches => $list,
pull_request => $pr,
status => $status->{state},
status_info => $status->{info},
queryTime => sprintf( "%2f", $end - $start )
};
$c->render( json => $result );
};
app->start;