diff --git a/CHANGELOG.md b/CHANGELOG.md index a1a4c427fb8..dd8a5b3ff38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.9.0 + +### Added + +- API endpoint `Github\Api\Repo::transfer()` + ## 2.8.0 ### Added diff --git a/doc/repos.md b/doc/repos.md index 8835ccf87b2..d6abe19a0fe 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -329,3 +329,14 @@ $topics = $client->api('repo')->topics('ornicar', 'php-github-api'); ```php $currentTopics = $client->api('repo')->replaceTopics('ornicar', 'php-github-api', ['new', 'topics']); ``` + +### Transfer a repo to another user + +```php +$repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github'); +``` +You can optionally assign some teams by passing an array with their ID's if you're transferring the repo to an organization: + +```php +$repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github', [1234]); +``` diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index cc2bc109972..c0c54a95f15 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -659,4 +659,24 @@ public function replaceTopics($username, $repository, array $topics) return $this->put('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics', ['names' => $topics]); } + + /** + * Transfer a repository. + * + * @link https://developer.github.com/v3/repos/#transfer-a-repository + * + * @param string $username + * @param string $repository + * @param string $newOwner + * @param array $teamId + * + * @return array + */ + public function transfer($username, $repository, $newOwner, $teamId = []) + { + //This api is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.nightshade-preview+json'; + + return $this->post('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/transfer', ['new_owner' => $newOwner, 'team_id' => $teamId]); + } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 6fe7bd9d5f2..b82468e2731 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -585,6 +585,25 @@ public function shouldReplaceRepositoryTopics() $this->assertEquals($expectedArray, $api->replaceTopics('KnpLabs', 'php-github-api', ['octocat', 'atom', 'electron', 'API'])); } + /** + * @test + */ + public function shouldTransferRepository() + { + $expectedArray = ['id' => 1, 'name' => 'php-github-api']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/transfer', [ + 'new_owner' => 'github', + 'team_id' => [1234, 1235], + ]) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->transfer('KnpLabs', 'php-github-api', 'github', [1234, 1235])); + } + /** * @return string */