Merge 07442da487 into 64b0f60368
This commit is contained in:
commit
ea25da911c
3 changed files with 320 additions and 75 deletions
|
|
@ -9,8 +9,10 @@
|
|||
|
||||
namespace PHPCI\Model\Build;
|
||||
|
||||
use Bitbucket\API\Http\Client;
|
||||
use Bitbucket\API\Http\Listener\NormalizeArrayListener;
|
||||
use Bitbucket\API\Http\Listener\OAuthListener;
|
||||
use PHPCI\Model\Build;
|
||||
use PHPCI\Model\Build\RemoteGitBuild;
|
||||
|
||||
/**
|
||||
* BitBucket Build Model
|
||||
|
|
@ -49,4 +51,83 @@ class BitbucketBuild extends RemoteGitBuild
|
|||
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '.git';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send status updates to any relevant third parties (i.e. Github)
|
||||
*/
|
||||
public function sendStatusPostback()
|
||||
{
|
||||
|
||||
$key = \b8\Config::getInstance()->get('phpci.bitbucket.key');
|
||||
$secret = \b8\Config::getInstance()->get('phpci.bitbucket.secret');
|
||||
|
||||
|
||||
if (empty($key) || empty($secret) || empty($this->data['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$project = $this->getProject();
|
||||
|
||||
if (empty($project)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($this->getStatus()) {
|
||||
case 0:
|
||||
case 1:
|
||||
$status = 'INPROGRESS';
|
||||
$description = 'PHPCI build running.';
|
||||
break;
|
||||
case 2:
|
||||
$status = 'SUCCESSFUL';
|
||||
$description = 'PHPCI build passed.';
|
||||
break;
|
||||
case 3:
|
||||
$status = 'FAILED';
|
||||
$description = 'PHPCI build failed.';
|
||||
break;
|
||||
default:
|
||||
$status = 'FAILED';
|
||||
$description = 'PHPCI build failed to complete.';
|
||||
break;
|
||||
}
|
||||
|
||||
$phpciUrl = \b8\Config::getInstance()->get('phpci.url') . '/build/view/' . $this->getId();
|
||||
|
||||
$buildRef = 'PHPCI-PROJECT-' . strtoupper(str_replace(['/', '_'], '-', $project->getReference()));
|
||||
|
||||
if (\strlen($buildRef) >= 40) {
|
||||
// bitbucket has limit for build key length
|
||||
$buildRef = 'PHPCI-PROJECT-' . $this->getProjectId();
|
||||
}
|
||||
|
||||
$params = [];
|
||||
if ($description != "") {
|
||||
$params["description"] = $description;
|
||||
}
|
||||
|
||||
$config = array(
|
||||
'oauth_consumer_key' => $key,
|
||||
'oauth_consumer_secret' => $secret,
|
||||
);
|
||||
|
||||
$client = new Client();
|
||||
$client->addListener(new NormalizeArrayListener());
|
||||
$client->addListener(new OAuthListener($config));
|
||||
$client->setApiVersion('2.0');
|
||||
|
||||
$mandatory = array(
|
||||
'state' => $status,
|
||||
'key' => $buildRef,
|
||||
'url' => $phpciUrl,
|
||||
);
|
||||
|
||||
$params = array_merge($mandatory, $params);
|
||||
|
||||
$client->post(
|
||||
sprintf('repositories/%s/commit/%s/statuses/build', $project->getReference(), $this->getCommitId()),
|
||||
json_encode($params),
|
||||
array('Content-Type' => 'application/json')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue