Skip to content

Add sort and direction for fetching organizations repos #863

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

Merged
merged 4 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion lib/Github/Api/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ public function update($organization, array $params)
* @param string $organization the user name
* @param string $type the type of repositories
* @param int $page the page
* @param string $sort sort by
* @param string $direction direction of sort, asc or desc
*
* @return array the repositories
*/
public function repositories($organization, $type = 'all', $page = 1)
public function repositories($organization, $type = 'all', $page = 1, $sort = 'created', $direction = 'desc')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this so the default value is null. Then check if the parameter is different from null and then add it to a $parameters array and pass it to the request.

This way we always use the default value of github and it won't cause BC breaks when github decided to change this default value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I updated my PR. 😄

{
return $this->get('/orgs/'.rawurlencode($organization).'/repos', [
'type' => $type,
'page' => $page,
'sort' => $sort,
'direction' => $direction,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion test/Github/Tests/Api/OrganizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function shouldGetOrganizationRepositories()
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/orgs/KnpLabs/repos', ['type' => 'all', 'page' => 1])
->with('/orgs/KnpLabs/repos', ['type' => 'all', 'page' => 1, 'sort' => 'created', 'direction' => 'desc'])
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->repositories('KnpLabs'));
Expand Down