Skip to content

Commit 5046093

Browse files
m1guelpfacrobat
authored andcommitted
Add the repository transfer endpoint (KnpLabs#699)
* Add the repository transfer endpoint * cs * Add tests * cs * Fix tests * typo * Update changelog * Update documentation * CamelCase * Doc fix
1 parent 1e404bf commit 5046093

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
## 2.9.0
6+
7+
### Added
8+
9+
- API endpoint `Github\Api\Repo::transfer()`
10+
511
## 2.8.0
612

713
### Added

doc/repos.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,14 @@ $topics = $client->api('repo')->topics('ornicar', 'php-github-api');
329329
```php
330330
$currentTopics = $client->api('repo')->replaceTopics('ornicar', 'php-github-api', ['new', 'topics']);
331331
```
332+
333+
### Transfer a repo to another user
334+
335+
```php
336+
$repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github');
337+
```
338+
You can optionally assign some teams by passing an array with their ID's if you're transferring the repo to an organization:
339+
340+
```php
341+
$repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github', [1234]);
342+
```

lib/Github/Api/Repo.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,24 @@ public function replaceTopics($username, $repository, array $topics)
659659

660660
return $this->put('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics', ['names' => $topics]);
661661
}
662+
663+
/**
664+
* Transfer a repository.
665+
*
666+
* @link https://developer.github.com/v3/repos/#transfer-a-repository
667+
*
668+
* @param string $username
669+
* @param string $repository
670+
* @param string $newOwner
671+
* @param array $teamId
672+
*
673+
* @return array
674+
*/
675+
public function transfer($username, $repository, $newOwner, $teamId = [])
676+
{
677+
//This api is in preview mode, so set the correct accept-header
678+
$this->acceptHeaderValue = 'application/vnd.github.nightshade-preview+json';
679+
680+
return $this->post('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/transfer', ['new_owner' => $newOwner, 'team_id' => $teamId]);
681+
}
662682
}

test/Github/Tests/Api/RepoTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,25 @@ public function shouldReplaceRepositoryTopics()
585585
$this->assertEquals($expectedArray, $api->replaceTopics('KnpLabs', 'php-github-api', ['octocat', 'atom', 'electron', 'API']));
586586
}
587587

588+
/**
589+
* @test
590+
*/
591+
public function shouldTransferRepository()
592+
{
593+
$expectedArray = ['id' => 1, 'name' => 'php-github-api'];
594+
595+
$api = $this->getApiMock();
596+
$api->expects($this->once())
597+
->method('post')
598+
->with('/repos/KnpLabs/php-github-api/transfer', [
599+
'new_owner' => 'github',
600+
'team_id' => [1234, 1235],
601+
])
602+
->will($this->returnValue($expectedArray));
603+
604+
$this->assertEquals($expectedArray, $api->transfer('KnpLabs', 'php-github-api', 'github', [1234, 1235]));
605+
}
606+
588607
/**
589608
* @return string
590609
*/

0 commit comments

Comments
 (0)