diff --git a/README.md b/README.md index 465c9b88..26a24f1b 100644 --- a/README.md +++ b/README.md @@ -204,16 +204,6 @@ $subscription = $github->activity->watching->setSubscription(':owner', ':repo', // Delete a Repository Subscription. $github->activity->watching->deleteSubscription(':owner', ':repo'); - -// Check if you are watching a repository (LEGACY). -// @return boolean True for a 204 response, False for a 404. -$github->activity->watching->check(':owner', ':repo'); - -// Watch a repository (LEGACY). -$github->activity->watching->watch(':owner', ':repo'); - -// Stop watching a repository (LEGACY). -$github->activity->watching->unwatch(':owner', ':repo'); ``` ### Gists @@ -629,44 +619,11 @@ See http://developer.github.com/v3/orgs/teams/. // List teams $teams = $github->orgs->teams->getList(':org'); -// Get team -$team = $github->orgs->teams->get(':teamId'); - // Create team $repos = array(':repoName'); $permission = 'pull|push|admin'; $github->orgs->teams->create(':org', ':name', $repos, $permission); -// Edit team -$github->orgs->teams->edit(':teamId', ':name', $permission); - -// Delete team -$github->orgs->teams->delete(':teamId'); - -// List team members -$members = $github->orgs->teams->getListMembers(':teamId'); - -// Get team member -$isUserMember = $github->orgs->teams->isMember(':teamId', ':user'); - -// Add team member -$github->orgs->teams->addMember(':teamId', ':user'); - -// Remove team member -$github->orgs->teams->removeMember(':teamId', ':user'); - -// List team repos -$repos = $github->orgs->teams->getListRepos(':teamId'); - -// Get team repo -$isRepoManagedByTeam = $github->orgs->teams->checkRepo(':teamId', ':repo'); - -// Add team repo -$github->orgs->teams->addRepo(':teamId', ':org', ':repo'); - -// Remove team repo -$github->orgs->teams->removeRepo(':teamId', ':owner', ':repo'); - // List user teams - TODO ``` diff --git a/Tests/Package/Activity/WatchingTest.php b/Tests/Package/Activity/WatchingTest.php index d7ce4b73..8acf26a6 100644 --- a/Tests/Package/Activity/WatchingTest.php +++ b/Tests/Package/Activity/WatchingTest.php @@ -159,107 +159,4 @@ public function testDeleteSubscription() $this->object->deleteSubscription('joomla', 'joomla-platform') ); } - - /** - * Tests the check method - * - * @return void - */ - public function testCheck() - { - $this->response = $this->getResponseObject('', 204); - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions/joomla/joomla-platform', [], 0) - ->willReturn($this->response); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(true) - ); - } - - /** - * Tests the checkFalse method - * - * @return void - */ - public function testCheckFalse() - { - $this->response = $this->getResponseObject('', 404); - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions/joomla/joomla-platform', [], 0) - ->willReturn($this->response); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(false) - ); - } - - /** - * Tests the checkUnexpected method - * - * @return void - */ - public function testCheckUnexpected() - { - $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - - $this->response = $this->getResponseObject(false, 666); - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions/joomla/joomla-platform', [], 0) - ->willReturn($this->response); - - $this->object->check('joomla', 'joomla-platform'); - } - - /** - * Tests the watch method - * - * @return void - */ - public function testWatch() - { - $this->response = $this->getResponseObject('', 204); - - $this->client->expects($this->once()) - ->method('put') - ->with('/user/subscriptions/joomla/joomla-platform', '', [], 0) - ->willReturn($this->response); - - $response = (string) $this->response->getBody(); - - $this->assertEquals( - $response, - $this->object->watch('joomla', 'joomla-platform') - ); - } - - /** - * Tests the unwatch method - * - * @return void - */ - public function testUnwatch() - { - $this->response = $this->getResponseObject('', 204); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/user/subscriptions/joomla/joomla-platform', [], 0) - ->willReturn($this->response); - - $response = (string) $this->response->getBody(); - - $this->assertEquals( - $response, - $this->object->unwatch('joomla', 'joomla-platform') - ); - } } diff --git a/Tests/Package/AuthorizationsTest.php b/Tests/Package/AuthorizationsTest.php index f5746fc5..a285ad51 100644 --- a/Tests/Package/AuthorizationsTest.php +++ b/Tests/Package/AuthorizationsTest.php @@ -37,474 +37,6 @@ protected function setUp(): void $this->object = new Authorization($this->options, $this->client); } - /** - * Tests the createAuthorisation method - * - * @return void - * - * @since 1.0 - */ - public function testCreate() - { - $this->response = $this->getResponseObject($this->sampleString, 201); - - $authorisation = '{' - . '"scopes":["public_repo"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/authorizations', $authorisation) - ->willReturn($this->response); - - $this->assertThat( - $this->object->create(['public_repo'], 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the createAuthorisation method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testCreateFailure() - { - $exception = false; - - $this->response = $this->getResponseObject($this->errorString, 500); - - $authorisation = '{' - . '"scopes":["public_repo"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/authorizations', $authorisation) - ->willReturn($this->response); - - try { - $this->object->create(['public_repo'], 'My test app', 'http://www.joomla.org'); - } catch (\DomainException $e) { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the delete method - * - * @return void - * - * @since 1.0 - */ - public function testDelete() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/42') - ->willReturn($this->response); - - $this->assertThat( - $this->object->delete(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the delete method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testDeleteFailure() - { - $exception = false; - - $this->response = $this->getResponseObject($this->errorString, 500); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/42') - ->willReturn($this->response); - - try { - $this->object->delete(42); - } catch (\DomainException $e) { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the deleteGrant method - * - * @return void - * - * @since 1.0 - */ - public function testDeleteGrant() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/grants/42') - ->willReturn($this->response); - - $this->assertThat( - $this->object->deleteGrant(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the deleteGrant method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testDeleteGrantFailure() - { - $exception = false; - - $this->response = $this->getResponseObject($this->errorString, 500); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/grants/42') - ->willReturn($this->response); - - try { - $this->object->deleteGrant(42); - } catch (\DomainException $e) { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the editAuthorisation method - Add scopes - * - * @return void - * - * @since 1.0 - */ - public function testEditAddScopes() - { - $authorisation = '{' - . '"add_scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->willReturn($this->response); - - $this->assertThat( - $this->object->edit(42, [], ['public_repo', 'gist'], [], 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editAuthorisation method - Remove scopes - * - * @return void - * - * @since 1.0 - */ - public function testEditRemoveScopes() - { - $authorisation = '{' - . '"remove_scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->willReturn($this->response); - - $this->assertThat( - $this->object->edit(42, [], [], ['public_repo', 'gist'], 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editAuthorisation method - Scopes param - * - * @return void - * - * @since 1.0 - */ - public function testEditScopes() - { - $authorisation = '{' - . '"scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->willReturn($this->response); - - $this->assertThat( - $this->object->edit(42, ['public_repo', 'gist'], [], [], 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editAuthorisation method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testEditFailure() - { - $exception = false; - - $this->response = $this->getResponseObject($this->errorString, 500); - - $authorisation = '{' - . '"add_scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->willReturn($this->response); - - try { - $this->object->edit(42, [], ['public_repo', 'gist'], [], 'My test app', 'http://www.joomla.org'); - } catch (\DomainException $e) { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the editAuthorisation method - too many scope params - * - * @return void - * - * @since 1.0 - */ - public function testEditTooManyScopes() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit(42, [], ['public_repo', 'gist'], ['public_repo', 'gist'], 'My test app', 'http://www.joomla.org'); - } - - /** - * Tests the get method - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/42') - ->willReturn($this->response); - - $this->assertThat( - $this->object->get(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response = $this->getResponseObject($this->errorString, 500); - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/42') - ->willReturn($this->response); - - $this->object->get(42); - } - - /** - * Tests the getGrant method - * - * @return void - * - * @since 1.0 - */ - public function testGetGrant() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants/42') - ->willReturn($this->response); - - $this->assertThat( - $this->object->getGrant(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getGrant method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetGrantFailure() - { - $this->expectException(\DomainException::class); - - $this->response = $this->getResponseObject($this->errorString, 500); - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants/42') - ->willReturn($this->response); - - $this->object->getGrant(42); - } - - /** - * Tests the getList method - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations') - ->willReturn($this->response); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response = $this->getResponseObject($this->errorString, 500); - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations') - ->willReturn($this->response); - - $this->object->getList(); - } - - /** - * Tests the getListGrants method - * - * @return void - * - * @since 1.0 - */ - public function testGetListGrants() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants') - ->willReturn($this->response); - - $this->assertThat( - $this->object->getListGrants(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getListGrants method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetListGrantsFailure() - { - $this->expectException(\DomainException::class); - - $this->response = $this->getResponseObject($this->errorString, 500); - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants') - ->willReturn($this->response); - - $this->object->getListGrants(); - } - /** * Tests the getRateLimit method * @@ -662,47 +194,4 @@ public function testRequestTokenInvalidFormat() $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'invalid'); } - - /** - * Tests the revokeGrantForApplication method - * - * @return void - * - * @since 1.0 - */ - public function testRevokeGrantForApplication() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/applications/42/grants/1a2b3c') - ->willReturn($this->response); - - $this->assertThat( - $this->object->revokeGrantForApplication(42, '1a2b3c'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the revokeGrantForApplication method - failure - * - * @return void - * - * @since 1.0 - */ - public function testRevokeGrantForApplicationFailure() - { - $this->expectException(\DomainException::class); - - $this->response = $this->getResponseObject($this->errorString, 500); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/applications/42/grants/1a2b3c') - ->willReturn($this->response); - - $this->object->revokeGrantForApplication(42, '1a2b3c'); - } } diff --git a/Tests/Package/Orgs/HooksTest.php b/Tests/Package/Orgs/HooksTest.php index 57a2b3a2..ab3aadbb 100644 --- a/Tests/Package/Orgs/HooksTest.php +++ b/Tests/Package/Orgs/HooksTest.php @@ -131,56 +131,6 @@ public function testCreateInvalidEvent() $this->object->create('{org}', '{url}', 'form', null, false, ['{invalid}']); } - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::edit() - * - * @return void - */ - public function testEdit() - { - $this->response = $this->getResponseObject($this->sampleString, 201); - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/{org}/hooks') - ->willReturn($this->response); - - $this->assertThat( - $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, ['create'], true), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::edit() - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->edit('{org}', '{url}', '{invalid}'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::edit() - * - * @return void - */ - public function testEditFailure2() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, ['{invalid}']); - } - /** * Test method. * diff --git a/Tests/Package/Orgs/TeamsTest.php b/Tests/Package/Orgs/TeamsTest.php index a95123e8..b445d0d1 100644 --- a/Tests/Package/Orgs/TeamsTest.php +++ b/Tests/Package/Orgs/TeamsTest.php @@ -59,26 +59,6 @@ public function testGetList() ); } - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123') - ->willReturn($this->response); - - $this->assertThat( - $this->object->get(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - /** * Test method. * @@ -117,469 +97,6 @@ public function testCreateWrongPermission() $this->object->create('joomla', 'TheTeam', ['joomla-platform'], 'invalid'); } - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::edit() - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/teams/123') - ->willReturn($this->response); - - $this->assertThat( - $this->object->edit(123, 'TheTeam', 'admin'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::edit() - * - * @return void - */ - public function testEditWrongPermission() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->edit(123, 'TheTeam', 'invalid'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::delete() - * - * @return void - */ - public function testDelete() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123') - ->willReturn($this->response); - - $this->assertThat( - $this->object->delete(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getListMembers() - * - * @return void - */ - public function testGetListMembers() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members') - ->willReturn($this->response); - - $this->assertThat( - $this->object->getListMembers(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::isMember() - * - * @deprecated - * - * @return void - */ - public function testIsMember() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members/elkuku') - ->willReturn($this->response); - - $this->assertThat( - $this->object->isMember(123, 'elkuku'), - $this->equalTo(json_decode(true)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::isMember() - * - * @deprecated - * - * @return void - */ - public function testIsMemberNo() - { - $this->response = $this->getResponseObject($this->sampleString, 404); - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members/elkuku') - ->willReturn($this->response); - - $this->assertThat( - $this->object->isMember(123, 'elkuku'), - $this->equalTo(json_decode(false)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::isMember() - * - * @deprecated - * - * @return void - */ - public function testIsMemberUnexpected() - { - $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - - $this->response = $this->getResponseObject($this->sampleString, 666); - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members/elkuku') - ->willReturn($this->response); - - $this->assertThat( - $this->object->isMember(123, 'elkuku'), - $this->equalTo(json_decode(true)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addMember() - * - * @deprecated - * - * @return void - */ - public function testAddMember() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('put') - ->with('/teams/123/members/elkuku') - ->willReturn($this->response); - - $this->assertThat( - $this->object->addMember(123, 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::removeMember() - * - * @deprecated - * - * @return void - */ - public function testRemoveMember() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123/members/elkuku') - ->willReturn($this->response); - - $this->assertThat( - $this->object->removeMember(123, 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getListRepos() - * - * @return void - */ - public function testGetListRepos() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos') - ->willReturn($this->response); - - $this->assertThat( - $this->object->getListRepos(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() - * - * @return void - */ - public function testCheckRepo() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos/joomla/cms') - ->willReturn($this->response); - - $this->assertThat( - $this->object->checkRepo(123, 'joomla', 'cms'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() - * - * @return void - */ - public function testCheckRepoNo() - { - $this->response = $this->getResponseObject($this->sampleString, 404); - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos/joomla/cms') - ->willReturn($this->response); - - $this->assertThat( - $this->object->checkRepo(123, 'joomla', 'cms'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() - * - * @return void - */ - public function testCheckRepoUnexpected() - { - $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - - $this->response = $this->getResponseObject($this->sampleString, 666); - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos/joomla/cms') - ->willReturn($this->response); - - $this->assertThat( - $this->object->checkRepo(123, 'joomla', 'cms'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addRepo() - * - * @return void - */ - public function testAddRepo() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('put') - ->with('/teams/123/repos/joomla/joomla-platform') - ->willReturn($this->response); - - $this->assertThat( - $this->object->addRepo(123, 'joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::removeRepo() - * - * @return void - */ - public function testRemoveRepo() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123/repos/joomla/joomla-platform') - ->willReturn($this->response); - - $this->assertThat( - $this->object->removeRepo(123, 'joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() - * - * @return void - */ - public function testGetTeamMemberships() - { - $body = '{"state":"TEST"}'; - $this->response = $this->getResponseObject($body); - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/memberships/{user}') - ->willReturn($this->response); - - $this->assertThat( - $this->object->getTeamMembership(123, '{user}'), - $this->equalTo('TEST') - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() - * - * Response if user is not a member - * - * @return void - */ - public function testGetTeamMembershipsFailure1() - { - $body = '{"state":"TEST"}'; - $this->response = $this->getResponseObject($body, 404); - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/memberships/{user}') - ->willReturn($this->response); - - $this->assertThat( - $this->object->getTeamMembership(123, '{user}'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() - * - * Unexpected Response - * - * @return void - */ - public function testGetTeamMembershipsFailure2() - { - $this->expectException(\Laminas\Diactoros\Exception\InvalidArgumentException::class); - - $this->response = $this->getResponseObject('{"state":"TEST"}', 666); - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/memberships/{user}') - ->willReturn($this->response); - - $this->assertThat( - $this->object->getTeamMembership(123, '{user}'), - $this->equalTo('TEST') - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() - * - * @return void - */ - public function testAddTeamMemberships() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/teams/123/memberships/{user}') - ->willReturn($this->response); - - $this->assertThat( - $this->object->addTeamMembership(123, '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() - * - * Invalid role - * - * @return void - */ - public function testAddTeamMembershipsFailure() - { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Roles must be either "member" or "maintainer".'); - - $this->object->addTeamMembership(123, '{user}', 'INVALID'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::removeTeamMembership() - * - * @return void - */ - public function testRemoveTeamMemberships() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123/memberships/{user}') - ->willReturn($this->response); - - $this->assertThat( - $this->object->removeTeamMembership(123, '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - /** * Test method. * diff --git a/Tests/Package/Repositories/DownloadsTest.php b/Tests/Package/Repositories/DownloadsTest.php deleted file mode 100644 index 189a7c5d..00000000 --- a/Tests/Package/Repositories/DownloadsTest.php +++ /dev/null @@ -1,134 +0,0 @@ -object = new Downloads($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/downloads') - ->willReturn($this->response); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/downloads/123abc') - ->willReturn($this->response); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); - - $this->object->create('joomla', 'joomla-platform', 'aaa.zip', 1234, 'Description', 'content_type'); - } - - /** - * Tests the Upload method. - * - * @return void - */ - public function testUpload() - { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); - - $this->object->upload( - 'joomla', - 'joomla-platform', - 123, - 'a/b/aaa.zip', - 'acl', - 201, - 'aaa.zip', - '123abc', - '123abc', - '123abc', - 'content_type', - '@aaa.zip' - ); - } - - /** - * Tests the Delete method. - * - * @return void - */ - public function testDelete() - { - $this->response = $this->getResponseObject($this->sampleString, 204); - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/downloads/123') - ->willReturn($this->response); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } -} diff --git a/Tests/Package/SearchTest.php b/Tests/Package/SearchTest.php index 7f1e636f..fb1fd65c 100644 --- a/Tests/Package/SearchTest.php +++ b/Tests/Package/SearchTest.php @@ -37,86 +37,14 @@ protected function setUp(): void } /** - * Tests the issues method + * Tests that the methods for the removed legacy search API are gone * * @return void */ - public function testIssues() + public function testLegacyMethodsAreRemoved() { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/issues/search/joomla/joomla-platform/open/github') - ->willReturn($this->response); - - $this->assertEquals( - json_decode($this->sampleString), - $this->object->issues('joomla', 'joomla-platform', 'open', 'github') - ); - } - - /** - * Tests the issuesInvalidState method - * - * @return void - */ - public function testIssuesInvalidState() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->issues('joomla', 'joomla-platform', 'invalid', 'github'); - } - - /** - * Tests the repositories method - * - * @return void - */ - public function testRepositories() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/repos/search/joomla') - ->willReturn($this->response); - - $this->assertThat( - $this->object->repositories('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the users method - * - * @return void - */ - public function testUsers() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/user/search/joomla') - ->willReturn($this->response); - - $this->assertThat( - $this->object->users('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the email method - * - * @return void - */ - public function testEmail() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/user/email/email@joomla') - ->willReturn($this->response); - - $this->assertThat( - $this->object->email('email@joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); + foreach (['issues', 'repositories', 'users', 'email'] as $method) { + $this->assertFalse(method_exists($this->object, $method), $method); + } } } diff --git a/Tests/Package/Users/KeysTest.php b/Tests/Package/Users/KeysTest.php index 5edc5c0e..983de14f 100644 --- a/Tests/Package/Users/KeysTest.php +++ b/Tests/Package/Users/KeysTest.php @@ -110,24 +110,6 @@ public function testCreate() ); } - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/users/keys/1') - ->willReturn($this->response); - - $this->assertThat( - $this->object->edit(1, 'email@example.com', '12345'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - /** * Tests the delete method * diff --git a/docs/index.md b/docs/index.md index 8ca42a4a..6afad0fc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,3 +1,4 @@ * [Overview](overview.md) * [Updating from v2 to v3](v2-to-v3-update.md) * [Updating from v3 to v4](v3-to-v4-update.md) +* [Updating from v4 to v5](v4-to-v5-update.md) diff --git a/docs/v4-to-v5-update.md b/docs/v4-to-v5-update.md new file mode 100644 index 00000000..42a14acd --- /dev/null +++ b/docs/v4-to-v5-update.md @@ -0,0 +1,22 @@ +## Updating from v4 to v5 + +The following changes were made to the Github API package between v4 and v5. + +### Wrappers for removed GitHub endpoints removed + +The following methods and classes wrapped endpoints that GitHub has removed or replaced, so they could not work +against the live API. They were deprecated in 4.x and are removed. + +| Removed | Use instead | +|---|---| +| `Package\Authorization::create()`, `delete()`, `deleteGrant()`, `edit()`, `get()`, `getGrant()`, `getList()`, `getListGrants()` (OAuth Authorizations API) | A personal access token or GitHub App token in the `gh.token` option | +| `Package\Authorization::revokeGrantForApplication()` | `DELETE /applications/{client_id}/grant` | +| `Package\Repositories\Downloads` and `$github->repositories->downloads` | `Package\Repositories\Releases` and its assets | +| `Package\Search::issues()`, `repositories()`, `users()`, `email()` (legacy search API) | `Package\Search::getIssues()`, `getRepositories()`, `getUsers()`; there is no email search | +| `Package\Activity\Watching::check()`, `watch()`, `unwatch()` | `getSubscription()`, `setSubscription()`, `deleteSubscription()` | +| `Package\Orgs\Teams::get()`, `edit()`, `delete()`, `getListMembers()`, `getListRepos()`, `checkRepo()`, `addRepo()`, `removeRepo()` (`/teams/{team_id}` routes) | The `…BySlug()` methods, e.g. `getBySlug($org, $slug)` | +| `Package\Orgs\Teams::isMember()`, `addMember()`, `removeMember()`, `getTeamMembership()`, `addTeamMembership()`, `removeTeamMembership()` | `getMembershipBySlug()`, `addMembershipBySlug()`, `removeMembershipBySlug()` | +| `Package\Orgs\Hooks::edit()` (created a new hook) | `Package\Orgs\Hooks::editHook($org, $id, ...)` | +| `Package\Users\Keys::edit()` (GitHub has no endpoint to update a key) | Delete the key and create a new one | + +`Authorization::getRateLimit()`, `getAuthorizationLink()` and `requestToken()` are kept. diff --git a/src/Package/Activity/Watching.php b/src/Package/Activity/Watching.php index acf4c745..1979a860 100644 --- a/src/Package/Activity/Watching.php +++ b/src/Package/Activity/Watching.php @@ -130,83 +130,4 @@ public function deleteSubscription($owner, $repo) 204 ); } - - /** - * Check if you are watching a repository (LEGACY). - * - * Requires for the user to be authenticated. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return boolean - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function check($owner, $repo) - { - // Build the request path. - $path = '/user/subscriptions/' . $owner . '/' . $repo; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->getStatusCode()) { - case '204': - // This repository is watched by you. - return true; - - case '404': - // This repository is not watched by you. - return false; - } - - throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode()); - } - - /** - * Watch a repository (LEGACY). - * - * Requires for the user to be authenticated. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function watch($owner, $repo) - { - // Build the request path. - $path = '/user/subscriptions/' . $owner . '/' . $repo; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), ''), - 204 - ); - } - - /** - * Stop watching a repository (LEGACY). - * - * Requires for the user to be authenticated. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function unwatch($owner, $repo) - { - // Build the request path. - $path = '/user/subscriptions/' . $owner . '/' . $repo; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } } diff --git a/src/Package/Authorization.php b/src/Package/Authorization.php index bf3317e4..0f9cd209 100644 --- a/src/Package/Authorization.php +++ b/src/Package/Authorization.php @@ -24,206 +24,6 @@ */ class Authorization extends AbstractPackage { - /** - * Method to create an authorization. - * - * @param array $scopes A list of scopes that this authorization is in. - * @param string $note A note to remind you what the OAuth token is for. - * @param string $url A URL to remind you what app the OAuth token is for. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function create(array $scopes = [], $note = '', $url = '') - { - // Build the request path. - $path = '/authorizations'; - - $data = json_encode( - ['scopes' => $scopes, 'note' => $note, 'note_url' => $url] - ); - - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } - - /** - * Method to delete an authorization - * - * @param integer $id ID of the authorization to delete - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function delete($id) - { - // Build the request path. - $path = '/authorizations/' . $id; - - // Send the request. - return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } - - /** - * Delete a grant - * - * Deleting an OAuth application's grant will also delete all OAuth tokens associated with the application for your user. - * - * @param integer $id ID of the authorization to delete - * - * @return object - * - * @since 1.5.0 - * @throws \DomainException - */ - public function deleteGrant($id) - { - // Build the request path. - $path = '/authorizations/grants/' . $id; - - // Send the request. - return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } - - /** - * Method to edit an authorization. - * - * @param integer $id ID of the authorization to edit - * @param array $scopes Replaces the authorization scopes with these. - * @param array $addScopes A list of scopes to add to this authorization. - * @param array $removeScopes A list of scopes to remove from this authorization. - * @param string $note A note to remind you what the OAuth token is for. - * @param string $url A URL to remind you what app the OAuth token is for. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - * @throws \RuntimeException - */ - public function edit($id, array $scopes = [], array $addScopes = [], array $removeScopes = [], $note = '', $url = '') - { - // Check if more than one scopes array contains data - $scopesCount = 0; - $scope = ''; - $scopeData = ''; - - if (!empty($scopes)) { - $scope = 'scopes'; - $scopeData = $scopes; - $scopesCount++; - } - - if (!empty($addScopes)) { - $scope = 'add_scopes'; - $scopeData = $addScopes; - $scopesCount++; - } - - if (!empty($removeScopes)) { - $scope = 'remove_scopes'; - $scopeData = $removeScopes; - $scopesCount++; - } - - // Only allowed to send data for one scope parameter - if ($scopesCount >= 2) { - throw new \RuntimeException('You can only send one scope key in this request.'); - } - - // Build the request path. - $path = '/authorizations/' . $id; - - $data = json_encode( - [ - $scope => $scopeData, - 'note' => $note, - 'note_url' => $url, - ] - ); - - // Send the request. - return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); - } - - /** - * Method to get details about an authorised application for the authenticated user. - * - * @param integer $id ID of the authorization to retrieve - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($id) - { - // Build the request path. - $path = '/authorizations/' . $id; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Get a single grant - * - * @param integer $id ID of the authorization to retrieve - * - * @return object - * - * @since 1.5.0 - * @throws \DomainException - */ - public function getGrant($id) - { - // Build the request path. - $path = '/authorizations/grants/' . $id; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Method to get the authorised applications for the authenticated user. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getList() - { - // Build the request path. - $path = '/authorizations'; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * List your grants. - * - * You can use this API to list the set of OAuth applications that have been granted access to your account. - * - * @return object - * - * @since 1.5.0 - * @throws \DomainException - */ - public function getListGrants() - { - // Build the request path. - $path = '/authorizations/grants'; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - /** * Method to get the rate limit for the authenticated user. * @@ -345,26 +145,4 @@ public function requestToken($clientId, $clientSecret, $code, $redirectUri = '', 200 ); } - - /** - * Revoke a grant for an application - * - * OAuth application owners can revoke a grant for their OAuth application and a specific user. - * - * @param integer $clientId The application client ID - * @param integer $accessToken The access token to revoke - * - * @return object - * - * @since 1.5.0 - * @throws \DomainException - */ - public function revokeGrantForApplication($clientId, $accessToken) - { - // Build the request path. - $path = "/applications/$clientId/grants/$accessToken"; - - // Send the request. - return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } } diff --git a/src/Package/Orgs/Hooks.php b/src/Package/Orgs/Hooks.php index 23dc959d..e3dd2278 100644 --- a/src/Package/Orgs/Hooks.php +++ b/src/Package/Orgs/Hooks.php @@ -123,75 +123,6 @@ public function create($org, $url, $contentType = 'form', $secret = null, $insec ); } - /** - * Edit a hook. - * - * @param string $org The name of the organization. - * @param string $url The URL to which the payloads will be delivered. - * @param string $contentType The media type used to serialize the payloads. Supported values include "json" and "form". - * @param string $secret If provided, payloads will be delivered with an X-Hub-Signature header. - * The value of this header is computed as the - * [HMAC hex digest of the body, using the secret as the key][hub-signature]. - * @param boolean $insecureSsl Determines whether the SSL certificate of the host for url will be verified when delivering payloads. - * If false, verification is performed. If true, verification is not performed. - * @param array $events Determines what events the hook is triggered for. - * @param boolean $active Determines whether the hook is actually triggered on pushes. - * - * @return object - * - * @since 1.4.0 - * @throws \UnexpectedValueException - */ - public function edit($org, $url, $contentType = null, $secret = null, $insecureSsl = null, array $events = [], $active = null) - { - // Build the request path. - $path = "/orgs/$org/hooks"; - - $config = [ - 'url' => $url, - ]; - - if ($contentType) { - if (\in_array($contentType, ['form', 'json']) == false) { - throw new \UnexpectedValueException('Content type must be either "form" or "json".'); - } - - $config['content_type'] = $contentType; - } - - if ($insecureSsl !== null) { - $config['insecure_ssl'] = (int) $insecureSsl; - } - - if ($secret) { - $config['secret'] = $secret; - } - - $data = [ - 'config' => (object) $config, - ]; - - if ($active !== null) { - $data['active'] = (bool) $active; - } - - if (!empty($events)) { - // Check to ensure all events are in the allowed list - foreach ($events as $event) { - if (!\in_array($event, $this->hookEvents)) { - throw new \RuntimeException('Your events array contains an unauthorized event.'); - } - } - - $data['events'] = $events; - } - - return $this->processResponse( - $this->client->post($this->fetchUrl($path), $data), - 201 - ); - } - /** * Ping a hook. * diff --git a/src/Package/Orgs/Teams.php b/src/Package/Orgs/Teams.php index 7aaa82eb..0b60d0b7 100644 --- a/src/Package/Orgs/Teams.php +++ b/src/Package/Orgs/Teams.php @@ -42,25 +42,6 @@ public function getList($org) ); } - /** - * Get team. - * - * @param integer $id The team id. - * - * @return object - * - * @since 1.0 - */ - public function get($id) - { - // Build the request path. - $path = '/teams/' . (int) $id; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - /** * Create team. * @@ -106,372 +87,6 @@ public function create($org, $name, array $repoNames = [], $permission = '') ); } - /** - * Edit team. - * - * In order to edit a team, the authenticated user must be an owner of the org that the team is associated with. - * - * @param integer $id The team id. - * @param string $name The name of the team. - * @param string $permission The permission. (Deprecated) - * pull - team members can pull, but not push to or administer these repositories. Default - * push - team members can pull and push, but not administer these repositories. - * admin - team members can pull, push and administer these repositories. - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function edit($id, $name, $permission = '') - { - // Build the request path. - $path = '/teams/' . (int) $id; - - $data = [ - 'name' => $name, - ]; - - if ($permission) { - if (\in_array($permission, ['pull', 'push', 'admin']) == false) { - throw new \UnexpectedValueException('Permissions must be either "pull", "push", or "admin".'); - } - - $data['permission'] = $permission; - } - - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), $data) - ); - } - - /** - * Delete team. - * - * In order to delete a team, the authenticated user must be an owner of the org that the team is associated with. - * - * @param integer $id The team id. - * - * @return object - * - * @since 1.0 - */ - public function delete($id) - { - // Build the request path. - $path = '/teams/' . $id; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * List team members. - * - * In order to list members in a team, the authenticated user must be a member of the team. - * - * @param integer $id The team id. - * - * @return object - * - * @since 1.0 - */ - public function getListMembers($id) - { - // Build the request path. - $path = '/teams/' . $id . '/members'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Get team member. - * - * In order to get if a user is a member of a team, the authenticated user must be a member of the team. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * - * @return boolean - * - * @since 1.0 - * @throws \UnexpectedValueException - * @deprecated Use getTeamMembership() instead - */ - public function isMember($id, $user) - { - // Build the request path. - $path = '/teams/' . $id . '/members/' . $user; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->getStatusCode()) { - case 204: - // Response if user is a member - return true; - - case 404: - // Response if user is not a member - return false; - - default: - throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode()); - } - } - - /** - * Add team member. - * - * In order to add a user to a team, the authenticated user must have ‘admin’ permissions - * to the team or be an owner of the org that the team is associated with. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * - * @return object - * - * @since 1.0 - * @deprecated Use addTeamMembership() instead - */ - public function addMember($id, $user) - { - // Build the request path. - $path = '/teams/' . $id . '/members/' . $user; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), ''), - 204 - ); - } - - /** - * Remove team member. - * - * In order to remove a user from a team, the authenticated user must have ‘admin’ permissions - * to the team or be an owner of the org that the team is associated with. - * NOTE: This does not delete the user, it just remove them from the team. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * - * @return object - * - * @since 1.0 - * @deprecated Use removeTeamMembership() instead - */ - public function removeMember($id, $user) - { - // Build the request path. - $path = '/teams/' . $id . '/members/' . $user; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * Get team membership - * - * In order to get a user's membership with a team, the team must be visible to the authenticated user. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * - * @return string|boolean The state the user's membership is in or boolean false if the user is not a member. - * - * @since 1.4.0 - * @throws \UnexpectedValueException - */ - public function getTeamMembership($id, $user) - { - // Build the request path. - $path = "/teams/$id/memberships/$user"; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->getStatusCode()) { - case 200: - // Response if user is an active member or pending membership - $body = json_decode((string) $response->getBody()); - - return $body->state; - - case 404: - // Response if user is not a member - return false; - - default: - throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode()); - } - } - - /** - * Add team membership - * - * If the user is already a member of the team's organization, this endpoint will add the user to the team. - * In order to add a membership between an organization member and a team, the authenticated user must be - * an organization owner or a maintainer of the team. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * @param string $role The role the user should have on the team. Can be either 'member' or 'maintainer'. - * - * @return object - * - * @since 1.4.0 - * @throws \UnexpectedValueException - */ - public function addTeamMembership($id, $user, $role = 'member') - { - // Build the request path. - $path = "/teams/$id/memberships/$user"; - - if (\in_array($role, ['member', 'maintainer']) == false) { - throw new \UnexpectedValueException('Roles must be either "member" or "maintainer".'); - } - - $data = [ - 'role' => $role, - ]; - - return $this->processResponse($this->client->put($this->fetchUrl($path), $data)); - } - - /** - * Remove team membership - * - * In order to remove a membership between a user and a team, the authenticated user must have 'admin' permissions to the team - * or be an owner of the organization that the team is associated with. - * NOTE: This does not delete the user, it just removes their membership from the team. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * - * @return object - * - * @since 1.4.0 - * @throws \UnexpectedValueException - */ - public function removeTeamMembership($id, $user) - { - // Build the request path. - $path = "/teams/$id/memberships/$user"; - - return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } - - /** - * List team repos. - * - * @param integer $id The team id. - * - * @return object - * - * @since 1.0 - */ - public function getListRepos($id) - { - // Build the request path. - $path = '/teams/' . $id . '/repos'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Check if a team manages a repository. - * - * @param integer $id The team id. - * @param string $owner The owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return boolean - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function checkRepo($id, $owner, $repo) - { - // Build the request path. - $path = '/teams/' . $id . '/repos/' . $owner . '/' . $repo; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->getStatusCode()) { - case 204: - // Response if repo is managed by this team. - return true; - - case 404: - // Response if repo is not managed by this team. - return false; - - default: - throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode()); - } - } - - /** - * Add or update team repository. - * - * In order to add a repo to a team, the authenticated user must be an owner of the - * org that the team is associated with. Also, the repo must be owned by the organization, - * or a direct form of a repo owned by the organization. - * - * If you attempt to add a repo to a team that is not owned by the organization, you get: - * Status: 422 Unprocessable Entity - * - * @param integer $id The team id. - * @param string $org The name of the organization of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return object - * - * @since 1.0 - */ - public function addRepo($id, $org, $repo) - { - // Build the request path. - $path = '/teams/' . $id . '/repos/' . $org . '/' . $repo; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), ''), - 204 - ); - } - - /** - * Remove team repository. - * - * In order to remove a repo from a team, the authenticated user must be an owner - * of the org that the team is associated with. NOTE: This does not delete the - * repo, it just removes it from the team. - * - * @param integer $id The team id. - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return object - * - * @since 1.0 - */ - public function removeRepo($id, $owner, $repo) - { - // Build the request path. - $path = '/teams/' . (int) $id . '/repos/' . $owner . '/' . $repo; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - /** * List user teams. * diff --git a/src/Package/Repositories.php b/src/Package/Repositories.php index c79bd231..c0f5c93e 100644 --- a/src/Package/Repositories.php +++ b/src/Package/Repositories.php @@ -24,7 +24,6 @@ * @property-read Repositories\Commits $commits GitHub API object for commits. * @property-read Repositories\Contents $contents GitHub API object for contents. * @property-read Repositories\Deployments $deployments GitHub API object for deployments. - * @property-read Repositories\Downloads $downloads GitHub API object for downloads. * @property-read Repositories\Forks $forks GitHub API object for forks. * @property-read Repositories\Hooks $hooks GitHub API object for hooks. * @property-read Repositories\Keys $keys GitHub API object for keys. diff --git a/src/Package/Repositories/Downloads.php b/src/Package/Repositories/Downloads.php deleted file mode 100644 index 4e23ea1a..00000000 --- a/src/Package/Repositories/Downloads.php +++ /dev/null @@ -1,170 +0,0 @@ -processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Get a single download. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The id of the download. - * - * @return object - * - * @since 1.0 - * @deprecated The Releases API should be used instead - */ - public function get($owner, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/downloads/' . $id; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Create a new download (Part 1: Create the resource). - * - * Creating a new download is a two step process. You must first create a new download resource. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $name The name. - * @param string $size Size of file in bytes. - * @param string $description The description. - * @param string $contentType The content type. - * - * @return void - * - * @note This API endpoint no longer exists at GitHub - * @since 1.0 - * @throws \RuntimeException - * @deprecated The Releases API should be used instead - */ - public function create($owner, $repo, $name, $size, $description = '', $contentType = '') - { - throw new \RuntimeException('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); - } - - /** - * Create a new download (Part 2: Upload file to s3). - * - * Now that you have created the download resource, you can use the information - * in the response to upload your file to s3. This can be done with a POST to - * the s3_url you got in the create response. Here is a brief example using curl: - * - * curl \ - * -F "key=downloads/octocat/Hello-World/new_file.jpg" \ - * -F "acl=public-read" \ - * -F "success_action_status=201" \ - * -F "Filename=new_file.jpg" \ - * -F "AWSAccessKeyId=1ABCDEF..." \ - * -F "Policy=ewogIC..." \ - * -F "Signature=mwnF..." \ - * -F "Content-Type=image/jpeg" \ - * -F "file=@new_file.jpg" \ - * https://github.s3.amazonaws.com/ - * - * NOTES - * The order in which you pass these fields matters! Follow the order shown above exactly. - * All parameters shown are required and if you excluded or modify them your upload will - * fail because the values are hashed and signed by the policy. - * - * More information about using the REST API to interact with s3 can be found here: - * http://docs.amazonwebservices.com/AmazonS3/latest/API/ - * - * @param string $key Value of path field in the response. - * @param string $acl Value of acl field in the response. - * @param string $successActionStatus 201, or whatever you want to get back. - * @param string $filename Value of name field in the response. - * @param string $awsAccessKeyId Value of accesskeyid field in the response. - * @param string $policy Value of policy field in the response. - * @param string $signature Value of signature field in the response. - * @param string $contentType Value of mime_type field in the response. - * @param string $file Local file. Example assumes the file existing in the directory - * where you are running the curl command. Yes, the @ matters. - * - * @return void - * - * @note This API endpoint no longer exists at GitHub - * @since 1.0 - * @throws \RuntimeException - * @deprecated The Releases API should be used instead - */ - public function upload($key, $acl, $successActionStatus, $filename, $awsAccessKeyId, $policy, $signature, $contentType, $file) - { - throw new \RuntimeException('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); - } - - /** - * Delete a download. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The id of the download. - * - * @return object - * - * @since 1.0 - * @deprecated The Releases API should be used instead - */ - public function delete($owner, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/downloads/' . (int) $id; - - // Send the request. - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } -} diff --git a/src/Package/Search.php b/src/Package/Search.php index f1a744c0..00a347de 100644 --- a/src/Package/Search.php +++ b/src/Package/Search.php @@ -20,118 +20,4 @@ */ class Search extends AbstractPackage { - /** - * Search issues. - * - * @param string $owner The name of the owner of the repository. - * @param string $repo The name of the repository. - * @param string $state The state - open or closed. - * @param string $keyword The search term. - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - * @deprecated The legacy API is deprecated - */ - public function issues($owner, $repo, $state, $keyword) - { - if (\in_array($state, ['open', 'close']) == false) { - throw new \UnexpectedValueException('State must be either "open" or "closed"'); - } - - // Build the request path. - $path = '/legacy/issues/search/' . $owner . '/' . $repo . '/' . $state . '/' . $keyword; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Search repositories. - * - * Find repositories by keyword. Note, this legacy method does not follow - * the v3 pagination pattern. - * This method returns up to 100 results per page and pages can be fetched - * using the start_page parameter. - * - * @param string $keyword The search term. - * @param string $language Filter results by language https://github.com/languages - * @param integer $startPage Page number to fetch - * - * @return object - * - * @since 1.0 - * @deprecated The legacy API is deprecated - */ - public function repositories($keyword, $language = '', $startPage = 0) - { - // Build the request path. - $uri = $this->fetchUrl('/legacy/repos/search/' . $keyword); - - if ($language) { - $uri->setVar('language', $language); - } - - if ($startPage) { - $uri->setVar('start_page', $startPage); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Search users. - * - * Find users by keyword. - * - * @param string $keyword The search term. - * @param integer $startPage Page number to fetch - * - * @return object - * - * @since 1.0 - * @deprecated The legacy API is deprecated - */ - public function users($keyword, $startPage = 0) - { - // Build the request path. - $uri = $this->fetchUrl('/legacy/user/search/' . $keyword); - - if ($startPage) { - $uri->setVar('start_page', $startPage); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Email search. - * - * This API call is added for compatibility reasons only. There’s no guarantee - * that full email searches will always be available. The @ character in the - * address must be left unencoded. Searches only against public email addresses - * (as configured on the user’s GitHub profile). - * - * @param string $email The email address(es). - * - * @return object - * - * @since 1.0 - * @deprecated The legacy API is deprecated - */ - public function email($email) - { - // Build the request path. - $path = '/legacy/user/email/' . $email; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } } diff --git a/src/Package/Users/Keys.php b/src/Package/Users/Keys.php index d8c5091e..096f1876 100644 --- a/src/Package/Users/Keys.php +++ b/src/Package/Users/Keys.php @@ -107,32 +107,6 @@ public function create($title, $key) ); } - /** - * Update a public key. - * - * @param integer $id The id of the key. - * @param string $title The title of the key. - * @param string $key The key. - * - * @return object - * - * @since 1.0 - */ - public function edit($id, $title, $key) - { - // Build the request path. - $path = '/users/keys/' . $id; - - $data = [ - 'title' => $title, - 'key' => $key, - ]; - - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), json_encode($data)) - ); - } - /** * Delete a public key. *