1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the bitbucket-api package. |
5
|
|
|
* |
6
|
|
|
* (c) Alexandru G. <[email protected]> |
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 Bitbucket\API\Repositories\Pipelines\Steps; |
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Manage the pipelines of a repository |
20
|
|
|
* |
21
|
|
|
* @author Marco Veenendaal <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class Pipelines extends Api |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Get the information associated with a repository's pipelines |
27
|
|
|
* |
28
|
|
|
* @access public |
29
|
|
|
* @param string $account The team or individual account owning the repository. |
30
|
|
|
* @param string $repo The repository identifier. |
31
|
|
|
* @return ResponseInterface |
32
|
1 |
|
*/ |
33
|
|
|
public function all($account, $repo) |
34
|
1 |
|
{ |
35
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->get( |
36
|
|
|
sprintf('/repositories/%s/%s/pipelines/', $account, $repo) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Creates a pipeline for the specified repository. |
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 array|string $params Additional parameters as array or JSON string |
47
|
|
|
* @return ResponseInterface |
48
|
2 |
|
*/ |
49
|
|
|
public function create($account, $repo, $params = array()) |
50
|
|
|
{ |
51
|
2 |
|
// allow developer to directly specify params as json if (s)he wants. |
52
|
1 |
|
if ('array' !== gettype($params)) { |
53
|
|
|
if (empty($params)) { |
54
|
|
|
throw new \InvalidArgumentException('Invalid JSON provided.'); |
55
|
|
|
} |
56
|
1 |
|
|
57
|
|
|
$params = $this->decodeJSON($params); |
58
|
|
|
} |
59
|
2 |
|
|
60
|
2 |
|
return $this->getClient()->setApiVersion('2.0')->post( |
61
|
2 |
|
sprintf('/repositories/%s/%s/pipelines/', $account, $repo), |
62
|
2 |
|
json_encode($params), |
63
|
|
|
array('Content-Type' => 'application/json') |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get a specific pipeline |
69
|
|
|
* |
70
|
|
|
* @access public |
71
|
|
|
* @param string $account The team or individual account owning the repository. |
72
|
|
|
* @param string $repo The repository identifier. |
73
|
|
|
* @param string $uuid The pipeline's identifier. |
74
|
|
|
* @return ResponseInterface |
75
|
1 |
|
*/ |
76
|
|
|
public function get($account, $repo, $uuid) |
77
|
1 |
|
{ |
78
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->get( |
79
|
|
|
sprintf('/repositories/%s/%s/pipelines/%s', $account, $repo, $uuid) |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Stop a specific pipeline |
85
|
|
|
* |
86
|
|
|
* @access public |
87
|
|
|
* @param string $account The team or individual account owning the repository. |
88
|
|
|
* @param string $repo The repository identifier. |
89
|
|
|
* @param string $uuid The pipeline's identifier. |
90
|
|
|
* @return ResponseInterface |
91
|
1 |
|
*/ |
92
|
|
|
public function stopPipeline($account, $repo, $uuid) |
93
|
1 |
|
{ |
94
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->post( |
95
|
|
|
sprintf('/repositories/%s/%s/pipelines/%s/stopPipeline', $account, $repo, $uuid) |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get steps |
101
|
|
|
* |
102
|
|
|
* @access public |
103
|
|
|
* @return Pipelines\Steps |
104
|
|
|
* |
105
|
|
|
* @throws \InvalidArgumentException |
106
|
|
|
* @codeCoverageIgnore |
107
|
|
|
*/ |
108
|
|
|
public function steps() |
109
|
|
|
{ |
110
|
|
|
return $this->api(Steps::class); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|