Skip to content

Commit 950aea6

Browse files
author
Frederic Dewinne
committed
beginning of continuouphp package Phing task
1 parent b21c5e6 commit 950aea6

File tree

6 files changed

+92
-32
lines changed

6 files changed

+92
-32
lines changed

build.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
<target name="package" description="Ouput the package url">
1919
<continuousphp-package
20-
project="${project}"
20+
provider="${provider}"
21+
repository="${repository}"
2122
reference="${reference}"
2223
property="package.url" />
2324
<echo message="---PACKAGE_URL:${package.url}---" />

features/bootstrap/Continuous/Features/TaskContext.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ class TaskContext implements Context, SnippetAcceptingContext
2323
/**
2424
* @var string
2525
*/
26-
protected $project;
26+
protected $provider;
27+
28+
/**
29+
* @var string
30+
*/
31+
protected $repository;
2732

2833
/**
2934
* @var string
@@ -55,11 +60,19 @@ public function setToken($token)
5560
}
5661

5762
/**
58-
* @Given the project :project
63+
* @Given the provider :provider
64+
*/
65+
public function setProvider($provider)
66+
{
67+
$this->provider = $provider;
68+
}
69+
70+
/**
71+
* @Given the repository :repository
5972
*/
60-
public function setProject($project)
73+
public function setRepository($repository)
6174
{
62-
$this->project = $project;
75+
$this->repository = $repository;
6376
}
6477

6578
/**
@@ -77,7 +90,8 @@ public function runPackageTask()
7790
{
7891
$command = self::PHING_BIN_PATH . ' config package'
7992
. " -Dtoken=" . $this->token
80-
. " -Dproject=" . $this->project
93+
. " -Dprovider=" . $this->provider
94+
. " -Drepository=" . $this->repository
8195
. " -Dreference=" . $this->reference;
8296

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

103-
\PHPUnit_Framework_Assert::assertNotEquals('${package.url}', $url);
117+
\PHPUnit_Framework_Assert::assertNotEquals('${package.url}', $url, $this->lastOutput);
104118
}
105119
}

features/package.feature

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Feature: continuousphp package
55

66
Scenario: Get the last build of master branch
77
Given I've the token "cc2efee7-be03-4611-923e-065bc3dd3326"
8-
And the project "git-hub/continuousphp/phing-tasks"
9-
And the reference "/head/master"
8+
And the provider "git-hub"
9+
And the repository "continuousphp/phing-tasks"
10+
And the reference "/refs/heads/master"
1011
When I use the continuousphp package task
1112
Then I should retrieve a valid download url

src/Continuous/Task/AbstractTask.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @author Frederic Dewinne <frederic@continuousphp.com>
2121
* @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
2222
*/
23-
abstract class AbstractTask extends \Task
23+
abstract class AbstractTask extends \ProjectComponent
2424
{
2525
/**
2626
* @var string
@@ -55,7 +55,14 @@ protected function getClient()
5555
{
5656
if (is_null(self::$client)) {
5757
$this->setClient(new Client(
58-
array('base_url' => 'https://api.continuousphp.com/')
58+
array(
59+
'base_url' => 'https://api.continuousphp.com/',
60+
'defaults' => array(
61+
'headers' => array(
62+
'Accept' => 'application/hal+json',
63+
)
64+
)
65+
)
5966
));
6067
}
6168

src/Continuous/Task/PackageTask.php

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ class PackageTask extends AbstractTask
2929
/**
3030
* @var string
3131
*/
32-
protected $project;
32+
protected $provider;
33+
34+
/**
35+
* @var string
36+
*/
37+
protected $repository;
3338

3439
/**
3540
* @var string
@@ -48,16 +53,27 @@ public function setReference($reference)
4853
}
4954

5055
/**
51-
* @param string $project
56+
* @param string $provider
5257
* @return $this
5358
*/
54-
public function setProject($project)
59+
public function setProvider($provider)
5560
{
56-
$this->project = $project;
61+
$this->provider = $provider;
5762

5863
return $this;
5964
}
6065

66+
/**
67+
* @param string $repository
68+
* @return $this
69+
*/
70+
public function setRepository($repository)
71+
{
72+
$this->repository = $repository;
73+
74+
return $this;
75+
}
76+
6177
/**
6278
* @param string $property
6379
* @return $this
@@ -75,14 +91,31 @@ public function setProperty($property)
7591
*/
7692
public function main()
7793
{
78-
$build = $this->getClient()
79-
->get('/api/projects/' . urlencode($this->getProject()) . '/builds?token=' . $this->getToken(),
80-
array(
81-
'headers' => array(
82-
'Accept' => 'application/hal+json',
83-
'Origin' => 'https://app.continuousphp.com'
84-
)
85-
));
94+
$buildUrl = '/api/projects/' . urlencode($this->provider . '/' . $this->repository) . '/builds'
95+
. '?token=' . $this->getToken()
96+
. '&state[]=complete'
97+
. '&result[]=success'
98+
. '&result[]=warning';
99+
100+
if ($this->reference) {
101+
$buildUrl.= '&ref=' . urlencode($this->reference);
102+
}
86103

104+
$response = $this->getClient()
105+
->get($buildUrl);
106+
107+
$response = json_decode($response->getBody()->getContents(), true);
108+
109+
$build = $response['_embedded']['builds'][0];
110+
111+
$message = "found build $build[buildId] for reference $build[ref] created on $build[created]"
112+
. " and finished with $build[result] result";
113+
$this->log($message);
114+
$this->log($build['_links']['self']['href']);
115+
116+
$response = $this->getClient()
117+
->get($build['_links']['self']['href'] . '/packages/deploy?token=' . $this->getToken());
118+
$response = json_decode($response->getBody()->getContents(), true);
119+
$this->getProject()->setProperty('package.url', $response['url']);
87120
}
88121
}

tests/ContinuousTest/Task/PackageTaskTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,22 @@
2323
class PackageTaskTest extends \PHPUnit_Framework_TestCase
2424
{
2525

26-
public function testProjectSetter()
26+
public function testProviderSetter()
2727
{
28-
$project = 'toto';
28+
$provider = 'toto';
2929

3030
$task = new PackageTask();
31-
$this->assertSame($task, $task->setProject($project));
32-
$this->assertAttributeSame($project, 'project', $task);
31+
$this->assertSame($task, $task->setProvider($provider));
32+
$this->assertAttributeSame($provider, 'provider', $task);
33+
}
34+
35+
public function testRepositorySetter()
36+
{
37+
$repository = 'toto';
38+
39+
$task = new PackageTask();
40+
$this->assertSame($task, $task->setRepository($repository));
41+
$this->assertAttributeSame($repository, 'repository', $task);
3342
}
3443

3544
public function testReferenceSetter()
@@ -49,9 +58,4 @@ public function testPropertySetter()
4958
$this->assertSame($task, $task->setProperty($property));
5059
$this->assertAttributeSame($property, 'property', $task);
5160
}
52-
53-
public function mainTest()
54-
{
55-
56-
}
5761
}

0 commit comments

Comments
 (0)