Skip to content

Commit

Permalink
feature #1082 Feat: Support new Team Repositories Endpoint (iBotPeaches)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 3.9.x-dev branch.

Discussion
----------

* old - https://docs.github.com/en/rest/teams/teams#list-team-repositories-legacy
* new - https://docs.github.com/en/rest/teams/teams#list-team-repositories

Commits
-------

ca59785 refactor: support new team endpoint, fallback to legacy if no org
69e82d6 test: support new team endpoint, fallback to legacy if no org
  • Loading branch information
iBotPeaches authored Sep 12, 2022
1 parent e1c8cb9 commit 3467a34
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/Github/Api/Organization/Teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ public function removeMember($team, $username, $organization)
return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
}

public function repositories($team)
/**
* @link https://docs.github.com/en/rest/teams/teams#list-team-repositories
*/
public function repositories($team, $organization = '')
{
return $this->get('/teams/'.rawurlencode($team).'/repos');
if (empty($organization)) {
return $this->get('/teams/'.rawurlencode($team).'/repos');
}

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

public function repository($team, $organization, $repository)
Expand Down
16 changes: 16 additions & 0 deletions test/Github/Tests/Api/Organization/TeamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ public function shouldGetTeamRepositories()
{
$expectedValue = [['name' => 'l3l0repo']];

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

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

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

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
Expand Down

0 comments on commit 3467a34

Please sign in to comment.