Skip to content

Commit 7574e92

Browse files
committed
Merge pull request KnpLabs#176 from nidup/feature/combined-status
Add support for the combined view of commit statuses
2 parents 414457e + e715465 commit 7574e92

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

lib/Github/Api/Repository/Statuses.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,21 @@ class Statuses extends AbstractApi
2222
*/
2323
public function show($username, $repository, $sha)
2424
{
25-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/statuses/'.rawurlencode($sha));
25+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/statuses');
26+
}
27+
28+
/**
29+
* @link https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
30+
*
31+
* @param string $username
32+
* @param string $repository
33+
* @param string $sha
34+
*
35+
* @return array
36+
*/
37+
public function combined($username, $repository, $sha)
38+
{
39+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/status');
2640
}
2741

2842
/**
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Repository;
4+
5+
use Github\Tests\Api\TestCase;
6+
7+
class StatusesTest extends TestCase
8+
{
9+
/**
10+
* @test
11+
*/
12+
public function shouldShowCommitStatuses()
13+
{
14+
$expectedValue = array(
15+
array('state' => 'success', 'context' => 'Travis'),
16+
array('state' => 'pending', 'context' => 'Travis')
17+
);
18+
19+
$api = $this->getApiMock();
20+
$api->expects($this->once())
21+
->method('get')
22+
->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/statuses')
23+
->will($this->returnValue($expectedValue));
24+
25+
$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'commitSHA123456'));
26+
}
27+
28+
/**
29+
* @test
30+
*/
31+
public function shouldShowCombinedCommitStatuses()
32+
{
33+
$expectedValue = array(
34+
array(
35+
'state' => 'success',
36+
'statuses' => array(
37+
array(
38+
'state' => 'success',
39+
'context' => 'Travis'
40+
),
41+
array(
42+
'state' => 'success',
43+
'context' => 'Jenkins'
44+
)
45+
)
46+
)
47+
);
48+
49+
$api = $this->getApiMock();
50+
$api->expects($this->once())
51+
->method('get')
52+
->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/status')
53+
->will($this->returnValue($expectedValue));
54+
55+
$this->assertEquals($expectedValue, $api->combined('KnpLabs', 'php-github-api', 'commitSHA123456'));
56+
}
57+
58+
/**
59+
* @test
60+
* @expectedException Github\Exception\MissingArgumentException
61+
*/
62+
public function shouldNotCreateWithoutStatus()
63+
{
64+
$data = array();
65+
66+
$api = $this->getApiMock();
67+
$api->expects($this->never())
68+
->method('post');
69+
70+
$api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data);
71+
}
72+
73+
/**
74+
* @test
75+
*/
76+
public function shouldCreateCommitStatus()
77+
{
78+
$expectedValue = array('state' => 'success');
79+
$data = array('state' => 'success');
80+
81+
$api = $this->getApiMock();
82+
$api->expects($this->once())
83+
->method('post')
84+
->with('repos/KnpLabs/php-github-api/statuses/commitSHA123456', $data)
85+
->will($this->returnValue($expectedValue));
86+
87+
$this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data));
88+
}
89+
90+
protected function getApiClass()
91+
{
92+
return 'Github\Api\Repository\Statuses';
93+
}
94+
}

0 commit comments

Comments
 (0)