Skip to content

Commit 3717439

Browse files
committed
updated PullRequests::activity to support fetching a single PR activity
1 parent bbcd02d commit 3717439

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

docs/repositories/pullrequests.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ $pull->delete($account_name, $repo_slug, 1);
7777
$pull->diff($account_name, $repo_slug, 1);
7878
```
7979

80-
### Get the log of all of a repository's pull request activity
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+
8183
```php
8284
$pull->activity($account_name, $repo_slug, 1);
8385
```

lib/Bitbucket/API/Repositories/PullRequests.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,25 @@ public function diff($account, $repo, $id)
215215
/**
216216
* Get the log of all of a repository's pull request activity
217217
*
218+
* If `$id` is omitted the repository's pull request activity is returned.
219+
* If `$id` is not omitted the pull request activity is returned.
220+
*
218221
* @access public
219222
* @param string $account The team or individual account owning the repository.
220223
* @param string $repo The repository identifier.
221-
* @param int $id ID of the pull request
224+
* @param int $id (Optional) ID of the pull request
222225
* @return MessageInterface
223226
*/
224-
public function activity($account, $repo, $id)
227+
public function activity($account, $repo, $id = 0)
225228
{
226-
return $this->getClient()->setApiVersion('2.0')->get(
227-
sprintf('repositories/%s/%s/pullrequests/%d/activity', $account, $repo, $id)
228-
);
229+
$endpoint = sprintf('repositories/%s/%s/pullrequests/', $account, $repo);
230+
231+
if ($id === 0) {
232+
$endpoint .= 'activity';
233+
} else {
234+
$endpoint .= $id.'/activity';
235+
}
236+
237+
return $this->getClient()->setApiVersion('2.0')->get($endpoint);
229238
}
230239
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,22 @@ public function testGetPullRequestActivity()
236236

237237
$this->assertEquals($expectedResult, $actual);
238238
}
239+
240+
public function testGetRepositoryPullRequestActivity()
241+
{
242+
$endpoint = 'repositories/gentle/eof/pullrequests/activity';
243+
$expectedResult = $this->fakeResponse(array('dummy'));
244+
245+
$client = $this->getHttpClientMock();
246+
$client->expects($this->once())
247+
->method('get')
248+
->with($endpoint)
249+
->will($this->returnValue($expectedResult));
250+
251+
/** @var \Bitbucket\API\Repositories\PullRequests $pull */
252+
$pull = $this->getClassMock('Bitbucket\API\Repositories\PullRequests', $client);
253+
$actual = $pull->activity('gentle', 'eof');
254+
255+
$this->assertEquals($expectedResult, $actual);
256+
}
239257
}

0 commit comments

Comments
 (0)