From 07442da48722e3688342a3255423a68e5b94f430 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Fri, 17 Jun 2016 11:39:43 +0300 Subject: [PATCH] Add support for bitbucket build status API --- PHPCI/Model/Build/BitbucketBuild.php | 83 ++++++- composer.json | 3 +- composer.lock | 309 ++++++++++++++++++++------- 3 files changed, 320 insertions(+), 75 deletions(-) diff --git a/PHPCI/Model/Build/BitbucketBuild.php b/PHPCI/Model/Build/BitbucketBuild.php index 3af0d2b5..6d7d462c 100644 --- a/PHPCI/Model/Build/BitbucketBuild.php +++ b/PHPCI/Model/Build/BitbucketBuild.php @@ -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') + ); + } } diff --git a/composer.json b/composer.json index a9080a94..2440eabc 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,8 @@ "pda/pheanstalk": "~3.1", "maknz/slack": "~1.7", "hipchat/hipchat-php": "~1.4", - "mremi/flowdock": "~1.0" + "mremi/flowdock": "~1.0", + "gentle/bitbucket-api": "0.7.1" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 9714ff78..ebd760bc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "de65276e03e231d7072c744a3c63662e", - "content-hash": "1d9f6f487e6d906bbed73e2667c276d6", + "hash": "8cfc08869e3fb3feccb26e91387bc4ee", + "content-hash": "1ed1fc60527e8bf08bb76466ef252106", "packages": [ { "name": "block8/b8framework", @@ -54,6 +54,60 @@ ], "time": "2015-10-05 10:50:20" }, + { + "name": "gentle/bitbucket-api", + "version": "0.7.1", + "source": { + "type": "git", + "url": "https://github.com/gentlero/bitbucket-api.git", + "reference": "c3de78a5a5939d494cda4293ffae9db47b8d5de9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/gentlero/bitbucket-api/zipball/c3de78a5a5939d494cda4293ffae9db47b8d5de9", + "reference": "c3de78a5a5939d494cda4293ffae9db47b8d5de9", + "shasum": "" + }, + "require": { + "jacobkiers/oauth": "~1.0.10", + "kriswallsmith/buzz": "~0.13", + "php": ">=5.3" + }, + "conflict": { + "eabay/bitbucket-repo-sync": "*" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, + "suggest": { + "ext-curl": "*" + }, + "type": "library", + "autoload": { + "psr-0": { + "Bitbucket\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alexandru Guzinschi", + "email": "alex@gentle.ro", + "homepage": "http://www.sebi.me", + "role": "Developer" + } + ], + "description": "Bitbucket API wrapper for PHP >= 5.3", + "homepage": "https://bitbucket.org/gentlero/bitbucket-api", + "keywords": [ + "api", + "bitbucket" + ], + "time": "2015-11-07 13:31:32" + }, { "name": "guzzle/guzzle", "version": "v3.9.3", @@ -213,16 +267,16 @@ }, { "name": "guzzlehttp/promises", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8" + "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8", - "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8", + "url": "https://api.github.com/repos/guzzle/promises/zipball/c10d860e2a9595f8883527fa0021c7da9e65f579", + "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579", "shasum": "" }, "require": { @@ -260,7 +314,7 @@ "keywords": [ "promise" ], - "time": "2016-03-08 01:15:46" + "time": "2016-05-18 16:56:05" }, { "name": "guzzlehttp/psr7", @@ -404,6 +458,113 @@ ], "time": "2014-11-20 16:49:30" }, + { + "name": "jacobkiers/oauth", + "version": "1.0.12", + "source": { + "type": "git", + "url": "https://github.com/jacobkiers/OAuth.git", + "reference": "95477a77107436e67a10e799fad04d82719a5f1e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jacobkiers/OAuth/zipball/95477a77107436e67a10e799fad04d82719a5f1e", + "reference": "95477a77107436e67a10e799fad04d82719a5f1e", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "mockery/mockery": "*", + "phpunit/phpunit": "3.7.*@stable", + "squizlabs/php_codesniffer": "*" + }, + "type": "library", + "autoload": { + "psr-0": { + "JacobKiers\\OAuth": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gary Jones", + "email": "gary@garyjones.co.uk", + "role": "developer" + }, + { + "name": "Alexandre Eher", + "role": "Composer packager" + }, + { + "name": "Jacob Kiers", + "email": "jacob@alphacomm.nl", + "role": "developer" + }, + { + "name": "Andy Smith", + "role": "original author" + } + ], + "description": "Based on Andy Smith's basic PHP library for OAuth 1.0a", + "homepage": "https://github.com/jacobkiers/OAuth", + "keywords": [ + "oauth" + ], + "time": "2015-10-02 13:50:51" + }, + { + "name": "kriswallsmith/buzz", + "version": "v0.15", + "source": { + "type": "git", + "url": "https://github.com/kriswallsmith/Buzz.git", + "reference": "d4041666c3ffb379af02a92dabe81c904b35fab8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kriswallsmith/Buzz/zipball/d4041666c3ffb379af02a92dabe81c904b35fab8", + "reference": "d4041666c3ffb379af02a92dabe81c904b35fab8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, + "suggest": { + "ext-curl": "*" + }, + "type": "library", + "autoload": { + "psr-0": { + "Buzz": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kris Wallsmith", + "email": "kris.wallsmith@gmail.com", + "homepage": "http://kriswallsmith.net/" + } + ], + "description": "Lightweight HTTP client", + "homepage": "https://github.com/kriswallsmith/Buzz", + "keywords": [ + "curl", + "http client" + ], + "time": "2015-06-25 17:26:56" + }, { "name": "maknz/slack", "version": "1.7.0", @@ -663,9 +824,7 @@ "authors": [ { "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" + "email": "fabien@symfony.com" } ], "description": "Pimple is a simple Dependency Injection Container for PHP 5.3", @@ -870,16 +1029,16 @@ }, { "name": "swiftmailer/swiftmailer", - "version": "v5.4.1", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421" + "reference": "d8db871a54619458a805229a057ea2af33c753e8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/0697e6aa65c83edf97bb0f23d8763f94e3f11421", - "reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/d8db871a54619458a805229a057ea2af33c753e8", + "reference": "d8db871a54619458a805229a057ea2af33c753e8", "shasum": "" }, "require": { @@ -919,20 +1078,20 @@ "mail", "mailer" ], - "time": "2015-06-06 14:19:39" + "time": "2016-05-01 08:45:47" }, { "name": "symfony/config", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "980ee40c28f00acff8906c11b778aab5f0db74c2" + "reference": "24f155da1ff180df8e15e34a8f6e2f8a0eadefa8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/980ee40c28f00acff8906c11b778aab5f0db74c2", - "reference": "980ee40c28f00acff8906c11b778aab5f0db74c2", + "url": "https://api.github.com/repos/symfony/config/zipball/24f155da1ff180df8e15e34a8f6e2f8a0eadefa8", + "reference": "24f155da1ff180df8e15e34a8f6e2f8a0eadefa8", "shasum": "" }, "require": { @@ -972,20 +1131,20 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2016-03-04 07:55:57" + "time": "2016-04-20 18:53:54" }, { "name": "symfony/console", - "version": "v2.8.4", + "version": "v2.8.6", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "9a5aef5fc0d4eff86853d44202b02be8d5a20154" + "reference": "48221d3de4dc22d2cd57c97e8b9361821da86609" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/9a5aef5fc0d4eff86853d44202b02be8d5a20154", - "reference": "9a5aef5fc0d4eff86853d44202b02be8d5a20154", + "url": "https://api.github.com/repos/symfony/console/zipball/48221d3de4dc22d2cd57c97e8b9361821da86609", + "reference": "48221d3de4dc22d2cd57c97e8b9361821da86609", "shasum": "" }, "require": { @@ -1032,20 +1191,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-03-17 09:19:04" + "time": "2016-04-26 12:00:47" }, { "name": "symfony/event-dispatcher", - "version": "v2.8.4", + "version": "v2.8.6", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "47d2d8cade9b1c3987573d2943bb9352536cdb87" + "reference": "a158f13992a3147d466af7a23b564ac719a4ddd8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/47d2d8cade9b1c3987573d2943bb9352536cdb87", - "reference": "47d2d8cade9b1c3987573d2943bb9352536cdb87", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/a158f13992a3147d466af7a23b564ac719a4ddd8", + "reference": "a158f13992a3147d466af7a23b564ac719a4ddd8", "shasum": "" }, "require": { @@ -1092,20 +1251,20 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-03-07 14:04:32" + "time": "2016-05-03 18:59:18" }, { "name": "symfony/filesystem", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "f82499a459dcade2ea56df94cc58b19c8bde3d20" + "reference": "74fec3511b62cb934b64bce1d96f06fffa4beafd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/f82499a459dcade2ea56df94cc58b19c8bde3d20", - "reference": "f82499a459dcade2ea56df94cc58b19c8bde3d20", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/74fec3511b62cb934b64bce1d96f06fffa4beafd", + "reference": "74fec3511b62cb934b64bce1d96f06fffa4beafd", "shasum": "" }, "require": { @@ -1141,20 +1300,20 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2016-03-27 10:24:39" + "time": "2016-04-12 18:09:53" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.1.1", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "1289d16209491b584839022f29257ad859b8532d" + "reference": "dff51f72b0706335131b00a7f49606168c582594" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/1289d16209491b584839022f29257ad859b8532d", - "reference": "1289d16209491b584839022f29257ad859b8532d", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/dff51f72b0706335131b00a7f49606168c582594", + "reference": "dff51f72b0706335131b00a7f49606168c582594", "shasum": "" }, "require": { @@ -1166,7 +1325,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "1.2-dev" } }, "autoload": { @@ -1200,20 +1359,20 @@ "portable", "shim" ], - "time": "2016-01-20 09:13:37" + "time": "2016-05-18 14:26:46" }, { "name": "symfony/yaml", - "version": "v2.8.4", + "version": "v2.8.6", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb" + "reference": "e4fbcc65f90909c999ac3b4dfa699ee6563a9940" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/584e52cb8f788a887553ba82db6caacb1d6260bb", - "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb", + "url": "https://api.github.com/repos/symfony/yaml/zipball/e4fbcc65f90909c999ac3b4dfa699ee6563a9940", + "reference": "e4fbcc65f90909c999ac3b4dfa699ee6563a9940", "shasum": "" }, "require": { @@ -1249,7 +1408,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-03-04 07:54:35" + "time": "2016-03-29 19:00:15" } ], "packages-dev": [ @@ -1828,21 +1987,24 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.7", + "version": "1.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "phpunit/phpunit": "~4|~5" + }, "type": "library", "autoload": { "classmap": [ @@ -1865,7 +2027,7 @@ "keywords": [ "timer" ], - "time": "2015-06-21 08:01:12" + "time": "2016-05-12 18:03:57" }, { "name": "phpunit/php-token-stream", @@ -1918,16 +2080,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.8.24", + "version": "4.8.26", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a1066c562c52900a142a0e2bbf0582994671385e" + "reference": "fc1d8cd5b5de11625979125c5639347896ac2c74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a1066c562c52900a142a0e2bbf0582994671385e", - "reference": "a1066c562c52900a142a0e2bbf0582994671385e", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fc1d8cd5b5de11625979125c5639347896ac2c74", + "reference": "fc1d8cd5b5de11625979125c5639347896ac2c74", "shasum": "" }, "require": { @@ -1941,7 +2103,7 @@ "phpunit/php-code-coverage": "~2.1", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": ">=1.0.6", + "phpunit/php-timer": "^1.0.6", "phpunit/phpunit-mock-objects": "~2.3", "sebastian/comparator": "~1.1", "sebastian/diff": "~1.2", @@ -1986,7 +2148,7 @@ "testing", "xunit" ], - "time": "2016-03-14 06:16:08" + "time": "2016-05-17 03:09:28" }, { "name": "phpunit/phpunit-mock-objects", @@ -2162,16 +2324,16 @@ }, { "name": "sebastian/environment", - "version": "1.3.5", + "version": "1.3.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf" + "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf", - "reference": "dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4e8f0da10ac5802913afc151413bc8c53b6c2716", + "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716", "shasum": "" }, "require": { @@ -2208,7 +2370,7 @@ "environment", "hhvm" ], - "time": "2016-02-26 18:40:46" + "time": "2016-05-17 03:18:57" }, { "name": "sebastian/exporter", @@ -2317,16 +2479,16 @@ }, { "name": "sebastian/git", - "version": "2.1.1", + "version": "2.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/git.git", - "reference": "38638de3e94830a5cd7a5956135589b967609cd5" + "reference": "607dcc6003502acdd0e6199b60ba954ce00f3004" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/git/zipball/38638de3e94830a5cd7a5956135589b967609cd5", - "reference": "38638de3e94830a5cd7a5956135589b967609cd5", + "url": "https://api.github.com/repos/sebastianbergmann/git/zipball/607dcc6003502acdd0e6199b60ba954ce00f3004", + "reference": "607dcc6003502acdd0e6199b60ba954ce00f3004", "shasum": "" }, "require": { @@ -2358,7 +2520,7 @@ "keywords": [ "git" ], - "time": "2016-02-21 15:02:23" + "time": "2016-03-12 23:31:06" }, { "name": "sebastian/global-state", @@ -2579,16 +2741,16 @@ }, { "name": "symfony/dependency-injection", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "6a9058101b591edced21ca3c83c80a3978f5c6b0" + "reference": "b2f4d40a6ed0f6ace59aa3c88d08a94eb9aef811" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/6a9058101b591edced21ca3c83c80a3978f5c6b0", - "reference": "6a9058101b591edced21ca3c83c80a3978f5c6b0", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/b2f4d40a6ed0f6ace59aa3c88d08a94eb9aef811", + "reference": "b2f4d40a6ed0f6ace59aa3c88d08a94eb9aef811", "shasum": "" }, "require": { @@ -2601,6 +2763,7 @@ }, "suggest": { "symfony/config": "", + "symfony/expression-language": "For using expressions in service container configuration", "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", "symfony/yaml": "" }, @@ -2634,11 +2797,11 @@ ], "description": "Symfony DependencyInjection Component", "homepage": "https://symfony.com", - "time": "2016-03-30 10:41:14" + "time": "2016-05-09 18:14:44" }, { "name": "symfony/finder", - "version": "v3.0.4", + "version": "v3.0.6", "source": { "type": "git", "url": "https://github.com/symfony/finder.git",