diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index 62df3a3cf82..897cd584b56 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -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 = []) { - $parameters = []; - if ($userId) { - $parameters['user_id'] = $userId; - } + $parameters = array_merge([ + 'page' => 1, + 'per_page' => 30, + ], $params); $this->configurePreviewHeader(); diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 3af63b73679..adec54105cb 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -95,9 +95,30 @@ 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); + + 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) @@ -105,6 +126,18 @@ 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'])) { @@ -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)); diff --git a/test/Github/Tests/Api/AppTest.php b/test/Github/Tests/Api/AppTest.php index b813a11dd1f..65c073defbf 100644 --- a/test/Github/Tests/Api/AppTest.php +++ b/test/Github/Tests/Api/AppTest.php @@ -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()); } /** diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index 45c98cb9a1d..405d75c5c9f 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -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 */ @@ -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')); } /**