Skip to content

Branch lists . ( ? query per_page) - #1020

Merged
acrobat merged 2 commits into
KnpLabs:masterfrom
pitonic:patch-1
Jul 13, 2021
Merged

acrobat merged 2 commits into
KnpLabs:masterfrom
pitonic:patch-1

Conversation

@pitonic

@pitonic pitonic commented Jul 12, 2021 •

Copy link
Copy Markdown
Contributor

For function "branches" added: parameters for the query string.
example to use:

return $this->client->api('repo')->branches($this->id, $repo, null , [ 'page' =>2, 'per_page' => 100 ]);

pitonic added 2 commits July 12, 2021 10:23
For function "branches"  added: parameters for the query string.
example to use:
``` return $this->client->api('repo')->branches($this->id, $repo, null , [ 'page' =>2, 'per_page' => 100 ]);
@nicolai-petrov-venngage

Copy link
Copy Markdown

example:

<?php
require_once __DIR__ . '/vendor/autoload.php';

$id = "GoogleCloudPlatform";
$token = "topSecret";
$repo = "click-to-deploy";

$client = new \Github\Client();
// $client->authenticate($token, \Github\Client::AUTH_ACCESS_TOKEN);

// example: first page.
$result1 = $client->api('repo')->branches($id, $repo, null, [
    'per_page' => 100,
    'page' => 1 ] );
echo \count($result1) . " - branches found on the first page." .PHP_EOL;

// example: second page.
$result2 = $client->api('repo')->branches($id, $repo, null, [
    'per_page' => 100,
    'page' => 2 ] );
echo \count($result2) . " - branches found on the second page." .PHP_EOL;

Output:

→ php testBranchLists.php
100 - branches found on the first page.
22 - branches found on the second page.

@pitonic pitonic changed the title added: parameters for the query string Branch lists . ( ? query per_page) Jul 13, 2021
@pitonic

pitonic commented Jul 13, 2021

Copy link
Copy Markdown
Contributor Author

Documemtations:
https://docs.github.com/en/rest/reference/repos
#branches

protected | boolean | query |

 Setting to true returns only protected branches. When set to false, only unprotected branches are returned. Omitting this parameter returns all branches.

per_page | integer | query |

Results per page (max 100).Default: 30

page | integer | query |

Page number of the results to fetch.Default: 1

@GrahamCampbell

Copy link
Copy Markdown
Contributor

👎 This usage is incorrect. Use the ResultPager class.

@acrobat

acrobat commented Jul 13, 2021 •

Copy link
Copy Markdown
Collaborator

I'm going to merge this so we have support for the protected parameter. But as @GrahamCampbell indicates to paginate over the api results you should use the ResultPager class. This class has all the logic implemented to easily loop over all the results/pages and even fetch them lazy.

See: https://github.com/KnpLabs/php-github-api/blob/master/doc/result_pager.md

@acrobat
acrobat merged commit 2e58baa into KnpLabs:master Jul 13, 2021
@acrobat

acrobat commented Jul 13, 2021

Copy link
Copy Markdown
Collaborator

Thanks @pitonic! And congrats on your first contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants