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

Commit 2e3a204

Browse files
committed
Merge pull request #458 from localheinz/feature/increase-limit
Enhancement: Show as many contributors as GitHub is willing to give us
2 parents eb60389 + 467bb35 commit 2e3a204

4 files changed

Lines changed: 4 additions & 103 deletions

File tree

module/Application/src/Application/Controller/ContributorsController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
class ContributorsController extends AbstractActionController
1010
{
11-
const LIST_LIMIT = 36;
12-
1311
/**
1412
* @var RepositoryRetriever
1513
*/
@@ -34,8 +32,7 @@ public function indexAction()
3432
{
3533
$contributors = $this->repositoryRetriever->getContributors(
3634
$this->repositoryData['owner'],
37-
$this->repositoryData['name'],
38-
self::LIST_LIMIT
35+
$this->repositoryData['name']
3936
);
4037

4138
$metadata = $this->repositoryRetriever->getUserRepositoryMetadata(

module/Application/src/Application/Service/RepositoryRetriever.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,13 @@ public function getUserRepositories($user, $params = [])
6060
* @param string $repo
6161
* @return array
6262
*/
63-
public function getContributors($owner, $repo, $limit = 20)
63+
public function getContributors($owner, $repo)
6464
{
6565
try {
6666
$contributors = $this->githubClient->api('repos')->contributors($owner, $repo);
6767
$data = json_decode($contributors, true);
68-
$data = array_reverse($data);
6968

70-
return array_slice($data, 0, $limit);
69+
return array_reverse($data);
7170
} catch (RuntimeException $e) {
7271
return false;
7372
}

module/Application/test/ApplicationTest/Service/RepositoryRetrieverTest.php

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -318,101 +318,6 @@ private function getClientMock(Api\AbstractApi $apiInstance, array $payload = []
318318
return $client;
319319
}
320320

321-
public function testGetContributorsHasDefaultLimitOf20()
322-
{
323-
$owner = 'foo';
324-
$name = 'bar';
325-
326-
$limit = 20;
327-
328-
$repositoryApi = $this->getMockBuilder(Api\Repos::class)
329-
->disableOriginalConstructor()
330-
->getMock()
331-
;
332-
333-
$response = json_encode($this->contributors(50));
334-
335-
$repositoryApi
336-
->expects($this->once())
337-
->method('contributors')
338-
->with(
339-
$this->equalTo($owner),
340-
$this->equalTo($name)
341-
)
342-
->willReturn($response)
343-
;
344-
345-
$client = $this->getMockBuilder(Client::class)
346-
->disableOriginalConstructor()
347-
->getMock()
348-
;
349-
350-
$client
351-
->expects($this->once())
352-
->method('api')
353-
->with($this->equalTo('repos'))
354-
->willReturn($repositoryApi)
355-
;
356-
357-
$service = new RepositoryRetriever($client);
358-
359-
$contributors = $service->getContributors(
360-
$owner,
361-
$name
362-
);
363-
364-
$this->assertInternalType('array', $contributors);
365-
$this->assertCount($limit, $contributors);
366-
}
367-
368-
public function testGetContributorsAcceptsLimit()
369-
{
370-
$owner = 'foo';
371-
$name = 'bar';
372-
373-
$limit = 37;
374-
375-
$repositoryApi = $this->getMockBuilder(Api\Repos::class)
376-
->disableOriginalConstructor()
377-
->getMock()
378-
;
379-
380-
$response = json_encode($this->contributors(50));
381-
382-
$repositoryApi
383-
->expects($this->once())
384-
->method('contributors')
385-
->with(
386-
$this->equalTo($owner),
387-
$this->equalTo($name)
388-
)
389-
->willReturn($response)
390-
;
391-
392-
$client = $this->getMockBuilder(Client::class)
393-
->disableOriginalConstructor()
394-
->getMock()
395-
;
396-
397-
$client
398-
->expects($this->once())
399-
->method('api')
400-
->with($this->equalTo('repos'))
401-
->willReturn($repositoryApi)
402-
;
403-
404-
$service = new RepositoryRetriever($client);
405-
406-
$contributors = $service->getContributors(
407-
$owner,
408-
$name,
409-
$limit
410-
);
411-
412-
$this->assertInternalType('array', $contributors);
413-
$this->assertCount($limit, $contributors);
414-
}
415-
416321
public function testGetContributorsDecodesResponseToArray()
417322
{
418323
$owner = 'foo';

module/Application/view/application/contributors/index.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
We have <strong><?php echo $this->escapeHtml($this->metadata->forks_count); ?> forks</strong>,
99
<strong><?php echo $this->escapeHtml($this->metadata->stargazers_count); ?> stargazers</strong>,
1010
<strong><?php echo $this->escapeHtml($this->metadata->watchers_count); ?> watchers</strong> and
11-
<strong>awesome contributors</strong> who make this site better.
11+
<strong><?php echo count($this->contributors); ?> awesome contributors</strong> who make this site better.
1212
<a href="<?php echo $this->escapeHtmlAttr($this->gitHubRepositoryUrl()); ?>" target="_blank">Join us!</a>
1313
</p>
1414
</div>

0 commit comments

Comments
 (0)