You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ResultPager fetchall on apps/installations incorrect result #597
FYI I'm using a CustomResultPager as a workaround for this problem.
<?php
namespace AppBundle\Github;
use Github\Api\ApiInterface;
use Github\Client;
use Github\ResultPager;
/**
* Workaround for:
*
* https://platform.github.community/t/pagination-differs-in-installations-api/1862
*/
class CustomResultPager extends ResultPager
{
private $key;
public function __construct(Client $client, string $key)
{
parent::__construct($client);
$this->key = $key;
}
public function fetchAll(ApiInterface $api, $method, array $parameters = array())
{
// get the perPage from the api
$perPage = $api->getPerPage();
// set parameters per_page to GitHub max to minimize number of requests
$api->setPerPage(100);
$result = $this->decode($this->callApi($api, $method, $parameters));
$this->postFetch();
while ($this->hasNext()) {
$next = $this->fetchNext();
$result = array_merge($result, $this->decode($next));
}
// restore the perPage
$api->setPerPage($perPage);
return $result;
}
protected function decode(array $result) {
if(! isset($result[$this->key])) {
throw new \Exception("No key $this->key, got: ".array_keys($result));
}
return $result[$this->key];
}
}
I see two solutions to address this issue here:
Include this class in php-github-api and document when to use it.
Modify the existing ResultPager to merge differently when the key totalCount is present. This would be transparent to the user but more hack-ish.
Activity
bdelbasso commentedon Jun 8, 2017
FYI I'm using a
CustomResultPageras a workaround for this problem.I see two solutions to address this issue here:
Include this class in php-github-api and document when to use it.
Modify the existing
ResultPagerto merge differently when the keytotalCountis present. This would be transparent to the user but more hack-ish.@acrobat @Nyholm What do you think?
Daniel15 commentedon Sep 3, 2017
My workaround is very similar to @bdelbasso's. I instead implemented it as a separate method:
I think it'd be good to include this functionality in the existing
ResultPager