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; |
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Allows you to create a new repository or edit a specific one. |
19
|
|
|
* |
20
|
|
|
* @author Alexandru G. <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Repository extends API\Api |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Get information associated with an individual repository. |
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 ResponseInterface |
31
|
|
|
*/ |
32
|
1 |
|
public function get($account, $repo) |
33
|
|
|
{ |
34
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->get( |
35
|
1 |
|
sprintf('/repositories/%s/%s', $account, $repo) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Create a new repository |
41
|
|
|
* |
42
|
|
|
* If `$params` are omitted, a private git repository will be created, |
43
|
|
|
* with a "no forking" policy. |
44
|
|
|
* |
45
|
|
|
* @access public |
46
|
|
|
* @param string $account The team or individual account owning the repository. |
47
|
|
|
* @param string $repo The repository identifier. |
48
|
|
|
* @param array|string $params Additional parameters as array or JSON string |
49
|
|
|
* @return ResponseInterface |
50
|
|
|
* |
51
|
|
|
* @throws \InvalidArgumentException If invalid JSON is provided. |
52
|
|
|
* |
53
|
|
|
* @see https://confluence.atlassian.com/x/WwZAGQ |
54
|
|
|
*/ |
55
|
13 |
|
public function create($account, $repo, $params = array()) |
56
|
|
|
{ |
57
|
|
|
$defaults = array( |
58
|
|
|
'scm' => 'git', |
59
|
13 |
|
'name' => $repo, |
60
|
1 |
|
'is_private' => true, |
61
|
|
|
'description' => 'My secret repo', |
62
|
|
|
'fork_policy' => 'no_forks', |
63
|
|
|
); |
64
|
12 |
|
|
65
|
12 |
|
// allow developer to directly specify params as json if (s)he wants. |
66
|
|
|
if ('array' !== gettype($params)) { |
67
|
12 |
|
if (empty($params)) { |
68
|
12 |
|
throw new \InvalidArgumentException('Invalid JSON provided.'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$params = $this->decodeJSON($params); |
72
|
12 |
|
} |
73
|
10 |
|
|
74
|
1 |
|
$params = json_encode(array_merge($defaults, $params)); |
75
|
|
|
|
76
|
|
|
return $this->getClient()->setApiVersion('2.0')->post( |
77
|
9 |
|
sprintf('/repositories/%s/%s', $account, $repo), |
78
|
|
|
$params, |
79
|
|
|
array('Content-Type' => 'application/json') |
80
|
3 |
|
); |
81
|
|
|
} |
82
|
3 |
|
|
83
|
3 |
|
/** |
84
|
3 |
|
* Update a repository |
85
|
3 |
|
* |
86
|
|
|
* @access public |
87
|
|
|
* @param string $account The team or individual account owning the repository. |
88
|
|
|
* @param string $repo The repository identifier. |
89
|
|
|
* @param array $params Additional parameters |
90
|
|
|
* @return ResponseInterface |
91
|
|
|
* |
92
|
|
|
* @see https://confluence.atlassian.com/x/WwZAGQ |
93
|
|
|
*/ |
94
|
|
|
public function update($account, $repo, array $params = array()) |
95
|
|
|
{ |
96
|
|
|
return $this->getClient()->setApiVersion('2.0')->put( |
97
|
|
|
sprintf('/repositories/%s/%s', $account, $repo), |
98
|
|
|
$params |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Delete a repository |
104
|
|
|
* |
105
|
|
|
* @access public |
106
|
|
|
* @param string $account The team or individual account owning the repository. |
107
|
|
|
* @param string $repo The repository identifier. |
108
|
|
|
* @return ResponseInterface |
109
|
|
|
*/ |
110
|
|
|
public function delete($account, $repo) |
111
|
|
|
{ |
112
|
|
|
return $this->getClient()->setApiVersion('2.0')->delete( |
113
|
|
|
sprintf('/repositories/%s/%s', $account, $repo) |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Gets the list of accounts watching a repository. |
119
|
|
|
* |
120
|
|
|
* @access public |
121
|
|
|
* @param string $account The team or individual account owning the repository. |
122
|
|
|
* @param string $repo The repository identifier. |
123
|
|
|
* @return ResponseInterface |
124
|
|
|
*/ |
125
|
|
|
public function watchers($account, $repo) |
126
|
|
|
{ |
127
|
|
|
return $this->getClient()->setApiVersion('2.0')->get( |
128
|
|
|
sprintf('/repositories/%s/%s/watchers', $account, $repo) |
129
|
|
|
); |
130
|
1 |
|
} |
131
|
|
|
|
132
|
1 |
|
/** |
133
|
1 |
|
* Gets the list of repository forks. |
134
|
1 |
|
* |
135
|
|
|
* @access public |
136
|
|
|
* @param string $account The team or individual account owning the repository. |
137
|
|
|
* @param string $repo The repository identifier. |
138
|
|
|
* @return ResponseInterface |
139
|
|
|
*/ |
140
|
|
|
public function forks($account, $repo) |
141
|
|
|
{ |
142
|
|
|
return $this->getClient()->setApiVersion('2.0')->get( |
143
|
|
|
sprintf('/repositories/%s/%s/forks', $account, $repo) |
144
|
|
|
); |
145
|
|
|
} |
146
|
1 |
|
|
147
|
|
|
/** |
148
|
1 |
|
* Fork a repository |
149
|
1 |
|
* |
150
|
|
|
* @access public |
151
|
|
|
* @param string $account The team or individual account owning the repository. |
152
|
|
|
* @param string $repo The repository identifier. |
153
|
|
|
* @param string $name Fork name |
154
|
|
|
* @param array $params Additional parameters |
155
|
|
|
* @return ResponseInterface |
156
|
|
|
* |
157
|
|
|
* @see https://confluence.atlassian.com/display/BITBUCKET/repository+Resource#repositoryResource-POSTanewfork |
158
|
|
|
*/ |
159
|
|
|
public function fork($account, $repo, $name, array $params = array()) |
160
|
|
|
{ |
161
|
1 |
|
$params['name'] = $name; |
162
|
|
|
|
163
|
1 |
|
$params = json_encode($params); |
164
|
1 |
|
|
165
|
|
|
return $this->getClient()->setApiVersion('2.0')->post( |
166
|
|
|
sprintf('/repositories/%s/%s/forks', $account, $repo), |
167
|
|
|
$params, |
168
|
|
|
array('Content-Type' => 'application/json') |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Get a list of branches associated with a repository. |
174
|
|
|
* |
175
|
|
|
* @access public |
176
|
1 |
|
* @param string $account The team or individual account owning the repository. |
177
|
|
|
* @param string $repo The repository identifier. |
178
|
1 |
|
* @param string $name The name of the branch |
179
|
1 |
|
* @return ResponseInterface |
180
|
|
|
*/ |
181
|
|
|
public function branches($account, $repo, $name = '') |
182
|
|
|
{ |
183
|
|
|
return $this->getClient()->setApiVersion('2.0')->get( |
184
|
|
|
sprintf('/repositories/%s/%s/refs/branches/%s', $account, $repo, $name) |
185
|
|
|
); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Get a pagination list of tags or tag object by name |
190
|
|
|
* |
191
|
|
|
* @access public |
192
|
|
|
* @param string $account The team or individual account owning the repository. |
193
|
|
|
* @param string $repo The repository identifier. |
194
|
|
|
* @param string $name The name of the tag |
195
|
1 |
|
* @return ResponseInterface |
196
|
|
|
*/ |
197
|
1 |
|
public function tags($account, $repo, $name = '') |
198
|
|
|
{ |
199
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->get( |
200
|
|
|
sprintf('/repositories/%s/%s/refs/tags/%s', $account, $repo, $name) |
201
|
1 |
|
); |
202
|
1 |
|
} |
203
|
1 |
|
|
204
|
1 |
|
/** |
205
|
|
|
* Get the history of a file in a changeset |
206
|
|
|
* |
207
|
|
|
* Returns the history of a file starting from the provided changeset. |
208
|
|
|
* |
209
|
|
|
* @access public |
210
|
|
|
* @param string $account The team or individual account owning the repository. |
211
|
|
|
* @param string $repo The repository identifier. |
212
|
|
|
* @param string $node The simple changeset node id. |
213
|
|
|
* @param string $path Filename. |
214
|
|
|
* @return ResponseInterface |
215
|
|
|
*/ |
216
|
1 |
|
public function filehistory($account, $repo, $node, $path) |
217
|
|
|
{ |
218
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->get( |
219
|
1 |
|
sprintf('/repositories/%s/%s/filehistory/%s/%s', $account, $repo, $node, $path) |
220
|
|
|
); |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|