Skip to content

Commit

Permalink
uses continuousphp sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Dewinne committed May 10, 2015
1 parent e73c039 commit 0e20af7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 53 deletions.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
"require": {
"php": ">=5.4.0",
"phing/phing": "~2.9",
"guzzlehttp/guzzle": "~5.0"
"continuousphp/sdk": "~0.1"
},
"autoload": {
"psr-4": {
"Continuous\\Task\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Continuous\\Tests\\Task\\": "tests/",
"Continuous\\Features\\": "features/bootstrap/"
}
}
}
File renamed without changes.
5 changes: 3 additions & 2 deletions tests/phpunit.xml → phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<phpunit backupGlobals="false"
bootstrap="./vendor/autoload.php"
cacheTokens="true"
colors="true">
<testsuites>
<testsuite name="Phing Tasks test suite">
<directory>ContinuousTest</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../src</directory>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
28 changes: 1 addition & 27 deletions src/AbstractTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Continuous\Task;

use GuzzleHttp\Client;
use Continuous\Sdk\Client;

/**
* AbstractTask
Expand All @@ -22,24 +22,11 @@
*/
abstract class AbstractTask extends \ProjectComponent
{
/**
* @var string
*/
static protected $token;

/**
* @var Client
*/
static protected $client;

/**
* @return string
*/
protected function getToken()
{
return self::$token;
}

/**
* @param Client $client
*/
Expand All @@ -53,19 +40,6 @@ public function setClient(Client $client)
*/
protected function getClient()
{
if (is_null(self::$client)) {
$this->setClient(new Client(
array(
'base_url' => 'https://api.continuousphp.com/',
'defaults' => array(
'headers' => array(
'Accept' => 'application/hal+json',
)
)
)
));
}

return self::$client;
}
}
16 changes: 14 additions & 2 deletions src/ConfigTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Continuous\Task;

use Continuous\Sdk\Service;

/**
* ConfigTask
*
Expand All @@ -20,22 +22,32 @@
*/
class ConfigTask extends AbstractTask
{
/**
* @var string
*/
protected $token;

/**
* @param string $token
* @return $this
*/
public function setToken($token)
{
self::$token = $token;
$this->token = $token;

return $this;
}

/**
* Task entry point
*/
public function main()
{
$config = [];
if ($this->token) {
$config['token'] = $this->token;
}

$this->setClient(Service::factory($config));
}
}
45 changes: 25 additions & 20 deletions src/PackageTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,36 @@ public function setProperty($property)
*/
public function main()
{
$buildUrl = '/api/projects/' . urlencode($this->provider . '/' . $this->repository) . '/builds'
. '?token=' . $this->getToken()
. '&state[]=complete'
. '&result[]=success'
. '&result[]=warning';
$projectId = $this->provider . '/' . $this->repository;
$projectFilter = [
'projectId' => $projectId,
'state' => ['complete'],
'result' => ['success', 'warning']
];

if ($this->reference) {
$buildUrl.= '&ref=' . urlencode($this->reference);
$projectFilter['ref'] = $this->reference;
}

// Get the build list
$builds = $this->getClient()
->getBuilds($projectFilter);

$response = $this->getClient()
->get($buildUrl)
->json();

$build = $response['_embedded']['builds'][0];

$message = "found build $build[buildId] for reference $build[ref] created on $build[created]"
. " and finished with $build[result] result";
$this->log($message);
$this->log($build['_links']['self']['href']);
if (empty($builds['_embedded']['builds'])) {
$message = 'No build found for the project "' . $projectId . '"';
if ($this->reference) {
$message.= ' on the reference "' . $this->reference . '"';
}
throw new \BuildException($message);
}

$response = $this->getClient()
->get($build['_links']['self']['href'] . '/packages/deploy?token=' . $this->getToken())
->json();
// Get the package download url of the last build
$package = $this->getClient()->getPackage([
'projectId' => $projectId,
'buildId' => $builds['_embedded']['builds'][0]['buildId'],
'packageType' => 'deploy'
]);

$this->getProject()->setProperty('package.url', $response['url']);
$this->getProject()->setProperty('package.url', $package['url']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function testTokenSetter()

$task = new ConfigTask();
$this->assertSame($task, $task->setToken($token));
$this->assertAttributeSame($token, 'token', 'Continuous\Task\AbstractTask');
$this->assertAttributeSame($token, 'token', $task);
}
}
File renamed without changes.

0 comments on commit 0e20af7

Please sign in to comment.