Skip to content

Commit 5583d0e

Browse files
committed
Merge branch 'release/0.8.0'
2 parents c3de78a + 7d7a76c commit 5583d0e

File tree

7 files changed

+210
-3
lines changed

7 files changed

+210
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 0.8.0 / 2015-12-05
6+
7+
### Added:
8+
- Implemented build statuses endpoints. (PR #27)
9+
10+
## Fixed:
11+
- Usage of short array syntax inside one test, forced the test suite to fail on PHP 5.3
12+
513
## 0.7.1 / 2015-11-07
614

715
### Fixed:

docs/examples/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ title: Examples
5050
- [Hooks](repositories/webhooks.html)
5151
- [Src](repositories/src.html)
5252
- [Wiki](repositories/wiki.html)
53+
- [Build statuses](repositories/commits/build-statuses.html)
5354
- [Teams](teams.html)
5455
- [User](user.html)
5556
- [Repositories](user/repositories.html)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
layout: default
3+
permalink: /examples/repositories/commits/build-statuses.html
4+
title: Build Statuses
5+
---
6+
7+
# Build Statuses
8+
9+
Manages build statuses on a commit.
10+
11+
### Prepare:
12+
13+
```php
14+
$buildStatuses = new Bitbucket\API\Repositories\Commits\BuildStatuses();
15+
$buildStatuses->setCredentials( new Bitbucket\API\Authentication\Basic($user, $password) );
16+
```
17+
18+
### Get the build status for a commit: (API 2.0)
19+
20+
```php
21+
$buildStatuses->get($account, $repository, $revision, $key);
22+
```
23+
24+
### Adds a build status to a commit: (API 2.0)
25+
26+
```php
27+
$buildStatuses->create($account, $repository, $revision, array(
28+
'state' => 'FAILED',
29+
'key'=> 'JENKINS-PROJECT-X',
30+
'name'=> 'Build #1',
31+
'url'=> 'https://example.com/path/to/build/info',
32+
'description'=> 'Changes by John Doe'
33+
));
34+
```
35+
36+
### Updates the build status for a commit: (API 2.0)
37+
38+
```php
39+
$buildStatuses->update($account, $repository, $revision, $key, array(
40+
'state' => 'SUCCESSFUL',
41+
'name'=> 'Build #2',
42+
'url'=> 'https://example.com/path/to/build/info',
43+
'description'=> 'Changes by John Doe'
44+
));
45+
```
46+
47+
----
48+
49+
#### Related:
50+
* [Authentication]({{ site.url }}/examples/authentication.html)
51+
* [BB Wiki](https://confluence.atlassian.com/bitbucket/buildstatus-resource-779295267.html)

lib/Bitbucket/API/Http/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Client extends ClientListener implements ClientInterface
3333
'api_versions' => array('1.0', '2.0'), // supported versions
3434
'format' => 'json',
3535
'formats' => array('json', 'xml'), // supported response formats
36-
'user_agent' => 'bitbucket-api-php/0.7.1 (https://bitbucket.org/gentlero/bitbucket-api)',
36+
'user_agent' => 'bitbucket-api-php/0.8.0 (https://bitbucket.org/gentlero/bitbucket-api)',
3737
'timeout' => 10,
3838
'verify_peer' => false
3939
);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 Brice M. <brice.mancone@gmail.com>
19+
*/
20+
class BuildStatuses extends Api
21+
{
22+
/**
23+
* Returns the status for specific build associated with a commit.
24+
*
25+
* @access public
26+
* @param string $account The team or individual account owning the repository.
27+
* @param string $repository The repository identifier.
28+
* @param string $revision A SHA1 value for the commit.
29+
* @param string $key The key that distinguishes the build status from others.
30+
* @return MessageInterface
31+
*
32+
* @see https://confluence.atlassian.com/bitbucket/buildstatus-resource-779295267.html
33+
*/
34+
public function get($account, $repository, $revision, $key)
35+
{
36+
return $this->getClient()->setApiVersion('2.0')->get(
37+
sprintf('repositories/%s/%s/commit/%s/statuses/build/%s', $account, $repository, $revision, $key)
38+
);
39+
}
40+
41+
/**
42+
* Adds a build status to a commit.
43+
* If the build is already associated with the commit, a POST also updates the status.
44+
*
45+
* @access public
46+
* @param string $account The team or individual account owning the repository.
47+
* @param string $repository The repository identifier.
48+
* @param string $revision A SHA1 value for the commit.
49+
* @param array $params The status.
50+
* @return MessageInterface
51+
*
52+
* @see https://confluence.atlassian.com/bitbucket/buildstatus-resource-779295267.html
53+
*/
54+
public function create($account, $repository, $revision, $params)
55+
{
56+
return $this->getClient()->setApiVersion('2.0')->post(
57+
sprintf('repositories/%s/%s/commit/%s/statuses/build', $account, $repository, $revision),
58+
json_encode($params),
59+
array('Content-Type' => 'application/json')
60+
);
61+
}
62+
63+
/**
64+
* Updates the build status for a commit.
65+
*
66+
* @access public
67+
* @param string $account The team or individual account owning the repository.
68+
* @param string $repository The repository identifier.
69+
* @param string $revision A SHA1 value for the commit.
70+
* @param string $key The key that distinguishes the build status from others.
71+
* @param array $params The status.
72+
* @return MessageInterface
73+
*
74+
* @see https://confluence.atlassian.com/bitbucket/buildstatus-resource-779295267.html
75+
*/
76+
public function update($account, $repository, $revision, $key, $params)
77+
{
78+
return $this->getClient()->setApiVersion('2.0')->put(
79+
sprintf('repositories/%s/%s/commit/%s/statuses/build/%s', $account, $repository, $revision, $key),
80+
json_encode($params),
81+
array('Content-Type' => 'application/json')
82+
);
83+
}
84+
}

test/Bitbucket/Tests/API/Http/ClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ public function testShouldDoPatchRequestAndReturnResponseInstance()
137137

138138
public function testClientIsKeptWhenInvokingChildFactory()
139139
{
140-
$options = [
140+
$options = array(
141141
'base_url' => 'localhost'
142-
];
142+
);
143143
$client = new Client($options);
144144
$pullRequest = new \Bitbucket\API\Repositories\PullRequests();
145145
$pullRequest->setClient($client);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Bitbucket\Tests\API\Repositories\Commits\Statuses;
4+
5+
use Bitbucket\Tests\API as Tests;
6+
use Bitbucket\API;
7+
8+
class BuildStatusesTest extends Tests\TestCase
9+
{
10+
public function testGet()
11+
{
12+
$endpoint = 'repositories/gentle/eof/commit/SHA1/statuses/build/KEY';
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\BuildStatuses $buildStatus */
22+
$buildStatus = $this->getClassMock('Bitbucket\API\Repositories\Commits\BuildStatuses', $client);
23+
$actual = $buildStatus->get('gentle', 'eof', 'SHA1', 'KEY');
24+
25+
$this->assertEquals($expectedResult, $actual);
26+
}
27+
28+
public function testCreate()
29+
{
30+
$endpoint = 'repositories/gentle/eof/commit/SHA1/statuses/build';
31+
$params = json_encode(array(
32+
'state' => 'SUCCESSFUL'
33+
));
34+
35+
$client = $this->getHttpClientMock();
36+
$client->expects($this->once())
37+
->method('post')
38+
->with($endpoint);
39+
40+
/** @var \Bitbucket\API\Repositories\Commits\BuildStatuses $buildStatus */
41+
$buildStatus = $this->getClassMock('Bitbucket\API\Repositories\Commits\BuildStatuses', $client);
42+
43+
$buildStatus->create('gentle', 'eof', 'SHA1', $params);
44+
}
45+
46+
public function testUpdate()
47+
{
48+
$endpoint = 'repositories/gentle/eof/commit/SHA1/statuses/build/KEY';
49+
$params = json_encode(array(
50+
'state' => 'SUCCESSFUL'
51+
));
52+
53+
$client = $this->getHttpClientMock();
54+
$client->expects($this->once())
55+
->method('put')
56+
->with($endpoint);
57+
58+
/** @var \Bitbucket\API\Repositories\Commits\BuildStatuses $buildStatus */
59+
$buildStatus = $this->getClassMock('Bitbucket\API\Repositories\Commits\BuildStatuses', $client);
60+
61+
$buildStatus->update('gentle', 'eof', 'SHA1', 'KEY', $params);
62+
}
63+
}

0 commit comments

Comments
 (0)