RunCommand: move JSON generation to its own function
This commit is contained in:
parent
bb91f96381
commit
2ce0ab9f51
|
@ -38,28 +38,8 @@ sub eventMatches {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub buildFinished {
|
||||
my ($self, $build, $dependents) = @_;
|
||||
my $event = "buildFinished";
|
||||
|
||||
my $cfg = $self->{config}->{runcommand};
|
||||
my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
|
||||
|
||||
my $tmp;
|
||||
|
||||
foreach my $conf (@config) {
|
||||
next unless eventMatches($conf, $event);
|
||||
next unless configSectionMatches(
|
||||
$conf->{job} // "*:*:*",
|
||||
$build->get_column('project'),
|
||||
$build->get_column('jobset'),
|
||||
$build->get_column('job'));
|
||||
|
||||
my $command = $conf->{command} // die "<runcommand> section lacks a 'command' option";
|
||||
|
||||
unless (defined $tmp) {
|
||||
$tmp = File::Temp->new(SUFFIX => '.json');
|
||||
|
||||
sub makeJsonPayload {
|
||||
my ($event, $build) = @_;
|
||||
my $json = {
|
||||
event => $event,
|
||||
build => $build->id,
|
||||
|
@ -113,7 +93,31 @@ sub buildFinished {
|
|||
push @{$json->{metrics}}, $j;
|
||||
}
|
||||
|
||||
print $tmp encode_json($json) or die;
|
||||
return $json;
|
||||
}
|
||||
|
||||
sub buildFinished {
|
||||
my ($self, $build, $dependents) = @_;
|
||||
my $event = "buildFinished";
|
||||
|
||||
my $cfg = $self->{config}->{runcommand};
|
||||
my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
|
||||
|
||||
my $tmp;
|
||||
|
||||
foreach my $conf (@config) {
|
||||
next unless eventMatches($conf, $event);
|
||||
next unless configSectionMatches(
|
||||
$conf->{job} // "*:*:*",
|
||||
$build->get_column('project'),
|
||||
$build->get_column('jobset'),
|
||||
$build->get_column('job'));
|
||||
|
||||
my $command = $conf->{command} // die "<runcommand> section lacks a 'command' option";
|
||||
|
||||
unless (defined $tmp) {
|
||||
$tmp = File::Temp->new(SUFFIX => '.json');
|
||||
print $tmp encode_json(makeJsonPayload($event, $build)) or die;
|
||||
}
|
||||
|
||||
$ENV{"HYDRA_JSON"} = $tmp->filename;
|
||||
|
|
Loading…
Reference in a new issue