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

Update list repositories methods in Teams and Apps API. #1067

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/Github/Api/Apps.php
Expand Up @@ -137,16 +137,16 @@ public function removeInstallation($installationId)
*
* @link https://developer.github.com/v3/apps/installations/#list-repositories
*
* @param int $userId
* @param array $params list of extra parameters.
*
* @return array
*/
public function listRepositories($userId = null)
public function listRepositories(array $params = [])
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can't remove/replace parameters as this would be a BC break. If the user parameter is not required anymore this should be deprecated so that we can remove it in the next major version

{
$parameters = [];
if ($userId) {
$parameters['user_id'] = $userId;
}
$parameters = array_merge([
'page' => 1,
'per_page' => 30,
], $params);
Comment on lines +146 to +149
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be needed as the ResultPager class should be used to loop over multiple pages of results


$this->configurePreviewHeader();

Expand Down
48 changes: 46 additions & 2 deletions lib/Github/Api/Organization/Teams.php
Expand Up @@ -95,16 +95,49 @@ public function removeMember($team, $username, $organization)
return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
}

public function repositories($team)
/**
* List a team's repositories.
*
* @link https://docs.github.com/en/rest/teams/teams#list-team-repositories
*
* @param string $team team ID or slug of the team name
* @param string $organization organization name
* @param array $params list of extra parameters.
*
* @return array
*/
public function repositories($team, $organization = '', $params = [])
{
return $this->get('/teams/'.rawurlencode($team).'/repos');
$parameters = array_merge([
'page' => 1,
'per_page' => 30,
], $params);
Comment on lines +111 to +114
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be needed as the ResultPager class should be used to loop over multiple pages of results


if (empty($organization)) {
// Legacy endpoint support
return $this->get('/teams/'.rawurlencode($team).'/repos', $parameters);
}

return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/repos', $parameters);
}

public function repository($team, $organization, $repository)
{
return $this->get('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository));
}

/**
* Add a repository to team or update team's permission on a repository.
*
* @link https://docs.github.com/en/rest/teams/teams#add-or-update-team-repository-permissions
*
* @param string $team the slug of the team name
* @param string $organization organization name
* @param string $repository repository name
* @param string $params list of extra parameters.
*
* @return array|string
*/
public function addRepository($team, $organization, $repository, $params = [])
{
if (isset($params['permission']) && !in_array($params['permission'], ['pull', 'push', 'admin', 'maintain', 'triage'])) {
Expand All @@ -114,6 +147,17 @@ public function addRepository($team, $organization, $repository, $params = [])
return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository), $params);
}

/**
* Remove a repository from a team.
*
* @link https://docs.github.com/en/rest/teams/teams#remove-a-repository-from-a-team
*
* @param string $team the slug of the team name
* @param string $organization organization name
* @param string $repository repository name.
*
* @return array|string
*/
public function removeRepository($team, $organization, $repository)
{
return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository));
Expand Down
4 changes: 2 additions & 2 deletions test/Github/Tests/Api/AppTest.php
Expand Up @@ -128,10 +128,10 @@ public function shouldGetRepositoriesFromInstallation()
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/installation/repositories', ['user_id' => '1234'])
->with('/installation/repositories', ['per_page' => '30', 'page' => 1])
->willReturn($result);

$this->assertEquals($result, $api->listRepositories('1234'));
$this->assertEquals($result, $api->listRepositories());
}

/**
Expand Down
20 changes: 18 additions & 2 deletions test/Github/Tests/Api/Organization/TeamsTest.php
Expand Up @@ -119,6 +119,22 @@ public function shouldRemoveTeamMembers()
$this->assertEquals($expectedValue, $api->removeMember('KnpWorld', 'l3l0', 'KnpLabs'));
}

/**
* @test
*/
public function shouldGetTeamRepositoriesLegacyEndPoint()
{
$expectedValue = [['name' => 'l3l0repo']];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/teams/1234/repos')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->repositories(1234));
}

/**
* @test
*/
Expand All @@ -129,10 +145,10 @@ public function shouldGetTeamRepositories()
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/teams/KnpWorld/repos')
->with('/orgs/KnpLabs/teams/KnpWorld/repos', ['per_page' => '30', 'page' => 1])
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->repositories('KnpWorld'));
$this->assertEquals($expectedValue, $api->repositories('KnpWorld', 'KnpLabs'));
}

/**
Expand Down