Skip to content

Commit e7d74c1

Browse files
author
Kevin Howe
committed
Updated Repository to support API v2.0 tags GET and POST
1 parent a9d7c1c commit e7d74c1

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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\Refs;
13+
14+
use Bitbucket\API;
15+
16+
/**
17+
* @author Kevin Howe <kjhowe@gmail.com>
18+
*/
19+
class Tags extends API\Api
20+
{
21+
/**
22+
* Get a list of tags
23+
*
24+
* @access public
25+
* @param string $account The team or individual account owning the repository.
26+
* @param string $repo The repository identifier.
27+
* @return MessageInterface
28+
*/
29+
public function all($account, $repo)
30+
{
31+
return $this->getClient()->setApiVersion('2.0')->get(
32+
sprintf('repositories/%s/%s/refs/tags', $account, $repo)
33+
);
34+
}
35+
36+
/**
37+
* Create a new tag
38+
*
39+
* @access public
40+
* @param string $account The team or individual account owning the repository.
41+
* @param string $repo The repository identifier.
42+
* @param string $name The name of the new tag.
43+
* @param string $hash The hash to tag.
44+
* @return MessageInterface
45+
*/
46+
public function create($account, $repo, $name, $hash)
47+
{
48+
$params = [
49+
'name' => $name,
50+
'target' => [
51+
'hash' => $hash,
52+
],
53+
];
54+
55+
$data = json_encode($params);
56+
57+
return $this->getClient()->setApiVersion('2.0')->post(
58+
sprintf('repositories/%s/%s/refs/tags', $account, $repo),
59+
$data,
60+
array('Content-Type' => 'application/json')
61+
);
62+
}
63+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Bitbucket\Tests\API\Repositories\Refs;
4+
5+
use Bitbucket\Tests\API as Tests;
6+
7+
class TagsTest extends Tests\TestCase
8+
{
9+
public function testAll()
10+
{
11+
$endpoint = 'repositories/gentle/eof/refs/tags';
12+
$expectedResult = json_encode('dummy');
13+
14+
$client = $this->getHttpClientMock();
15+
$client->expects($this->once())
16+
->method('get')
17+
->with($endpoint)
18+
->will($this->returnValue($expectedResult));
19+
20+
$repository = $this->getClassMock('Bitbucket\API\Repositories\Refs\Tags', $client);
21+
22+
/** @var $repository \Bitbucket\API\Repositories\Refs\Tags */
23+
$actual = $repository->all('gentle', 'eof');
24+
25+
$this->assertEquals($expectedResult, $actual);
26+
}
27+
28+
public function testCreate()
29+
{
30+
$endpoint = 'repositories/gentle/eof/refs/tags';
31+
$expectedResult = json_encode('dummy');
32+
33+
$client = $this->getHttpClientMock();
34+
$client->expects($this->once())
35+
->method('post')
36+
->with($endpoint)
37+
->will($this->returnValue($expectedResult));
38+
39+
$repository = $this->getClassMock('Bitbucket\API\Repositories\Refs\Tags', $client);
40+
41+
/** @var $repository \Bitbucket\API\Repositories\Refs\Tags */
42+
$actual = $repository->create('gentle', 'eof', 'tagName', '2310abb944423ecf1a90be9888dafd096744b531');
43+
44+
$this->assertEquals($expectedResult, $actual);
45+
}
46+
}

0 commit comments

Comments
 (0)