use strict;
use warnings;
use parent 'Hydra::Plugin';
use HTTP::Request;
use JSON::MaybeXS;
use LWP::UserAgent;
use Hydra::Helper::CatalystUtils;
{
my ($self) = @_;
return ($self->{ }->{ } // 0) == 1;
}
{
my ($buildStatus) = @_;
if ($buildStatus == 0) {
return "SUCCESSFUL";
} else {
return "FAILED";
}
}
{
my ($self, $topbuild, $dependents, $finished) = @_;
my $bitbucket = $self->{ }->{ };
my $baseurl = $self->{ }->{'base_uri'} || "http://localhost:3000";
foreach my $build ($topbuild, @{$dependents}) {
my $jobName = showJobName $build;
my $evals = $topbuild->jobsetevals;
my $ua = LWP::UserAgent->new();
my $body = encode_json(
{
state => $finished ? toBitBucketState($build->buildstatus) : "INPROGRESS",
url => "$baseurl/build/" . $build->id,
name => $jobName,
key => $build->id,
description => "Hydra build #" . $build->id . " of $jobName",
});
while (my $eval = $evals->next) {
foreach my $i ($eval->jobsetevalinputs){
next unless defined $i;
# Skip if the emailResponsible field is disabled
my $input = $eval->jobset->jobsetinputs->find({name => $i->name });
next unless $input->emailresponsible;
my $uri = $i->uri;
my $rev = $i->revision;
# Skip if the uri is not a bitbucket repo
next unless index($uri, 'bitbucket') != -1;
$uri =~ m![:/]([^/]+)/([^/]+?)?$!;
my $owner = $1;
my $repo = $2;
my $req = HTTP::Request->new('POST', "https://api.bitbucket.org/2.0/repositories/$owner/$repo/commit/$rev/statuses/build");
$req->header('Content-Type' => 'application/json');
$req->authorization_basic($bitbucket->{ }, $bitbucket->{ });
$req->content($body);
my $res = $ua->request($req);
print STDERR $res->status_line, ": ", $res->decoded_content, "\n" unless $res->is_success;
}
}
}
}
{
common(@_, [], 0);
}
{
common(@_, [], 0);
}
{
common(@_, 1);
}
1;