Skip to content

Commit c8f21e1

Browse files
committed
implemented PullRequests::update (API 2.0)
1 parent d089a2b commit c8f21e1

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

docs/repositories/pullrequests.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ $pull->create('gentle', 'secret-repo', array(
3939
)
4040
));
4141
```
42+
43+
### Update a pull request:
44+
```php
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+
));
53+
```
54+
4255
----
4356

4457
#### Related:

lib/Bitbucket/API/Repositories/PullRequests.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Bitbucket\API\Repositories;
1313

1414
use Bitbucket\API;
15-
use Bitbucket\API\Utils;
1615
use Buzz\Message\MessageInterface;
1716

1817
/**
@@ -96,4 +95,38 @@ public function create($account, $repo, $params = array())
9695
array('Content-Type' => 'application/json')
9796
);
9897
}
98+
99+
/**
100+
* Update a pull request
101+
*
102+
* @access public
103+
* @param string $account The team or individual account owning the repository.
104+
* @param string $repo The repository identifier.
105+
* @param int $id ID of the pull request that will be updated
106+
* @param array $params Additional parameters
107+
* @return MessageInterface
108+
*/
109+
public function update($account, $repo, $id, $params = array())
110+
{
111+
// allow developer to directly specify params as json if (s)he wants.
112+
if (!empty($params) && is_array($params)) {
113+
$params = json_encode(array_merge(
114+
array(
115+
'title' => 'Updated pull request',
116+
'destination' => array(
117+
'branch' => array(
118+
'name' => 'develop'
119+
)
120+
)
121+
),
122+
$params
123+
));
124+
}
125+
126+
return $this->getClient()->setApiVersion('2.0')->put(
127+
sprintf('repositories/%s/%s/pullrequests/%d', $account, $repo, $id),
128+
$params,
129+
array('Content-Type' => 'application/json')
130+
);
131+
}
99132
}

test/Bitbucket/Tests/API/Repositories/PullRequestsTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,50 @@ public function testCreateNewPullRequestFromArray()
8888

8989
$pull->create('gentle', 'eof', $params);
9090
}
91+
92+
public function testUpdatePullRequestFromJSON()
93+
{
94+
$endpoint = 'repositories/gentle/eof/pullrequests/1';
95+
$params = json_encode(array(
96+
'title' => 'Test PR (updated)',
97+
'destination' => array(
98+
'branch' => array(
99+
'name' => 'master'
100+
)
101+
)
102+
));
103+
104+
$client = $this->getHttpClientMock();
105+
$client->expects($this->once())
106+
->method('put')
107+
->with($endpoint, $params);
108+
109+
/** @var \Bitbucket\API\Repositories\PullRequests $pull */
110+
$pull = $this->getClassMock('Bitbucket\API\Repositories\PullRequests', $client);
111+
112+
$pull->update('gentle', 'eof', 1, $params);
113+
}
114+
115+
public function testUpdatePullRequestFromArray()
116+
{
117+
$endpoint = 'repositories/gentle/eof/pullrequests/1';
118+
$params = array(
119+
'title' => 'Test PR (updated)',
120+
'destination' => array(
121+
'branch' => array(
122+
'name' => 'master'
123+
)
124+
),
125+
);
126+
127+
$client = $this->getHttpClientMock();
128+
$client->expects($this->once())
129+
->method('put')
130+
->with($endpoint, json_encode($params));
131+
132+
/** @var \Bitbucket\API\Repositories\PullRequests $pull */
133+
$pull = $this->getClassMock('Bitbucket\API\Repositories\PullRequests', $client);
134+
135+
$pull->update('gentle', 'eof', 1, $params);
136+
}
91137
}

0 commit comments

Comments
 (0)