Skip to content

Commit f1463d4

Browse files
authored
Merge pull request #1522 from NixOS/no-jq
hydra-plugins: replace jq with perl's own canonical json output
2 parents 94eaad2 + 7fa3da7 commit f1463d4

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

nixos-modules/hydra.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ in
364364
requires = [ "hydra-init.service" ];
365365
restartTriggers = [ hydraConf ];
366366
after = [ "hydra-init.service" "network.target" ];
367-
path = with pkgs; [ hostname-debian cfg.package jq ];
367+
path = with pkgs; [ hostname-debian cfg.package ];
368368
environment = env // {
369369
HYDRA_DBI = "${env.HYDRA_DBI};application_name=hydra-evaluator";
370370
};

src/lib/Hydra/Plugin/BitBucketPulls.pm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use Hydra::Helper::CatalystUtils;
1010
use Hydra::Helper::Nix;
1111
use File::Temp;
1212
use POSIX qw(strftime);
13-
use IPC::Run qw(run);
1413

1514
sub supportedInputTypes {
1615
my ($self, $inputTypes) = @_;
@@ -45,12 +44,11 @@ sub fetchInput {
4544
my $ua = LWP::UserAgent->new();
4645
_iterate("https://api.bitbucket.com/2.0/repositories/$owner/$repo/pullrequests?state=OPEN", $auth, \%pulls, $ua);
4746
my $tempdir = File::Temp->newdir("bitbucket-pulls" . "XXXXX", TMPDIR => 1);
48-
my $filename = "$tempdir/bitbucket-pulls.json";
47+
my $filename = "$tempdir/bitbucket-pulls-sorted.json";
4948
open(my $fh, ">", $filename) or die "Cannot open $filename for writing: $!";
50-
print $fh encode_json \%pulls;
49+
print $fh JSON::MaybeXS->new(canonical => 1, pretty => 1)->encode(\%pulls);
5150
close $fh;
52-
run(["jq", "-S", "."], '<', $filename, '>', "$tempdir/bitbucket-pulls-sorted.json") or die "jq command failed: $?";
53-
my $storePath = addToStore("$tempdir/bitbucket-pulls-sorted.json");
51+
my $storePath = addToStore($filename);
5452
my $timestamp = time;
5553
return { storePath => $storePath, revision => strftime "%Y%m%d%H%M%S", gmtime($timestamp) };
5654
}

src/lib/Hydra/Plugin/GithubRefs.pm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use Hydra::Helper::CatalystUtils;
1010
use Hydra::Helper::Nix;
1111
use File::Temp;
1212
use POSIX qw(strftime);
13-
use IPC::Run qw(run);
1413

1514
=head1 NAME
1615
@@ -112,12 +111,11 @@ sub fetchInput {
112111
my $ua = LWP::UserAgent->new();
113112
_iterate("$githubEndpoint/repos/$owner/$repo/git/matching-refs/$type/$prefix?per_page=100", $auth, \%refs, $ua);
114113
my $tempdir = File::Temp->newdir("github-refs" . "XXXXX", TMPDIR => 1);
115-
my $filename = "$tempdir/github-refs.json";
114+
my $filename = "$tempdir/github-refs-sorted.json";
116115
open(my $fh, ">", $filename) or die "Cannot open $filename for writing: $!";
117-
print $fh encode_json \%refs;
116+
print $fh JSON::MaybeXS->new(canonical => 1, pretty => 1)->encode(\%refs);
118117
close $fh;
119-
run(["jq", "-S", "."], '<', $filename, '>', "$tempdir/github-refs-sorted.json") or die "jq command failed: $?";
120-
my $storePath = addToStore("$tempdir/github-refs-sorted.json");
118+
my $storePath = addToStore($filename);
121119
my $timestamp = time;
122120
return { storePath => $storePath, revision => strftime "%Y%m%d%H%M%S", gmtime($timestamp) };
123121
}

src/lib/Hydra/Plugin/GitlabPulls.pm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use Hydra::Helper::CatalystUtils;
2424
use Hydra::Helper::Nix;
2525
use File::Temp;
2626
use POSIX qw(strftime);
27-
use IPC::Run qw(run);
2827

2928
sub supportedInputTypes {
3029
my ($self, $inputTypes) = @_;
@@ -83,12 +82,11 @@ sub fetchInput {
8382
_iterate($url, $baseUrl, \%pulls, $ua, $target_repo_url);
8483

8584
my $tempdir = File::Temp->newdir("gitlab-pulls" . "XXXXX", TMPDIR => 1);
86-
my $filename = "$tempdir/gitlab-pulls.json";
85+
my $filename = "$tempdir/gitlab-pulls-sorted.json";
8786
open(my $fh, ">", $filename) or die "Cannot open $filename for writing: $!";
88-
print $fh encode_json \%pulls;
87+
print $fh JSON::MaybeXS->new(canonical => 1, pretty => 1)->encode(\%pulls);
8988
close $fh;
90-
run(["jq", "-S", "."], '<', $filename, '>', "$tempdir/gitlab-pulls-sorted.json") or die "jq command failed: $?";
91-
my $storePath = addToStore("$tempdir/gitlab-pulls-sorted.json");
89+
my $storePath = addToStore($filename);
9290
my $timestamp = time;
9391
return { storePath => $storePath, revision => strftime "%Y%m%d%H%M%S", gmtime($timestamp) };
9492
}

0 commit comments

Comments
 (0)