Skip to content

Commit bec3904

Browse files
committed
Merge branch 'feature/api-v2' into develop
Implemented repositories endpoint and repositories/pullrequests endpoint (API 2.0). Updated PullRequests/Comments to API 2.0
2 parents 88f02c7 + f5ef97a commit bec3904

File tree

14 files changed

+813
-90
lines changed

14 files changed

+813
-90
lines changed

docs/Home.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ A simple PHP wrapper for Bitbucket API.
1010
* [Group privileges](group-privileges.md)
1111
* [Invitations](invitations.md)
1212
* [Privileges](privileges.md)
13-
* [Repositories](repositories.md)
13+
* [Repositories](repositories.md) (API 2.0)
1414
* [Changesets](repositories/changesets.md)
1515
* [Deploykeys](repositories/deploykeys.md)
1616
* [Events](repositories/events.md)
1717
* [Followers](repositories/followers.md)
1818
* [Issues](repositories/issues.md)
1919
* [Links](repositories/links.md)
20-
* [PullRequests](repositories/pullrequests.md)
20+
* [PullRequests](repositories/pullrequests.md) (API 2.0)
2121
* [Repository](repositories/repository.md)
2222
* [Services](repositories/services.md)
2323
* [Src](repositories/src.md)
@@ -31,3 +31,7 @@ A simple PHP wrapper for Bitbucket API.
3131
* [OAuth](users/oauth.md)
3232
* [Privileges](users/privileges.md)
3333
* [SSH Keys](users/ssh-keys.md)
34+
35+
### Legend:
36+
37+
- API 2.0 = Contains methods that can be used against Bitbucket API v2.0

docs/repositories.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
----
44
The repositories namespace has a number of resources you can use to manage repository. The following resources are available on repositories:
55

6+
### Prepare:
7+
```php
8+
$repositories = new Bitbucket\API\Repositories();
9+
$repositories->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
10+
```
11+
12+
### Get a list of repositories for an account: (API 2.0)
13+
14+
If the caller is properly authenticated and authorized, this method returns a collection containing public and private repositories.
15+
```php
16+
$repositories->all($account_name);
17+
```
18+
19+
### Get a list of all public repositories: (API 2.0)
20+
21+
Only public repositories are returned.
22+
```php
23+
$repositories->all();
24+
```
25+
626
* [Changesets](repositories/changesets.md)
727
* [Deploykeys](repositories/deploykeys.md)
828
* [Events](repositories/events.md)

docs/repositories/pullrequests.md

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,98 @@ $pull = new Bitbucket\API\Repositories\PullRequests();
99
$pull->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
1010
```
1111

12-
### Get a list of a pull request comments:
12+
### Get all pull requests:
1313
```php
14-
$pull->comments()->all($account_name, $repo_slug, 1)
14+
$pull->all($account_name, $repo_slug);
1515
```
1616

17-
### Get an individual pull request comment:
17+
### Get all merged pull requests:
1818
```php
19-
$pull->comments()->get($account_name, $repo_slug, 1, 2)
19+
$pull->all($account_name, $repo_slug, array('state' => 'merged'));
2020
```
2121

22-
### Add a new comment:
22+
### Create a new pull request:
2323
```php
24-
$pull->comments()->create($account_name, $repo_slug, 41, "dummy content");
24+
$pull->create('gentle', 'secret-repo', array(
25+
'title' => 'Test PR',
26+
'description' => 'Fixed readme',
27+
'source' => array(
28+
'branch' => array(
29+
'name' => 'quickfix-1'
30+
),
31+
'repository' => array(
32+
'full_name' => 'vimishor/secret-repo'
33+
)
34+
),
35+
'destination' => array(
36+
'branch' => array(
37+
'name' => 'master'
38+
)
39+
)
40+
));
2541
```
2642

27-
### Update an existing comment:
43+
### Update a pull request:
2844
```php
29-
$pull->comments()->update($account_name, $repo_slug, 41, 4, "dummy content [edited]");
45+
$pull->update('gentle', 'secret-repo', 1, array(
46+
'title' => 'Test PR (updated)',
47+
'destination' => array(
48+
'branch' => array(
49+
'name' => 'master'
50+
)
51+
),
52+
));
3053
```
3154

32-
### Delete a pull request comment
55+
### Get a specific pull request:
3356
```php
34-
$pull->comments()->delete($account_name, $repo_slug, 41, 4);
57+
$pull->get($account_name, $repo_slug, 1);
3558
```
3659

37-
### Get all pull requests
60+
### Get the commits for a pull request:
3861
```php
39-
$pull->all($account_name, $repo_slug);
62+
$pull->commits($account_name, $repo_slug, 1);
63+
```
64+
65+
### Approve a pull request:
66+
```php
67+
$pull->approve($account_name, $repo_slug, 1);
68+
```
69+
70+
### Delete a a pull request approval:
71+
```php
72+
$pull->delete($account_name, $repo_slug, 1);
73+
```
74+
75+
### Get the diff for a pull request:
76+
```php
77+
$pull->diff($account_name, $repo_slug, 1);
78+
```
79+
80+
### Get the log of a pull request activity
81+
If pull request ID is omitted, the entire repository's pull request activity is returned.
82+
83+
```php
84+
$pull->activity($account_name, $repo_slug, 1);
85+
```
86+
87+
### Accept and merge a pull request:
88+
```php
89+
$pull->accept($account_name, $repo_slug, 1, array(
90+
'message' => 'This message will be used for merge commit.'
91+
));
92+
```
93+
94+
### Decline a pull request:
95+
```php
96+
$pull->accept($account_name, $repo_slug, 1, array(
97+
'message' => 'Please update the docs to reflect new changes.'
98+
));
4099
```
41100

42101
----
43102

44103
#### Related:
45104
* [Authentication](../authentication.md)
105+
* [PullRequests comments](pullrequests/comments.md)
46106
* [BB Wiki](https://confluence.atlassian.com/display/BITBUCKET/pullrequests+Resource#pullrequestsResource-Overview)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Pull requests comments
2+
3+
---
4+
Manage pull requests comments.
5+
6+
### Prepare:
7+
```php
8+
$pull = new Bitbucket\API\Repositories\PullRequests();
9+
$pull->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
10+
```
11+
12+
### Get a list of a pull request comments:
13+
```php
14+
$pull->comments()->all($account_name, $repo_slug, 1)
15+
```
16+
17+
### Get an individual pull request comment:
18+
```php
19+
$pull->comments()->get($account_name, $repo_slug, 1, 2)
20+
```
21+
22+
### Add a new comment:
23+
```php
24+
$pull->comments()->create($account_name, $repo_slug, 41, "dummy content");
25+
```
26+
27+
### Update an existing comment:
28+
```php
29+
$pull->comments()->update($account_name, $repo_slug, 41, 4, "dummy content [edited]");
30+
```
31+
32+
### Delete a pull request comment
33+
```php
34+
$pull->comments()->delete($account_name, $repo_slug, 41, 4);
35+
```

lib/Bitbucket/API/Api.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Bitbucket\API;
1313

14+
use Buzz\Message\MessageInterface;
1415
use Buzz\Message\RequestInterface;
1516
use Buzz\Client\ClientInterface as BuzzClientInterface;
1617
use Bitbucket\API\Http\ClientInterface;
@@ -123,10 +124,10 @@ public function authorize(RequestInterface $request)
123124
* Make an HTTP GET request to API
124125
*
125126
* @access public
126-
* @param string $endpoint API endpoint
127-
* @param string|array $params GET parameters
128-
* @param array $headers HTTP headers
129-
* @return mixed
127+
* @param string $endpoint API endpoint
128+
* @param string|array $params GET parameters
129+
* @param array $headers HTTP headers
130+
* @return MessageInterface
130131
*/
131132
public function requestGet($endpoint, $params = array(), $headers = array())
132133
{
@@ -137,10 +138,10 @@ public function requestGet($endpoint, $params = array(), $headers = array())
137138
* Make an HTTP POST request to API
138139
*
139140
* @access public
140-
* @param string $endpoint API endpoint
141-
* @param string|array $params POST parameters
142-
* @param array $headers HTTP headers
143-
* @return mixed
141+
* @param string $endpoint API endpoint
142+
* @param string|array $params POST parameters
143+
* @param array $headers HTTP headers
144+
* @return MessageInterface
144145
*/
145146
public function requestPost($endpoint, $params = array(), $headers = array())
146147
{
@@ -151,10 +152,10 @@ public function requestPost($endpoint, $params = array(), $headers = array())
151152
* Make an HTTP PUT request to API
152153
*
153154
* @access public
154-
* @param string $endpoint API endpoint
155-
* @param string|array $params POST parameters
156-
* @param array $headers HTTP headers
157-
* @return mixed
155+
* @param string $endpoint API endpoint
156+
* @param string|array $params POST parameters
157+
* @param array $headers HTTP headers
158+
* @return MessageInterface
158159
*/
159160
public function requestPut($endpoint, $params = array(), $headers = array())
160161
{
@@ -165,10 +166,10 @@ public function requestPut($endpoint, $params = array(), $headers = array())
165166
* Make a HTTP DELETE request to API
166167
*
167168
* @access public
168-
* @param string $endpoint API endpoint
169-
* @param string|array $params DELETE parameters
170-
* @param array $headers HTTP headers
171-
* @return mixed
169+
* @param string $endpoint API endpoint
170+
* @param string|array $params DELETE parameters
171+
* @param array $headers HTTP headers
172+
* @return MessageInterface
172173
*/
173174
public function requestDelete($endpoint, $params = array(), $headers = array())
174175
{
@@ -179,11 +180,11 @@ public function requestDelete($endpoint, $params = array(), $headers = array())
179180
* Create HTTP request
180181
*
181182
* @access protected
182-
* @param string $method HTTP method
183-
* @param string $endpoint Api endpoint
184-
* @param string|array $params Request parameter(s)
185-
* @param array $headers HTTP headers
186-
* @return mixed
183+
* @param string $method HTTP method
184+
* @param string $endpoint Api endpoint
185+
* @param string|array $params Request parameter(s)
186+
* @param array $headers HTTP headers
187+
* @return MessageInterface
187188
*
188189
* @throws \RuntimeException
189190
*/

lib/Bitbucket/API/Http/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function isListener($name)
102102
*/
103103
public function get($endpoint, $params = array(), $headers = array())
104104
{
105-
if (is_array($params) AND count($params) > 0) {
105+
if (is_array($params) && count($params) > 0) {
106106
$endpoint .= (strpos($endpoint, '?') === false ? '?' : '&').http_build_query($params, '', '&');
107107
$params = array();
108108
}
@@ -137,7 +137,7 @@ public function delete($endpoint, $params = array(), $headers = array())
137137
/**
138138
* {@inheritDoc}
139139
*/
140-
public function request($endpoint, array $params = array(), $method, array $headers = array())
140+
public function request($endpoint, $params = array(), $method = 'GET', array $headers = array())
141141
{
142142
// do not set base URL if a full one was provided
143143
if (false === strpos($endpoint, $this->getApiBaseUrl())) {
@@ -159,7 +159,7 @@ public function request($endpoint, array $params = array(), $method, array $head
159159
$request->setContent(is_array($params) ? http_build_query($params) : $params);
160160
}
161161

162-
$response = new Response;
162+
$response = new Response;
163163

164164
$this->executeListeners($request, 'preSend');
165165

lib/Bitbucket/API/Http/ClientInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface ClientInterface
2828
* @param array $headers HTTP headers
2929
* @return MessageInterface
3030
*/
31-
public function get($endpoint, $params, $headers = array());
31+
public function get($endpoint, $params = array(), $headers = array());
3232

3333
/**
3434
* Make an HTTP POST request to API
@@ -39,7 +39,7 @@ public function get($endpoint, $params, $headers = array());
3939
* @param array $headers HTTP headers
4040
* @return MessageInterface
4141
*/
42-
public function post($endpoint, $params, $headers = array());
42+
public function post($endpoint, $params = array(), $headers = array());
4343

4444
/**
4545
* Make an HTTP PUT request to API
@@ -50,7 +50,7 @@ public function post($endpoint, $params, $headers = array());
5050
* @param array $headers HTTP headers
5151
* @return MessageInterface
5252
*/
53-
public function put($endpoint, $params, $headers = array());
53+
public function put($endpoint, $params = array(), $headers = array());
5454

5555
/**
5656
* Make a HTTP DELETE request to API
@@ -61,7 +61,7 @@ public function put($endpoint, $params, $headers = array());
6161
* @param array $headers HTTP headers
6262
* @return MessageInterface
6363
*/
64-
public function delete($endpoint, $params, $headers = array());
64+
public function delete($endpoint, $params = array(), $headers = array());
6565

6666
/**
6767
* Make a HTTP request
@@ -73,7 +73,7 @@ public function delete($endpoint, $params, $headers = array());
7373
* @param array $headers
7474
* @return MessageInterface
7575
*/
76-
public function request($endpoint, array $params = array(), $method, array $headers = array());
76+
public function request($endpoint, $params = array(), $method = 'GET', array $headers = array());
7777

7878
/**
7979
* Get response format for next request

lib/Bitbucket/API/Repositories.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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;
13+
14+
/**
15+
* @author Alexandru G. <alex@gentle.ro>
16+
*/
17+
class Repositories extends Api
18+
{
19+
/**
20+
* Get a list of repositories.
21+
*
22+
* - If the caller is properly authenticated and authorized, will also return
23+
* the private repositories.
24+
* - If `$owner` is omitted, will return a list of all public repositories on Bitbucket.
25+
*
26+
* @access public
27+
* @param string $owner The account of the repo owner.
28+
* @return mixed
29+
*
30+
* @api 2.0
31+
* @since Method available since 0.2.0
32+
*/
33+
public function all($owner = null)
34+
{
35+
$endpoint = 'repositories';
36+
37+
if (!is_null($owner)) {
38+
$endpoint = sprintf('repositories/%s', $owner);
39+
}
40+
41+
return $this->getClient()->setApiVersion('2.0')->get($endpoint);
42+
}
43+
}

0 commit comments

Comments
 (0)