Skip to content

Commit 7e80362

Browse files
marcopetersvimishor
authored andcommitted
Merged in marco_veenendaal/bitbucket-api/feature/add-pipeline-calls (pull request #37)
Feature/add pipeline calls
1 parent d2e6d89 commit 7e80362

File tree

5 files changed

+353
-0
lines changed

5 files changed

+353
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3434
### Fixed:
3535
- Client::setApiVersion should accept only argument of type string (issue #57)
3636

37+
3738
## 0.8.2 / 2017-01-10
3839

3940
### Fixed:
@@ -44,6 +45,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4445
### Fixed:
4546
- Declining a PR without a `message` parameter caused a 500 response. (issue #43)
4647

48+
4749
## 0.8.0 / 2015-12-05
4850

4951
### Added:
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitbucket-api package.
5+
*
6+
* (c) Alexandru G. <alex@gentle.ro>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Bitbucket\API\Repositories;
13+
14+
use Bitbucket\API\Api;
15+
use Buzz\Message\MessageInterface;
16+
17+
/**
18+
* Manage the pipelines of a repository
19+
*
20+
* @author Marco Veenendaal <marco@deinternetjongens.nl>
21+
*/
22+
class Pipelines extends Api
23+
{
24+
/**
25+
* Get the information associated with a repository's pipelines
26+
*
27+
* @access public
28+
* @param string $account The team or individual account owning the repository.
29+
* @param string $repo The repository identifier.
30+
* @return MessageInterface
31+
*/
32+
public function all($account, $repo)
33+
{
34+
return $this->getClient()->setApiVersion('2.0')->get(
35+
sprintf('repositories/%s/%s/pipelines/', $account, $repo)
36+
);
37+
}
38+
39+
/**
40+
* Creates a pipeline for the specified repository.
41+
*
42+
* @access public
43+
* @param string $account The team or individual account owning the repository.
44+
* @param string $repo The repository identifier.
45+
* @param array|string $params Additional parameters as array or JSON string
46+
* @return MessageInterface
47+
*/
48+
public function create($account, $repo, $params = array())
49+
{
50+
// allow developer to directly specify params as json if (s)he wants.
51+
if ('array' !== gettype($params)) {
52+
if (empty($params)) {
53+
throw new \InvalidArgumentException('Invalid JSON provided.');
54+
}
55+
56+
$params = $this->decodeJSON($params);
57+
}
58+
59+
return $this->getClient()->setApiVersion('2.0')->post(
60+
sprintf('repositories/%s/%s/pipelines/', $account, $repo),
61+
json_encode($params),
62+
array('Content-Type' => 'application/json')
63+
);
64+
}
65+
66+
/**
67+
* Get a specific pipeline
68+
*
69+
* @access public
70+
* @param string $account The team or individual account owning the repository.
71+
* @param string $repo The repository identifier.
72+
* @param string $uuid The pipeline's identifier.
73+
* @return MessageInterface
74+
*/
75+
public function get($account, $repo, $uuid)
76+
{
77+
return $this->getClient()->setApiVersion('2.0')->get(
78+
sprintf('repositories/%s/%s/pipelines/%s', $account, $repo, $uuid)
79+
);
80+
}
81+
82+
/**
83+
* Stop a specific pipeline
84+
*
85+
* @access public
86+
* @param string $account The team or individual account owning the repository.
87+
* @param string $repo The repository identifier.
88+
* @param string $uuid The pipeline's identifier.
89+
* @return MessageInterface
90+
*/
91+
public function stopPipeline($account, $repo, $uuid)
92+
{
93+
return $this->getClient()->setApiVersion('2.0')->post(
94+
sprintf('repositories/%s/%s/pipelines/%s/stopPipeline', $account, $repo, $uuid)
95+
);
96+
}
97+
98+
/**
99+
* Get steps
100+
*
101+
* @access public
102+
* @return Pipelines\Steps
103+
*
104+
* @throws \InvalidArgumentException
105+
* @codeCoverageIgnore
106+
*/
107+
public function steps()
108+
{
109+
return $this->api('Repositories\\Pipelines\\Steps');
110+
}
111+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitbucket-api package.
5+
*
6+
* (c) Alexandru G. <alex@gentle.ro>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Bitbucket\API\Repositories\Pipelines;
13+
14+
use Bitbucket\API;
15+
use Buzz\Message\MessageInterface;
16+
17+
/**
18+
* Manage the steps of a pipeline.
19+
*
20+
* @author Marco Veenendaal <marco@deinternetjongens.nl>
21+
*/
22+
class Steps extends API\Api
23+
{
24+
/**
25+
* Get a list of all pipeline steps
26+
*
27+
* @access public
28+
* @param string $account The team or individual account owning the repository.
29+
* @param string $repo The repository identifier.
30+
* @param string $pipelineUuid UUID of the pipeline.
31+
* @return MessageInterface
32+
*/
33+
public function all($account, $repo, $pipelineUuid)
34+
{
35+
return $this->getClient()->setApiVersion('2.0')->get(
36+
sprintf('repositories/%s/%s/pipelines/%s/steps/', $account, $repo, $pipelineUuid)
37+
);
38+
}
39+
40+
/**
41+
* Get an individual pipeline step
42+
*
43+
* @access public
44+
* @param string $account The team or individual account owning the repository.
45+
* @param string $repo The repository identifier.
46+
* @param string $pipelineUuid UUID of the pipeline.
47+
* @param string $stepUuid UUID of the step.
48+
* @return MessageInterface
49+
*/
50+
public function get($account, $repo, $pipelineUuid, $stepUuid)
51+
{
52+
return $this->getClient()->setApiVersion('2.0')->get(
53+
sprintf('repositories/%s/%s/pipelines/%s/steps/%s', $account, $repo, $pipelineUuid, $stepUuid)
54+
);
55+
}
56+
57+
/**
58+
* Get the log of an individual pipeline step
59+
*
60+
* @access public
61+
* @param string $account The team or individual account owning the repository.
62+
* @param string $repo The repository identifier.
63+
* @param string $pipelineUuid UUID of the pipeline.
64+
* @param string $stepUuid UUID of the step.
65+
* @return MessageInterface
66+
*/
67+
public function log($account, $repo, $pipelineUuid, $stepUuid)
68+
{
69+
return $this->getClient()->setApiVersion('2.0')->get(
70+
sprintf('repositories/%s/%s/pipelines/%s/steps/%s/log', $account, $repo, $pipelineUuid, $stepUuid)
71+
);
72+
}
73+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Bitbucket\Tests\API\Repositories\Pipelines;
4+
5+
use Bitbucket\Tests\API as Tests;
6+
use Bitbucket\API;
7+
8+
class StepsTest extends Tests\TestCase
9+
{
10+
public function testGetAllSteps()
11+
{
12+
$endpoint = 'repositories/gentle/eof/pipelines/pipeline-uuid/steps/';
13+
$expectedResult = $this->fakeResponse(array('dummy'));
14+
15+
$client = $this->getHttpClientMock();
16+
$client->expects($this->once())
17+
->method('get')
18+
->with($endpoint)
19+
->will($this->returnValue($expectedResult));
20+
21+
/** @var \Bitbucket\API\Repositories\Pipelines\Steps $steps */
22+
$steps = $this->getClassMock('Bitbucket\API\Repositories\Pipelines\Steps', $client);
23+
$actual = $steps->all('gentle', 'eof', 'pipeline-uuid');
24+
25+
$this->assertEquals($expectedResult, $actual);
26+
}
27+
28+
public function testGetSpecificPipelineStep()
29+
{
30+
$endpoint = 'repositories/gentle/eof/pipelines/pipeline-uuid/steps/step-uuid';
31+
$expectedResult = $this->fakeResponse(array('dummy'));
32+
33+
$client = $this->getHttpClientMock();
34+
$client->expects($this->once())
35+
->method('get')
36+
->with($endpoint)
37+
->will($this->returnValue($expectedResult));
38+
39+
/** @var \Bitbucket\API\Repositories\Pipelines\Steps $steps */
40+
$steps = $this->getClassMock('Bitbucket\API\Repositories\Pipelines\Steps', $client);
41+
$actual = $steps->get('gentle', 'eof', 'pipeline-uuid', 'step-uuid');
42+
43+
$this->assertEquals($expectedResult, $actual);
44+
}
45+
46+
public function testGetLogOfSpecificPipelineStep()
47+
{
48+
$endpoint = 'repositories/gentle/eof/pipelines/pipeline-uuid/steps/step-uuid/log';
49+
$expectedResult = $this->fakeResponse(array('dummy'));
50+
51+
$client = $this->getHttpClientMock();
52+
$client->expects($this->once())
53+
->method('get')
54+
->with($endpoint)
55+
->will($this->returnValue($expectedResult));
56+
57+
/** @var \Bitbucket\API\Repositories\Pipelines\Steps $steps */
58+
$steps = $this->getClassMock('Bitbucket\API\Repositories\Pipelines\Steps', $client);
59+
$actual = $steps->log('gentle', 'eof', 'pipeline-uuid', 'step-uuid');
60+
61+
$this->assertEquals($expectedResult, $actual);
62+
}
63+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace Bitbucket\Tests\API\Repositories;
4+
5+
use Bitbucket\Tests\API as Tests;
6+
7+
class PipelinesTest extends Tests\TestCase
8+
{
9+
public function testGetAllPipelines()
10+
{
11+
$endpoint = 'repositories/gentle/eof/pipelines/';
12+
$expectedResult = $this->fakeResponse(array('dummy'));
13+
14+
$client = $this->getHttpClientMock();
15+
$client->expects($this->any())
16+
->method('get')
17+
->with($endpoint)
18+
->will($this->returnValue($expectedResult));
19+
20+
/** @var \Bitbucket\API\Repositories\Pipelines $pipelines */
21+
$pipelines = $this->getClassMock('Bitbucket\API\Repositories\Pipelines', $client);
22+
$actual = $pipelines->all('gentle', 'eof');
23+
24+
$this->assertEquals($expectedResult, $actual);
25+
}
26+
27+
public function testCreatePipelinesFromArray()
28+
{
29+
$endpoint = 'repositories/gentle/eof/pipelines/';
30+
$params = array(
31+
'type' => array(
32+
'ref_type' => 'branch',
33+
'type' => 'pipeline_ref_target',
34+
'ref_name' => 'master'
35+
)
36+
);
37+
38+
$client = $this->getHttpClientMock();
39+
$client->expects($this->once())
40+
->method('post')
41+
->with($endpoint, json_encode($params));
42+
43+
/** @var \Bitbucket\API\Repositories\Pipelines $pipelines */
44+
$pipelines = $this->getClassMock('Bitbucket\API\Repositories\Pipelines', $client);
45+
46+
$pipelines->create('gentle', 'eof', $params);
47+
}
48+
49+
public function testCreatePipelinesFromJson()
50+
{
51+
$endpoint = 'repositories/gentle/eof/pipelines/';
52+
$params = json_encode(array(
53+
'type' => array(
54+
'ref_type' => 'branch',
55+
'type' => 'pipeline_ref_target',
56+
'ref_name' => 'master'
57+
)
58+
));
59+
60+
$client = $this->getHttpClientMock();
61+
$client->expects($this->once())
62+
->method('post')
63+
->with($endpoint, $params);
64+
65+
/** @var \Bitbucket\API\Repositories\Pipelines $pipelines */
66+
$pipelines = $this->getClassMock('Bitbucket\API\Repositories\Pipelines', $client);
67+
68+
$pipelines->create('gentle', 'eof', $params);
69+
}
70+
71+
public function testGetSpecificPipeline()
72+
{
73+
$endpoint = 'repositories/gentle/eof/pipelines/uuid';
74+
$expectedResult = $this->fakeResponse(array('dummy'));
75+
76+
$client = $this->getHttpClientMock();
77+
$client->expects($this->once())
78+
->method('get')
79+
->with($endpoint)
80+
->will($this->returnValue($expectedResult));
81+
82+
/** @var \Bitbucket\API\Repositories\Pipelines $pipelines */
83+
$pipelines = $this->getClassMock('Bitbucket\API\Repositories\Pipelines', $client);
84+
85+
$actual = $pipelines->get('gentle', 'eof', 'uuid');
86+
87+
$this->assertEquals($expectedResult, $actual);
88+
}
89+
90+
public function testStopSpecificPipeline()
91+
{
92+
$endpoint = 'repositories/gentle/eof/pipelines/uuid/stopPipeline';
93+
94+
$client = $this->getHttpClientMock();
95+
$client->expects($this->once())
96+
->method('post')
97+
->with($endpoint);
98+
99+
/** @var \Bitbucket\API\Repositories\Pipelines $pipelines */
100+
$pipelines = $this->getClassMock('Bitbucket\API\Repositories\Pipelines', $client);
101+
102+
$pipelines->stopPipeline('gentle', 'eof', 'uuid');
103+
}
104+
}

0 commit comments

Comments
 (0)