Skip to content
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

Branch lists . ( ? query per_page) #1020

Merged
merged 2 commits into from
Jul 13, 2021
Merged

Branch lists . ( ? query per_page) #1020

merged 2 commits into from
Jul 13, 2021

Conversation

pitonic
Copy link
Contributor

@pitonic pitonic commented Jul 12, 2021

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 ]);

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

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
Copy link
Contributor Author

pitonic commented Jul 13, 2021

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
Contributor

👎 This usage is incorrect. Use the ResultPager class.

@acrobat
Copy link
Collaborator

acrobat commented Jul 13, 2021

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
Copy link
Collaborator

acrobat commented Jul 13, 2021

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