DynamicRunCommand: pull out the function determining if a build is

eligible for execution under dynamic run commands.
This commit is contained in:
Graham Christensen 2021-12-14 16:31:19 -05:00
parent e56c49333f
commit e7f68045f4
2 changed files with 46 additions and 3 deletions

View file

@ -37,6 +37,16 @@ sub areDynamicCommandsEnabled {
return 0;
}
sub isBuildEligibleForDynamicRunCommand {
my ($build) = @_;
if ($build->get_column("job") =~ "^runCommandHook\..+") {
return 1;
}
return 0;
}
sub configSectionMatches {
my ($name, $project, $jobset, $job) = @_;
@ -102,9 +112,8 @@ sub fanoutToCommands {
# 2. what if the result is a directory?
# 3. what if the job doens't have an out?
# 4. what if the build failed?
my $job = $build->get_column('job');
if ($job =~ "^runCommandHook\.") {
if (isBuildEligibleForDynamicRunCommand($build)) {
my $job = $build->get_column('job');
my $out = $build->buildoutputs->find({name => "out"});
push(@commands, {
matcher => "DynamicRunCommand($job)",

View file

@ -105,4 +105,38 @@ subtest "fanoutToCommandsWithDynamicRunCommandSupport" => sub {
);
};
subtest "isBuildEligibleForDynamicRunCommand" => sub {
my $build = Hydra::Schema::Result::Builds->new({
"job" => "foo bar baz"
});
is(
Hydra::Plugin::RunCommand::isBuildEligibleForDynamicRunCommand($build),
0,
"The job name does not match"
);
$build->set_column("job", "runCommandHook");
is(
Hydra::Plugin::RunCommand::isBuildEligibleForDynamicRunCommand($build),
0,
"The job name does not match"
);
$build->set_column("job", "runCommandHook.");
is(
Hydra::Plugin::RunCommand::isBuildEligibleForDynamicRunCommand($build),
0,
"The job name does not match"
);
$build->set_column("job", "runCommandHook.a");
is(
Hydra::Plugin::RunCommand::isBuildEligibleForDynamicRunCommand($build),
1,
"The job name does match"
);
};
done_testing;