From db6fcabbf3d23e200553e479d268eb632985e526 Mon Sep 17 00:00:00 2001 From: ahuston-0 Date: Sun, 7 Sep 2025 23:26:43 -0400 Subject: [PATCH] sync gitea changes with github changes --- src/lib/Hydra/Plugin/GiteaPulls.pm | 16 +++++++--------- src/lib/Hydra/Plugin/GiteaRefs.pm | 8 ++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/lib/Hydra/Plugin/GiteaPulls.pm b/src/lib/Hydra/Plugin/GiteaPulls.pm index c43d207d..0e30e448 100644 --- a/src/lib/Hydra/Plugin/GiteaPulls.pm +++ b/src/lib/Hydra/Plugin/GiteaPulls.pm @@ -16,6 +16,7 @@ use HTTP::Request; use LWP::UserAgent; use JSON::MaybeXS; use Hydra::Helper::CatalystUtils; +use Hydra::Helper::Nix; use File::Temp; use POSIX qw(strftime); @@ -26,19 +27,18 @@ sub supportedInputTypes { sub _iterate { my ($url, $auth, $pulls, $ua) = @_; - my $req = HTTP::Request->new('GET', $url); + $req->header('Accept' => 'application/json'); $req->header('Authorization' => 'token ' . $auth) if defined $auth; my $res = $ua->request($req); my $content = $res->decoded_content; die "Error pulling from the gitea pulls API: $content\n" - unless $res->is_success; - + unless $res->is_success; my $pulls_list = decode_json $content; - + # TODO Stream out the json instead foreach my $pull (@$pulls_list) { - $pulls->{$pull->{number}} = $pull; + $pulls->{$pull->{number}} = $pull; } # TODO Make Link header parsing more robust!!! @@ -71,12 +71,10 @@ sub fetchInput { my $tempdir = File::Temp->newdir("gitea-pulls" . "XXXXX", TMPDIR => 1); my $filename = "$tempdir/gitea-pulls.json"; open(my $fh, ">", $filename) or die "Cannot open $filename for writing: $!"; - print $fh encode_json \%pulls; + print $fh JSON->new->utf8->canonical->encode(\%pulls); close $fh; - my $storePath = trim(`nix-store --add "$filename"` - or die "cannot copy path $filename to the Nix store.\n"); - chomp $storePath; + my $storePath = addToStore($filename); my $timestamp = time; return { storePath => $storePath, revision => strftime "%Y%m%d%H%M%S", gmtime($timestamp) }; } diff --git a/src/lib/Hydra/Plugin/GiteaRefs.pm b/src/lib/Hydra/Plugin/GiteaRefs.pm index 1b728009..3e0ba458 100644 --- a/src/lib/Hydra/Plugin/GiteaRefs.pm +++ b/src/lib/Hydra/Plugin/GiteaRefs.pm @@ -7,8 +7,10 @@ use HTTP::Request; use LWP::UserAgent; use JSON::MaybeXS; use Hydra::Helper::CatalystUtils; +use Hydra::Helper::Nix; use File::Temp; use POSIX qw(strftime); +use IPC::Run qw(run); =head1 NAME @@ -118,10 +120,8 @@ sub fetchInput { open(my $fh, ">", $filename) or die "Cannot open $filename for writing: $!"; print $fh encode_json \%refs; close $fh; - system("jq -S . < $filename > $tempdir/gitea-refs-sorted.json"); - my $storePath = trim(qx{nix-store --add "$tempdir/gitea-refs-sorted.json"} - or die "cannot copy path $filename to the Nix store.\n"); - chomp $storePath; + run(["jq", "-S", "."], '<', $filename, '>', "$tempdir/gitea-refs-sorted.json") or die "jq command failed: $?"; + my $storePath = addToStore("$tempdir/gitea-refs-sorted.json"); my $timestamp = time; return { storePath => $storePath, revision => strftime "%Y%m%d%H%M%S", gmtime($timestamp) }; }