Skip to content

Commit

Permalink
beginning of continuouphp package Phing task
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Dewinne committed May 9, 2015
1 parent b21c5e6 commit 950aea6
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 32 deletions.
3 changes: 2 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

<target name="package" description="Ouput the package url">
<continuousphp-package
project="${project}"
provider="${provider}"
repository="${repository}"
reference="${reference}"
property="package.url" />
<echo message="---PACKAGE_URL:${package.url}---" />
Expand Down
26 changes: 20 additions & 6 deletions features/bootstrap/Continuous/Features/TaskContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ class TaskContext implements Context, SnippetAcceptingContext
/**
* @var string
*/
protected $project;
protected $provider;

/**
* @var string
*/
protected $repository;

/**
* @var string
Expand Down Expand Up @@ -55,11 +60,19 @@ public function setToken($token)
}

/**
* @Given the project :project
* @Given the provider :provider
*/
public function setProvider($provider)
{
$this->provider = $provider;
}

/**
* @Given the repository :repository
*/
public function setProject($project)
public function setRepository($repository)
{
$this->project = $project;
$this->repository = $repository;
}

/**
Expand All @@ -77,7 +90,8 @@ public function runPackageTask()
{
$command = self::PHING_BIN_PATH . ' config package'
. " -Dtoken=" . $this->token
. " -Dproject=" . $this->project
. " -Dprovider=" . $this->provider
. " -Drepository=" . $this->repository
. " -Dreference=" . $this->reference;

exec($command, $output, $return);
Expand All @@ -100,6 +114,6 @@ public function isValidDownloadUrl()
preg_match($regex, $this->lastOutput, $matches);
$url = $matches[1];

\PHPUnit_Framework_Assert::assertNotEquals('${package.url}', $url);
\PHPUnit_Framework_Assert::assertNotEquals('${package.url}', $url, $this->lastOutput);
}
}
5 changes: 3 additions & 2 deletions features/package.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Feature: continuousphp package

Scenario: Get the last build of master branch
Given I've the token "cc2efee7-be03-4611-923e-065bc3dd3326"
And the project "git-hub/continuousphp/phing-tasks"
And the reference "/head/master"
And the provider "git-hub"
And the repository "continuousphp/phing-tasks"
And the reference "/refs/heads/master"
When I use the continuousphp package task
Then I should retrieve a valid download url
11 changes: 9 additions & 2 deletions src/Continuous/Task/AbstractTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Frederic Dewinne <[email protected]>
* @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
*/
abstract class AbstractTask extends \Task
abstract class AbstractTask extends \ProjectComponent
{
/**
* @var string
Expand Down Expand Up @@ -55,7 +55,14 @@ protected function getClient()
{
if (is_null(self::$client)) {
$this->setClient(new Client(
array('base_url' => 'https://api.continuousphp.com/')
array(
'base_url' => 'https://api.continuousphp.com/',
'defaults' => array(
'headers' => array(
'Accept' => 'application/hal+json',
)
)
)
));
}

Expand Down
57 changes: 45 additions & 12 deletions src/Continuous/Task/PackageTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class PackageTask extends AbstractTask
/**
* @var string
*/
protected $project;
protected $provider;

/**
* @var string
*/
protected $repository;

/**
* @var string
Expand All @@ -48,16 +53,27 @@ public function setReference($reference)
}

/**
* @param string $project
* @param string $provider
* @return $this
*/
public function setProject($project)
public function setProvider($provider)
{
$this->project = $project;
$this->provider = $provider;

return $this;
}

/**
* @param string $repository
* @return $this
*/
public function setRepository($repository)
{
$this->repository = $repository;

return $this;
}

/**
* @param string $property
* @return $this
Expand All @@ -75,14 +91,31 @@ public function setProperty($property)
*/
public function main()
{
$build = $this->getClient()
->get('/api/projects/' . urlencode($this->getProject()) . '/builds?token=' . $this->getToken(),
array(
'headers' => array(
'Accept' => 'application/hal+json',
'Origin' => 'https://app.continuousphp.com'
)
));
$buildUrl = '/api/projects/' . urlencode($this->provider . '/' . $this->repository) . '/builds'
. '?token=' . $this->getToken()
. '&state[]=complete'
. '&result[]=success'
. '&result[]=warning';

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

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

$response = json_decode($response->getBody()->getContents(), true);

$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']);

$response = $this->getClient()
->get($build['_links']['self']['href'] . '/packages/deploy?token=' . $this->getToken());
$response = json_decode($response->getBody()->getContents(), true);
$this->getProject()->setProperty('package.url', $response['url']);
}
}
22 changes: 13 additions & 9 deletions tests/ContinuousTest/Task/PackageTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@
class PackageTaskTest extends \PHPUnit_Framework_TestCase
{

public function testProjectSetter()
public function testProviderSetter()
{
$project = 'toto';
$provider = 'toto';

$task = new PackageTask();
$this->assertSame($task, $task->setProject($project));
$this->assertAttributeSame($project, 'project', $task);
$this->assertSame($task, $task->setProvider($provider));
$this->assertAttributeSame($provider, 'provider', $task);
}

public function testRepositorySetter()
{
$repository = 'toto';

$task = new PackageTask();
$this->assertSame($task, $task->setRepository($repository));
$this->assertAttributeSame($repository, 'repository', $task);
}

public function testReferenceSetter()
Expand All @@ -49,9 +58,4 @@ public function testPropertySetter()
$this->assertSame($task, $task->setProperty($property));
$this->assertAttributeSame($property, 'property', $task);
}

public function mainTest()
{

}
}

0 comments on commit 950aea6

Please sign in to comment.