Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Enhancement: Show as many contributors as GitHub is willing to give us #458

Merged
merged 3 commits into from
Mar 4, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

class ContributorsController extends AbstractActionController
{
const LIST_LIMIT = 36;

/**
* @var RepositoryRetriever
*/
Expand All @@ -34,8 +32,7 @@ public function indexAction()
{
$contributors = $this->repositoryRetriever->getContributors(
$this->repositoryData['owner'],
$this->repositoryData['name'],
self::LIST_LIMIT
$this->repositoryData['name']
);

$metadata = $this->repositoryRetriever->getUserRepositoryMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ public function getUserRepositories($user, $params = [])
* @param string $repo
* @return array
*/
public function getContributors($owner, $repo, $limit = 20)
public function getContributors($owner, $repo)
{
try {
$contributors = $this->githubClient->api('repos')->contributors($owner, $repo);
$data = json_decode($contributors, true);
$data = array_reverse($data);

return array_slice($data, 0, $limit);
return array_reverse($data);
} catch (RuntimeException $e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,101 +318,6 @@ private function getClientMock(Api\AbstractApi $apiInstance, array $payload = []
return $client;
}

public function testGetContributorsHasDefaultLimitOf20()
{
$owner = 'foo';
$name = 'bar';

$limit = 20;

$repositoryApi = $this->getMockBuilder(Api\Repos::class)
->disableOriginalConstructor()
->getMock()
;

$response = json_encode($this->contributors(50));

$repositoryApi
->expects($this->once())
->method('contributors')
->with(
$this->equalTo($owner),
$this->equalTo($name)
)
->willReturn($response)
;

$client = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->getMock()
;

$client
->expects($this->once())
->method('api')
->with($this->equalTo('repos'))
->willReturn($repositoryApi)
;

$service = new RepositoryRetriever($client);

$contributors = $service->getContributors(
$owner,
$name
);

$this->assertInternalType('array', $contributors);
$this->assertCount($limit, $contributors);
}

public function testGetContributorsAcceptsLimit()
{
$owner = 'foo';
$name = 'bar';

$limit = 37;

$repositoryApi = $this->getMockBuilder(Api\Repos::class)
->disableOriginalConstructor()
->getMock()
;

$response = json_encode($this->contributors(50));

$repositoryApi
->expects($this->once())
->method('contributors')
->with(
$this->equalTo($owner),
$this->equalTo($name)
)
->willReturn($response)
;

$client = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->getMock()
;

$client
->expects($this->once())
->method('api')
->with($this->equalTo('repos'))
->willReturn($repositoryApi)
;

$service = new RepositoryRetriever($client);

$contributors = $service->getContributors(
$owner,
$name,
$limit
);

$this->assertInternalType('array', $contributors);
$this->assertCount($limit, $contributors);
}

public function testGetContributorsDecodesResponseToArray()
{
$owner = 'foo';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
We have <strong><?php echo $this->escapeHtml($this->metadata->forks_count); ?> forks</strong>,
<strong><?php echo $this->escapeHtml($this->metadata->stargazers_count); ?> stargazers</strong>,
<strong><?php echo $this->escapeHtml($this->metadata->watchers_count); ?> watchers</strong> and
<strong>awesome contributors</strong> who make this site better.
<strong><?php echo count($this->contributors); ?> awesome contributors</strong> who make this site better.
<a href="<?php echo $this->escapeHtmlAttr($this->gitHubRepositoryUrl()); ?>" target="_blank">Join us!</a>
</p>
<?php foreach ($this->contributors as $contributor): ?>
Expand Down