Skip to content

Commit 8da2564

Browse files
committed
Merge branch 'feature/api-v2' into develop
- Updated Repositories/Repository to API 2.0 (+BC). Methods that uses API 1.0 endpoints and have a corespondent in API 2.0 (like, but not limited to: Repository::create) have been deprecated.
2 parents bec3904 + cb34b34 commit 8da2564

File tree

5 files changed

+245
-31
lines changed

5 files changed

+245
-31
lines changed

docs/Home.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A simple PHP wrapper for Bitbucket API.
1818
* [Issues](repositories/issues.md)
1919
* [Links](repositories/links.md)
2020
* [PullRequests](repositories/pullrequests.md) (API 2.0)
21-
* [Repository](repositories/repository.md)
21+
* [Repository](repositories/repository.md) (API 2.0)
2222
* [Services](repositories/services.md)
2323
* [Src](repositories/src.md)
2424
* [Wiki](repositories/wiki.md)

docs/repositories/pullrequests.md

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

12-
### Get all pull requests:
12+
### Get all pull requests: (API 2.0)
1313
```php
1414
$pull->all($account_name, $repo_slug);
1515
```
1616

17-
### Get all merged pull requests:
17+
### Get all merged pull requests: (API 2.0)
1818
```php
1919
$pull->all($account_name, $repo_slug, array('state' => 'merged'));
2020
```
2121

22-
### Create a new pull request:
22+
### Create a new pull request: (API 2.0)
2323
```php
2424
$pull->create('gentle', 'secret-repo', array(
2525
'title' => 'Test PR',
@@ -40,7 +40,7 @@ $pull->create('gentle', 'secret-repo', array(
4040
));
4141
```
4242

43-
### Update a pull request:
43+
### Update a pull request: (API 2.0)
4444
```php
4545
$pull->update('gentle', 'secret-repo', 1, array(
4646
'title' => 'Test PR (updated)',
@@ -52,46 +52,46 @@ $pull->update('gentle', 'secret-repo', 1, array(
5252
));
5353
```
5454

55-
### Get a specific pull request:
55+
### Get a specific pull request: (API 2.0)
5656
```php
5757
$pull->get($account_name, $repo_slug, 1);
5858
```
5959

60-
### Get the commits for a pull request:
60+
### Get the commits for a pull request: (API 2.0)
6161
```php
6262
$pull->commits($account_name, $repo_slug, 1);
6363
```
6464

65-
### Approve a pull request:
65+
### Approve a pull request: (API 2.0)
6666
```php
6767
$pull->approve($account_name, $repo_slug, 1);
6868
```
6969

70-
### Delete a a pull request approval:
70+
### Delete a a pull request approval: (API 2.0)
7171
```php
7272
$pull->delete($account_name, $repo_slug, 1);
7373
```
7474

75-
### Get the diff for a pull request:
75+
### Get the diff for a pull request: (API 2.0)
7676
```php
7777
$pull->diff($account_name, $repo_slug, 1);
7878
```
7979

80-
### Get the log of a pull request activity
80+
### Get the log of a pull request activity: (API 2.0)
8181
If pull request ID is omitted, the entire repository's pull request activity is returned.
8282

8383
```php
8484
$pull->activity($account_name, $repo_slug, 1);
8585
```
8686

87-
### Accept and merge a pull request:
87+
### Accept and merge a pull request: (API 2.0)
8888
```php
8989
$pull->accept($account_name, $repo_slug, 1, array(
9090
'message' => 'This message will be used for merge commit.'
9191
));
9292
```
9393

94-
### Decline a pull request:
94+
### Decline a pull request: (API 2.0)
9595
```php
9696
$pull->accept($account_name, $repo_slug, 1, array(
9797
'message' => 'Please update the docs to reflect new changes.'

docs/repositories/repository.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ $repo = new Bitbucket\API\Repositories\Repository();
99
$repo->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
1010
```
1111

12-
### Create a new repository:
12+
### Get information associated with an individual repository: (API 2.0)
13+
```php
14+
$repo->get($account_name, $repo_slug);
15+
```
16+
17+
### Create a new repository: (API 1.0)
18+
**NOTE:** API 1.0 endpoint for repository creation has been deprecated, so please use the new API 2.0 endpoint described bellow.
19+
1320
```php
1421
$repo->create($repo_slug, array(
1522
'description' => 'My super secret project.',
@@ -18,6 +25,17 @@ $repo->create($repo_slug, array(
1825
));
1926
```
2027

28+
### Create a new repository: (API 2.0)
29+
```php
30+
$repo->create($account_name, $repo_slug, array(
31+
'scm' => 'git',
32+
'description' => 'My super secret project.',
33+
'language' => 'php',
34+
'is_private' => true,
35+
'forking_policy' => 'no_public_forks',
36+
));
37+
```
38+
2139
### Update an existing repository:
2240
```php
2341
$repo->update($account_name, $repo_slug, array(
@@ -27,11 +45,21 @@ $repo->update($account_name, $repo_slug, array(
2745
));
2846
```
2947

30-
### Delete a repository:
48+
### Delete a repository: (API 2.0)
3149
```php
3250
$repo->delete($account_name, $repo_slug);
3351
```
3452

53+
### Get the list of accounts watching a repository: (API 2.0)
54+
```php
55+
$repo->watchers($account_name, $repo_slug);
56+
```
57+
58+
### Get the list of repository forks: (API 2.0)
59+
```php
60+
$repo->forks($account_name, $repo_slug);
61+
```
62+
3563
### Fork a repository:
3664
```php
3765
$repo->fork($account_name, $repo_slug, $fork_slug, array(

lib/Bitbucket/API/Repositories/Repository.php

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
/*
3+
/**
44
* This file is part of the bitbucket-api package.
55
*
66
* (c) Alexandru G. <alex@gentle.ro>
@@ -12,16 +12,73 @@
1212
namespace Bitbucket\API\Repositories;
1313

1414
use Bitbucket\API;
15+
use Buzz\Message\MessageInterface;
1516

1617
/**
17-
* Repository class
18-
*
1918
* Allows you to create a new repository or edit a specific one.
2019
*
2120
* @author Alexandru G. <alex@gentle.ro>
2221
*/
2322
class Repository extends API\Api
2423
{
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 MessageInterface
31+
*/
32+
public function get($account, $repo)
33+
{
34+
return $this->getClient()->setApiVersion('2.0')->get(
35+
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 $params Additional parameters
49+
* @return MessageInterface
50+
*
51+
* @see https://confluence.atlassian.com/x/WwZAGQ
52+
*/
53+
public function create($account, $repo, $params = array())
54+
{
55+
// Keep BC for now.
56+
// @todo[1]: to be removed.
57+
if (is_array($repo)) {
58+
return $this->createLegacy($account, $repo);
59+
}
60+
61+
// allow developer to directly specify params as json if (s)he wants.
62+
if (!empty($params) && is_array($params)) {
63+
$params = json_encode(array_merge(
64+
array(
65+
'scm' => 'git',
66+
'name' => $repo,
67+
'is_private' => true,
68+
'description' => 'My secret repo',
69+
'forking_policy' => 'no_forks',
70+
),
71+
$params
72+
));
73+
}
74+
75+
return $this->getClient()->setApiVersion('2.0')->post(
76+
sprintf('repositories/%s/%s', $account, $repo),
77+
$params,
78+
array('Content-Type' => 'application/json')
79+
);
80+
}
81+
2582
/**
2683
* Create a new repository
2784
*
@@ -38,8 +95,11 @@ class Repository extends API\Api
3895
* @param string $name The name of the repository
3996
* @param array $params Additional parameters
4097
* @return mixed
98+
*
99+
* @deprecated This API 1.0 endpoint is deprecated.
100+
* @see $this->create() Sintax for using API 2.0 endpoint
41101
*/
42-
public function create($name, array $params = array())
102+
private function createLegacy($name, array $params = array())
43103
{
44104
$params['name'] = $name;
45105

@@ -58,7 +118,7 @@ public function create($name, array $params = array())
58118
* @param array $params Additional parameters
59119
* @return mixed
60120
*
61-
* @see https://confluence.atlassian.com/display/BITBUCKET/repository+Resource#repositoryResource-PUTarepositoryupdate
121+
* @see https://confluence.atlassian.com/x/WwZAGQ
62122
*/
63123
public function update($account, $repo, array $params = array())
64124
{
@@ -72,17 +132,47 @@ public function update($account, $repo, array $params = array())
72132
* Delete a repository
73133
*
74134
* @access public
75-
* @param string $account The team or individual account owning the repository.
76-
* @param string $repo The repository identifier.
77-
* @return mixed
135+
* @param string $account The team or individual account owning the repository.
136+
* @param string $repo The repository identifier.
137+
* @return MessageInterface
78138
*/
79139
public function delete($account, $repo)
80140
{
81-
return $this->requestDelete(
141+
return $this->getClient()->setApiVersion('2.0')->delete(
82142
sprintf('repositories/%s/%s', $account, $repo)
83143
);
84144
}
85145

146+
/**
147+
* Gets the list of accounts watching a repository.
148+
*
149+
* @access public
150+
* @param string $account The team or individual account owning the repository.
151+
* @param string $repo The repository identifier.
152+
* @return MessageInterface
153+
*/
154+
public function watchers($account, $repo)
155+
{
156+
return $this->getClient()->setApiVersion('2.0')->get(
157+
sprintf('repositories/%s/%s/watchers', $account, $repo)
158+
);
159+
}
160+
161+
/**
162+
* Gets the list of repository forks.
163+
*
164+
* @access public
165+
* @param string $account The team or individual account owning the repository.
166+
* @param string $repo The repository identifier.
167+
* @return MessageInterface
168+
*/
169+
public function forks($account, $repo)
170+
{
171+
return $this->getClient()->setApiVersion('2.0')->get(
172+
sprintf('repositories/%s/%s/forks', $account, $repo)
173+
);
174+
}
175+
86176
/**
87177
* Fork a repository
88178
*

0 commit comments

Comments
 (0)