Skip to content

Commit 739fbfe

Browse files
committed
implemented Comments::get and Comments::all for Commits (API 2.0)
1 parent c73d21b commit 739fbfe

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed

docs/repositories/commits.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ $commits->deleteApproval($account_name, $repo_slug, $commitSHA1);
4040

4141
#### Related:
4242
* [Authentication](../authentication.md)
43+
* [Commit(s) comments](commits/comments.md)
4344
* [BB Wiki](https://confluence.atlassian.com/x/doA7Fw)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Commits comments
2+
3+
---
4+
Manage commits comments.
5+
6+
### Prepare:
7+
```php
8+
$commit = new Bitbucket\API\Repositories\Commits();
9+
$commit->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
10+
```
11+
12+
### Get a list of a commit comments: (API 2.0)
13+
```php
14+
$commit->comments()->all($account_name, $repo_slug, $commitSHA1)
15+
```
16+
17+
### Get an individual commit comment: (API 2.0)
18+
```php
19+
$commit->comments()->get($account_name, $repo_slug, $commitSHA1, $commentID)
20+
```
21+
22+
----
23+
24+
#### Related:
25+
* [Authentication](../../authentication.md)
26+
* [Commit(s)](../commits.md)

lib/Bitbucket/API/Repositories/Commits.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,16 @@ public function deleteApproval($account, $repo, $revision)
9292
sprintf('repositories/%s/%s/commit/%s/approve', $account, $repo, $revision)
9393
);
9494
}
95+
96+
/**
97+
* Get comments
98+
*
99+
* @access public
100+
* @return Commits\Comments
101+
* @codeCoverageIgnore
102+
*/
103+
public function comments()
104+
{
105+
return $this->childFactory('Repositories\\Commits\\Comments');
106+
}
95107
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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\Repositories\Commits;
13+
14+
use Bitbucket\API\Api;
15+
use Buzz\Message\MessageInterface;
16+
17+
/**
18+
* @author Alexandru G. <alex@gentle.ro>
19+
*/
20+
class Comments extends Api
21+
{
22+
/**
23+
* Get a list of a commit comments
24+
*
25+
* @access public
26+
* @param string $account The team or individual account owning the repository.
27+
* @param string $repo The repository identifier.
28+
* @param string $revision A SHA1 value for the commit.
29+
* @return MessageInterface
30+
*/
31+
public function all($account, $repo, $revision)
32+
{
33+
return $this->getClient()->setApiVersion('2.0')->get(
34+
sprintf('repositories/%s/%s/commit/%s/comments', $account, $repo, $revision)
35+
);
36+
}
37+
38+
/**
39+
* Get an individual commit comment
40+
*
41+
* @access public
42+
* @param string $account The team or individual account owning the repository.
43+
* @param string $repo The repository identifier.
44+
* @param string $revision A SHA1 value for the commit.
45+
* @param int $commentID The comment identifier.
46+
* @return MessageInterface
47+
*/
48+
public function get($account, $repo, $revision, $commentID)
49+
{
50+
return $this->getClient()->setApiVersion('2.0')->get(
51+
sprintf('repositories/%s/%s/commit/%s/comments/%d', $account, $repo, $revision, $commentID)
52+
);
53+
}
54+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Bitbucket\Tests\API\Repositories\PullRequest;
4+
5+
use Bitbucket\Tests\API as Tests;
6+
use Bitbucket\API;
7+
8+
class CommitsTest extends Tests\TestCase
9+
{
10+
public function testGetAllComments()
11+
{
12+
$endpoint = 'repositories/gentle/eof/commit/SHA1/comments';
13+
$expectedResult = $this->fakeResponse(array('dummy'));
14+
15+
$client = $this->getHttpClientMock();
16+
$client->expects($this->once())
17+
->method('get')
18+
->with($endpoint)
19+
->will($this->returnValue($expectedResult));
20+
21+
/** @var \Bitbucket\API\Repositories\Commits\Comments $comments */
22+
$comments = $this->getClassMock('Bitbucket\API\Repositories\Commits\Comments', $client);
23+
$actual = $comments->all('gentle', 'eof', 'SHA1');
24+
25+
$this->assertEquals($expectedResult, $actual);
26+
}
27+
28+
public function testGetSingleComment()
29+
{
30+
$endpoint = 'repositories/gentle/eof/commit/SHA1/comments/1';
31+
$expectedResult = $this->fakeResponse(array('dummy'));
32+
33+
$client = $this->getHttpClientMock();
34+
$client->expects($this->once())
35+
->method('get')
36+
->with($endpoint)
37+
->will($this->returnValue($expectedResult));
38+
39+
/** @var \Bitbucket\API\Repositories\Commits\Comments $comments */
40+
$comments = $this->getClassMock('Bitbucket\API\Repositories\Commits\Comments', $client);
41+
$actual = $comments->get('gentle', 'eof', 'SHA1', 1);
42+
43+
$this->assertEquals($expectedResult, $actual);
44+
}
45+
}

0 commit comments

Comments
 (0)