Plugins: Add isEnabled method
Plugins are now disabled at startup time unless there is some relevant configuration in hydra.conf. This avoids hydra-notify having to do a lot of redundant work (a lot of plugins did a lot of database queries *before* deciding they were disabled). Note: BitBucketStatus users will need to add 'enable_bitbucket_status = 1' to hydra.conf.
This commit is contained in:
parent
f49a089fc0
commit
16811d3e78
12 changed files with 59 additions and 3 deletions
|
@ -12,11 +12,15 @@ sub new {
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
sub instantiate {
|
sub instantiate {
|
||||||
my ($class, %args) = @_;
|
my ($class, %args) = @_;
|
||||||
my $plugins = [];
|
my $plugins = [];
|
||||||
$args{plugins} = $plugins;
|
$args{plugins} = $plugins;
|
||||||
push @$plugins, $class->plugins(%args);
|
push @$plugins, grep { $_->isEnabled } $class->plugins(%args);
|
||||||
return @$plugins;
|
return @$plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,11 @@ use JSON;
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
use Hydra::Helper::CatalystUtils;
|
use Hydra::Helper::CatalystUtils;
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return $self->{config}->{enable_bitbucket_status} == 1;
|
||||||
|
}
|
||||||
|
|
||||||
sub toBitBucketState {
|
sub toBitBucketState {
|
||||||
my ($buildStatus) = @_;
|
my ($buildStatus) = @_;
|
||||||
if ($buildStatus == 0) {
|
if ($buildStatus == 0) {
|
||||||
|
|
|
@ -7,6 +7,11 @@ use LWP::UserAgent;
|
||||||
use Hydra::Helper::CatalystUtils;
|
use Hydra::Helper::CatalystUtils;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return defined $self->{config}->{circleci};
|
||||||
|
}
|
||||||
|
|
||||||
sub buildFinished {
|
sub buildFinished {
|
||||||
my ($self, $build, $dependents) = @_;
|
my ($self, $build, $dependents) = @_;
|
||||||
my $cfg = $self->{config}->{circleci};
|
my $cfg = $self->{config}->{circleci};
|
||||||
|
|
|
@ -6,6 +6,11 @@ use File::Basename;
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
use Hydra::Helper::CatalystUtils;
|
use Hydra::Helper::CatalystUtils;
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return defined $self->{config}->{coverityscan};
|
||||||
|
}
|
||||||
|
|
||||||
sub buildFinished {
|
sub buildFinished {
|
||||||
my ($self, $b, $dependents) = @_;
|
my ($self, $b, $dependents) = @_;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@ use Hydra::Helper::Nix;
|
||||||
use Hydra::Helper::CatalystUtils;
|
use Hydra::Helper::CatalystUtils;
|
||||||
use Hydra::Helper::Email;
|
use Hydra::Helper::Email;
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return $self->{config}->{email_notification} == 1;
|
||||||
|
}
|
||||||
|
|
||||||
my $template = <<EOF;
|
my $template = <<EOF;
|
||||||
Hi,
|
Hi,
|
||||||
|
@ -44,8 +48,6 @@ EOF
|
||||||
sub buildFinished {
|
sub buildFinished {
|
||||||
my ($self, $build, $dependents) = @_;
|
my ($self, $build, $dependents) = @_;
|
||||||
|
|
||||||
return unless $self->{config}->{email_notification} // 0;
|
|
||||||
|
|
||||||
die unless $build->finished;
|
die unless $build->finished;
|
||||||
|
|
||||||
# Figure out to whom to send notification for each build. For
|
# Figure out to whom to send notification for each build. For
|
||||||
|
|
|
@ -8,6 +8,11 @@ use LWP::UserAgent;
|
||||||
use Hydra::Helper::CatalystUtils;
|
use Hydra::Helper::CatalystUtils;
|
||||||
use List::Util qw(max);
|
use List::Util qw(max);
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return defined $self->{config}->{githubstatus};
|
||||||
|
}
|
||||||
|
|
||||||
sub toGithubState {
|
sub toGithubState {
|
||||||
my ($buildStatus) = @_;
|
my ($buildStatus) = @_;
|
||||||
if ($buildStatus == 0) {
|
if ($buildStatus == 0) {
|
||||||
|
|
|
@ -16,6 +16,11 @@ use List::Util qw(max);
|
||||||
# - gitlab_project_id => ID of the project in Gitlab, i.e. in the above
|
# - gitlab_project_id => ID of the project in Gitlab, i.e. in the above
|
||||||
# case the ID in gitlab of "nixexprs"
|
# case the ID in gitlab of "nixexprs"
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return defined $self->{config}->{gitlab_authorization};
|
||||||
|
}
|
||||||
|
|
||||||
sub toGitlabState {
|
sub toGitlabState {
|
||||||
my ($status, $buildStatus) = @_;
|
my ($status, $buildStatus) = @_;
|
||||||
if ($status == 0) {
|
if ($status == 0) {
|
||||||
|
|
|
@ -5,6 +5,11 @@ use parent 'Hydra::Plugin';
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
use Hydra::Helper::CatalystUtils;
|
use Hydra::Helper::CatalystUtils;
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return defined $self->{config}->{hipchat};
|
||||||
|
}
|
||||||
|
|
||||||
sub buildFinished {
|
sub buildFinished {
|
||||||
my ($self, $build, $dependents) = @_;
|
my ($self, $build, $dependents) = @_;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,11 @@ use HTTP::Request;
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
# use Hydra::Helper::CatalystUtils;
|
# use Hydra::Helper::CatalystUtils;
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return defined $self->{config}->{influxdb};
|
||||||
|
}
|
||||||
|
|
||||||
sub toBuildStatusDetailed {
|
sub toBuildStatusDetailed {
|
||||||
my ($buildStatus) = @_;
|
my ($buildStatus) = @_;
|
||||||
if ($buildStatus == 0) {
|
if ($buildStatus == 0) {
|
||||||
|
|
|
@ -5,6 +5,11 @@ use parent 'Hydra::Plugin';
|
||||||
use experimental 'smartmatch';
|
use experimental 'smartmatch';
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return defined $self->{config}->{runcommand};
|
||||||
|
}
|
||||||
|
|
||||||
sub configSectionMatches {
|
sub configSectionMatches {
|
||||||
my ($name, $project, $jobset, $job) = @_;
|
my ($name, $project, $jobset, $job) = @_;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,11 @@ use Nix::Store;
|
||||||
use Hydra::Model::DB;
|
use Hydra::Model::DB;
|
||||||
use Hydra::Helper::CatalystUtils;
|
use Hydra::Helper::CatalystUtils;
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return defined $self->{config}->{s3backup};
|
||||||
|
}
|
||||||
|
|
||||||
my $client;
|
my $client;
|
||||||
my %compressors = (
|
my %compressors = (
|
||||||
xz => "| $Nix::Config::xz",
|
xz => "| $Nix::Config::xz",
|
||||||
|
|
|
@ -7,6 +7,11 @@ use LWP::UserAgent;
|
||||||
use Hydra::Helper::CatalystUtils;
|
use Hydra::Helper::CatalystUtils;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
|
sub isEnabled {
|
||||||
|
my ($self) = @_;
|
||||||
|
return defined $self->{config}->{slack};
|
||||||
|
}
|
||||||
|
|
||||||
sub renderDuration {
|
sub renderDuration {
|
||||||
my ($build) = @_;
|
my ($build) = @_;
|
||||||
my $duration = $build->stoptime - $build->starttime;
|
my $duration = $build->stoptime - $build->starttime;
|
||||||
|
|
Loading…
Reference in a new issue