Skip to content

Add support for the combined view of commit statuses #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/Github/Api/Repository/Statuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ class Statuses extends AbstractApi
*/
public function show($username, $repository, $sha)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/statuses/'.rawurlencode($sha));
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/statuses');
}

/**
* @link https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
*
* @param string $username
* @param string $repository
* @param string $sha
*
* @return array
*/
public function combined($username, $repository, $sha)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/status');
}

/**
Expand Down
94 changes: 94 additions & 0 deletions test/Github/Tests/Api/Repository/StatusesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Github\Tests\Api\Repository;

use Github\Tests\Api\TestCase;

class StatusesTest extends TestCase
{
/**
* @test
*/
public function shouldShowCommitStatuses()
{
$expectedValue = array(
array('state' => 'success', 'context' => 'Travis'),
array('state' => 'pending', 'context' => 'Travis')
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/statuses')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'commitSHA123456'));
}

/**
* @test
*/
public function shouldShowCombinedCommitStatuses()
{
$expectedValue = array(
array(
'state' => 'success',
'statuses' => array(
array(
'state' => 'success',
'context' => 'Travis'
),
array(
'state' => 'success',
'context' => 'Jenkins'
)
)
)
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/status')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->combined('KnpLabs', 'php-github-api', 'commitSHA123456'));
}

/**
* @test
* @expectedException Github\Exception\MissingArgumentException
*/
public function shouldNotCreateWithoutStatus()
{
$data = array();

$api = $this->getApiMock();
$api->expects($this->never())
->method('post');

$api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data);
}

/**
* @test
*/
public function shouldCreateCommitStatus()
{
$expectedValue = array('state' => 'success');
$data = array('state' => 'success');

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('repos/KnpLabs/php-github-api/statuses/commitSHA123456', $data)
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data));
}

protected function getApiClass()
{
return 'Github\Api\Repository\Statuses';
}
}