-
-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #1115 feat: User Migration (haridarshan)
This PR was squashed before being merged into the 3.12-dev branch. Discussion ---------- Feature: - User Migrations Doc: - User Migrations doc Closes #795 Commits ------- 3948174 feat: Add User Migrations Api fc5a76c docs: Add migration list example with `ResultPager` and remove `per_page` 5389602 perf: remove `$params['repositories']` validation check 1bec9eb test: remove `shouldNotStartMigration` test-case 69fc864 chore(styleci): apply styleci patch
- Loading branch information
1 parent
90360bc
commit 67398b0
Showing
5 changed files
with
359 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
## User / Migrations API | ||
[Back to the "Users API"](../../users.md) | [Back to the navigation](../../README.md) | ||
|
||
# List user migrations | ||
|
||
https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#list-user-migrations | ||
|
||
```php | ||
$api = $github->api('user')->migration(); | ||
$paginator = new Github\ResultPager($github); | ||
$parameters = []; | ||
$migrations = $paginator->fetchAll($api, 'list', $parameters); | ||
|
||
do { | ||
foreach ($migrations as $migration) { | ||
// do something | ||
} | ||
$migrations = $paginator->fetchNext(); | ||
} | ||
while($paginator->hasNext()); | ||
``` | ||
|
||
# Start a User Migration | ||
|
||
https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#start-a-user-migration | ||
|
||
```php | ||
$client->users()->migration()->start([ | ||
'repositories' => [ | ||
'KnpLabs/php-github-api' | ||
], | ||
'lock_repositories' => true, | ||
'exclude_metadata' => false, | ||
'exclude_git_data' => false, | ||
'exclude_attachments' => true, | ||
'exclude_releases' => false, | ||
'exclude_owner_projects' => true, | ||
'org_metadata_only' => false, | ||
'exclude' => [ | ||
'Exclude attributes from the API response to improve performance' | ||
] | ||
]); | ||
``` | ||
|
||
# Get a User Migration Status | ||
|
||
https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#get-a-user-migration-status | ||
|
||
```php | ||
$status = $client->user()->migration()->status(12, [ | ||
'exclude' => [ | ||
'exclude attributes' | ||
] | ||
]); | ||
``` | ||
|
||
# Delete a User Migration Archive | ||
|
||
https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#delete-a-user-migration-archive | ||
|
||
```php | ||
$client->user()->migration()->deleteArchive(12); | ||
``` | ||
|
||
# Unlock a User Repository | ||
|
||
https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#unlock-a-user-repository | ||
|
||
```php | ||
$client->user()->migration()->unlockRepo(12, 'php-github-api'); | ||
``` | ||
|
||
# List repositories for a User Migration | ||
|
||
https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#list-repositories-for-a-user-migration | ||
|
||
```php | ||
$repos = $client->user()->migration()->repos(2); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Github\Api\User; | ||
|
||
use Github\Api\AbstractApi; | ||
|
||
class Migration extends AbstractApi | ||
{ | ||
/** | ||
* @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#list-user-migrations | ||
* | ||
* @param array $params | ||
* | ||
* @return array|string | ||
*/ | ||
public function list(array $params = []) | ||
{ | ||
return $this->get('/user/migrations', $params); | ||
} | ||
|
||
/** | ||
* @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#start-a-user-migration | ||
* | ||
* @param array $params | ||
* | ||
* @return array|string | ||
*/ | ||
public function start(array $params) | ||
{ | ||
return $this->post('/user/migrations', $params); | ||
} | ||
|
||
/** | ||
* @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#get-a-user-migration-status | ||
* | ||
* @param int $migrationId | ||
* @param array $params | ||
* | ||
* @return array|string | ||
*/ | ||
public function status(int $migrationId, array $params = []) | ||
{ | ||
return $this->get('/user/migrations/'.$migrationId, $params); | ||
} | ||
|
||
/** | ||
* @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#delete-a-user-migration-archive | ||
* | ||
* @param int $migrationId | ||
* | ||
* @return array|string | ||
*/ | ||
public function deleteArchive(int $migrationId) | ||
{ | ||
return $this->delete('/user/migrations/'.$migrationId.'/archive'); | ||
} | ||
|
||
/** | ||
* @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#unlock-a-user-repository | ||
* | ||
* @param int $migrationId | ||
* @param string $repository | ||
* | ||
* @return array|string | ||
*/ | ||
public function unlockRepo(int $migrationId, string $repository) | ||
{ | ||
return $this->delete('/user/migrations/'.$migrationId.'/repos/'.rawurlencode($repository).'/lock'); | ||
} | ||
|
||
/** | ||
* @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#list-repositories-for-a-user-migration | ||
* | ||
* @param int $migrationId | ||
* @param array $params | ||
* | ||
* @return array|string | ||
*/ | ||
public function repos(int $migrationId, array $params = []) | ||
{ | ||
return $this->get('/user/migrations/'.$migrationId.'/repositories', $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api\User; | ||
|
||
use Github\Api\User\Migration; | ||
use Github\Tests\Api\TestCase; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
|
||
class MigrationTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldListUserMigrations() | ||
{ | ||
$expectedArray = [ | ||
[ | ||
'id' => 79, | ||
'state' => 'pending', | ||
'lock_repositories' => true, | ||
'repositories' => [ | ||
[ | ||
'id' => 1296269, | ||
'name' => 'Hello-World', | ||
'full_name' => 'octocat/Hello-World', | ||
], | ||
], | ||
], | ||
[ | ||
'id' => 2, | ||
'name' => 'pending', | ||
'lock_repositories' => false, | ||
'repositories' => [ | ||
[ | ||
'id' => 123, | ||
'name' => 'php-github-api', | ||
'full_name' => 'KnpLabs/php-github-api', | ||
], | ||
], | ||
], | ||
]; | ||
|
||
/** @var Migration|MockObject $api */ | ||
$api = $this->getApiMock(); | ||
|
||
$api | ||
->expects($this->once()) | ||
->method('get') | ||
->with('/user/migrations') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->list()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldStartMigration() | ||
{ | ||
$expectedArray = [ | ||
'id' => 79, | ||
'state' => 'pending', | ||
'lock_repositories' => true, | ||
'repositories' => [ | ||
[ | ||
'id' => 1296269, | ||
'name' => 'Hello-World', | ||
'full_name' => 'octocat/Hello-World', | ||
], | ||
], | ||
]; | ||
|
||
/** @var Migration|MockObject $api */ | ||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('post') | ||
->with('/user/migrations') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->start([ | ||
'lock_repositories' => true, | ||
'repositories' => [ | ||
'KnpLabs/php-github-api', | ||
], | ||
])); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldGetMigrationStatus() | ||
{ | ||
$expectedArray = [ | ||
'id' => 79, | ||
'state' => 'exported', | ||
'lock_repositories' => true, | ||
'repositories' => [ | ||
[ | ||
'id' => 1296269, | ||
'name' => 'Hello-World', | ||
'full_name' => 'octocat/Hello-World', | ||
], | ||
], | ||
]; | ||
|
||
/** @var Migration|MockObject $api */ | ||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/user/migrations/79') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->status(79)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldDeleteMigrationArchive() | ||
{ | ||
/** @var Migration|MockObject $api */ | ||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('delete') | ||
->with('/user/migrations/79/archive') | ||
->will($this->returnValue(204)); | ||
|
||
$this->assertEquals(204, $api->deleteArchive(79)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldUnlockUserRepo() | ||
{ | ||
/** @var Migration|MockObject $api */ | ||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('delete') | ||
->with('/user/migrations/79/repos/php-github-api/lock') | ||
->will($this->returnValue(204)); | ||
|
||
$this->assertEquals(204, $api->unlockRepo(79, 'php-github-api')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldListRepos() | ||
{ | ||
$expectedArray = [ | ||
[ | ||
'id' => 1296269, | ||
'name' => 'Hello-World', | ||
'full_name' => 'test/Hello-World', | ||
], | ||
[ | ||
'id' => 234324, | ||
'name' => 'Hello-World2', | ||
'full_name' => 'test/Hello-World2', | ||
], | ||
]; | ||
|
||
/** @var Migration|MockObject $api */ | ||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/user/migrations/79/repositories') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->repos(79)); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getApiClass() | ||
{ | ||
return \Github\Api\User\Migration::class; | ||
} | ||
} |