use strict;
use warnings;
use parent 'Hydra::Plugin';
use HTTP::Request;
use LWP::UserAgent;
use Hydra::Helper::CatalystUtils;
use JSON::MaybeXS;
{
my ($self) = @_;
return defined $self->{ }->{ };
}
{
my ($self, $topbuild, $dependents) = @_;
my $cfg = $self->{ }->{ };
my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
# Figure out to which branches to send notification.
my %branches;
foreach my $build ($topbuild, @{$dependents}) {
my $prevBuild = getPreviousBuild($build);
my $jobName = showJobName $build;
foreach my $branch (@config) {
my $force = $branch->{ };
next unless $jobName =~ /^$branch->{jobs}$/;
# If build is failed, don't trigger circleci
next if ! $force && $build->buildstatus != 0;
my $fullUrl = "https://circleci.com/api/v1.1/project/" . $branch->{ } . "/" . $branch->{ } . "/" . $branch->{ } . "/tree/" . $branch->{ } . "?circle-token=" . $branch->{ };
$branches{$fullUrl} = 1;
}
}
return if scalar keys %branches == 0;
# Trigger earch branch
my $ua = LWP::UserAgent->new();
foreach my $url (keys %branches) {
my $req = HTTP::Request->new('POST', $url);
$req->header('Content-Type' => 'application/json');
$ua->request($req);
}
}
1;