Skip to content

Commit f8a89ae

Browse files
authored
Merge pull request #5 from continuousphp/state-param
Added state param to get packages of one or more specific states only
2 parents 05c3882 + be48b9c commit f8a89ae

6 files changed

Lines changed: 118 additions & 12 deletions

File tree

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ The goal of this task is to setup your credential in order to start consuming
4242
This task helps you to get a package url for a repository.
4343

4444
#### 2.1. Attributes
45-
| Name | Type | Description | Default | Required |
46-
| ----------- | ------ | ------------------------------------------------------------------- | ------- | -------- |
47-
| provider | String | the repository provider platform (git-hub, bitbucket...) | n/a | Yes |
48-
| repository | String | the repository name | n/a | Yes |
49-
| reference | String | the GIT reference of the package | n/a | No |
50-
| destination | String | the GIT reference of the package | n/a | No |
51-
| property | String | the property in which the download URL or file path will be defined | n/a | No |
45+
| Name | Type | Description | Default | Required |
46+
| ----------- | ------ | ------------------------------------------------------------------- | -------- | -------- |
47+
| provider | String | the repository provider platform (git-hub, bitbucket...) | n/a | Yes |
48+
| repository | String | the repository name | n/a | Yes |
49+
| reference | String | the GIT reference of the package | n/a | No |
50+
| state | String | the allowed build states, can be "complete", "in-progress", or both | complete | No |
51+
| destination | String | the Download destination for the package | n/a | No |
52+
| property | String | the property in which the download URL or file path will be defined | n/a | No |
5253

5354
#### 2.2 Example
5455
```xml
@@ -65,6 +66,7 @@ Download the package by adding the destination
6566
provider="git-hub"
6667
repository="continuousphp/phing-tasks"
6768
reference="refs/heads/master"
69+
state="in-progress,complete"
6870
destination="/tmp"
6971
property="package.path" />
7072
```

build.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@
2424
<echo message="---PACKAGE_URL:${package.url}---" />
2525
</target>
2626

27+
<target name="package-with-state" description="Ouput the package url">
28+
<continuousphp-package
29+
provider="${provider}"
30+
repository="${repository}"
31+
reference="${reference}"
32+
state="${state}"
33+
property="package.url" />
34+
<echo message="---PACKAGE_URL:${package.url}---" />
35+
</target>
36+
2737
</project>

features/bootstrap/TaskContext.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class TaskContext implements Context, SnippetAcceptingContext
3535
*/
3636
protected $reference;
3737

38+
/**
39+
* @var string
40+
*/
41+
protected $state;
42+
3843
/**
3944
* @var string
4045
*/
@@ -83,6 +88,14 @@ public function setReference($reference)
8388
$this->reference = $reference;
8489
}
8590

91+
/**
92+
* @Given the state :state
93+
*/
94+
public function setState($state)
95+
{
96+
$this->state = $state;
97+
}
98+
8699
/**
87100
* @When I use the continuousphp package task
88101
*/
@@ -93,7 +106,28 @@ public function runPackageTask()
93106
. " -Dprovider=" . $this->provider
94107
. " -Drepository=" . $this->repository
95108
. " -Dreference=" . $this->reference;
109+
110+
exec($command, $output, $return);
111+
112+
if ($return) {
113+
throw new \RuntimeException(implode(PHP_EOL, $output), $return);
114+
}
96115

116+
$this->lastOutput = implode(PHP_EOL, $output);
117+
}
118+
119+
/**
120+
* @When I use the continuousphp package-with-state task
121+
*/
122+
public function runPackageWithStateTask()
123+
{
124+
$command = self::PHING_BIN_PATH . ' config package-with-state'
125+
. " -Dtoken=" . $this->token
126+
. " -Dprovider=" . $this->provider
127+
. " -Drepository=" . $this->repository
128+
. " -Dreference=" . $this->reference
129+
. " -Dstate=" . $this->state;
130+
97131
exec($command, $output, $return);
98132

99133
if ($return) {

features/package.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@ Feature: continuousphp package
99
And the repository "continuousphp/phing-tasks"
1010
And the reference "refs/heads/master"
1111
When I use the continuousphp package task
12+
Then I should retrieve a valid download url
13+
14+
Scenario: Get the last build of master branch, specifying the state manually
15+
Given I've the token "e391f57ddd27bb37097a5c46a47776289cf1eff7"
16+
And the provider "git-hub"
17+
And the repository "continuousphp/phing-tasks"
18+
And the reference "refs/heads/master"
19+
And the state "complete,in-progress"
20+
When I use the continuousphp package-with-state task
1221
Then I should retrieve a valid download url

src/PackageTask.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class PackageTask extends AbstractTask
2626
*/
2727
protected $reference;
2828

29+
/**
30+
* @var string
31+
*/
32+
protected $state;
33+
2934
/**
3035
* @var string
3136
*/
@@ -57,6 +62,25 @@ public function setReference($reference)
5762
return $this;
5863
}
5964

65+
/**
66+
* @param string $stateList
67+
* @return $this
68+
*/
69+
public function setState($stateList)
70+
{
71+
$this->state = [];
72+
73+
foreach(explode(',', $stateList) as $state) {
74+
$state = trim($state);
75+
76+
if ($state) {
77+
$this->state[] = $state;
78+
}
79+
}
80+
81+
return $this;
82+
}
83+
6084
/**
6185
* @param string $provider
6286
* @return $this
@@ -108,19 +132,19 @@ public function setDestination($destination)
108132
public function main()
109133
{
110134
$projectFilter = [
111-
'provider' => $this->provider,
135+
'provider' => $this->provider,
112136
'repository' => $this->repository,
113-
'state' => ['complete'],
114-
'result' => ['success', 'warning']
137+
'result' => ['success', 'warning']
115138
];
116139

140+
$projectFilter['state'] = $this->state ? : ['complete'];
141+
117142
if ($this->reference) {
118143
$projectFilter['ref'] = $this->reference;
119144
}
120145

121146
// Get the build list
122-
$builds = $this->getClient()
123-
->getBuilds($projectFilter);
147+
$builds = $this->getClient()->getBuilds($projectFilter);
124148

125149
if (empty($builds['_embedded']['builds'])) {
126150
$message = 'No build found for the project "' . $this->provider . '/' . $this->repository . '"';

tests/PackageTaskTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,31 @@ public function testPropertySetter()
5858
$this->assertSame($task, $task->setProperty($property));
5959
$this->assertAttributeSame($property, 'property', $task);
6060
}
61+
62+
public function testStateSetter()
63+
{
64+
$stateList = 'in-progress,complete';
65+
66+
$task = new PackageTask();
67+
$this->assertSame($task, $task->setState($stateList));
68+
$this->assertAttributeSame(['in-progress', 'complete'], 'state', $task);
69+
}
70+
71+
public function testStateSetter_WithWhiteSpaces()
72+
{
73+
$stateList = 'in-progress , complete';
74+
75+
$task = new PackageTask();
76+
$this->assertSame($task, $task->setState($stateList));
77+
$this->assertAttributeSame(['in-progress', 'complete'], 'state', $task);
78+
}
79+
80+
public function testStateSetter_WithEmptyValue()
81+
{
82+
$stateList = 'in-progress , ';
83+
84+
$task = new PackageTask();
85+
$this->assertSame($task, $task->setState($stateList));
86+
$this->assertAttributeSame(['in-progress'], 'state', $task);
87+
}
6188
}

0 commit comments

Comments
 (0)