public function indexAction() { $contributors = $this->repositoryRetriever->getContributors($this->repository->owner(), $this->repository->name()); shuffle($contributors); $metadata = $this->repositoryRetriever->getUserRepositoryMetadata($this->repository->owner(), $this->repository->name()); return new ViewModel(['contributors' => $contributors, 'metadata' => $metadata]); }
/** * Removes a Module * * @return Http\Response * @throws Exception\InvalidDataException * @throws Exception\RepositoryException */ public function removeAction() { if (!$this->zfcUserAuthentication()->hasIdentity()) { return $this->redirect()->toRoute('zfcuser/login'); } $request = $this->getRequest(); if (!$request->isPost()) { throw Exception\InvalidDataException::fromInvalidRequest('Something went wrong with the post values of the request...', $request); } $postParams = $request->getPost(); $repo = $postParams->get('repo'); $owner = $postParams->get('owner'); $repository = $this->repositoryRetriever->getUserRepositoryMetadata($owner, $repo); if (!$repository instanceof \stdClass) { throw Exception\RepositoryException::fromNotFoundRepository('Not able to fetch the repository from GitHub due to an unknown error.', $owner, $repo); } if ($repository->fork || !$repository->permissions->push) { throw Exception\RepositoryException::fromInsufficientPermissions('You have no permission to remove this module. The reason might be that you are neither the owner nor a collaborator of this repository.', $repository->full_name, ['pushAccess', 'noFork']); } $module = $this->moduleMapper->findByUrl($repository->html_url); if (!$module) { throw Exception\RepositoryException::fromNotFoundRepositoryUrl($repository->name . ' was not found', $repository->html_url); } $this->moduleMapper->delete($module); $this->flashMessenger()->addSuccessMessage($repository->name . ' has been removed from ZF Modules'); return $this->redirect()->toRoute('zfcuser'); }
public function testGetContributorsReturnsFalseIfRuntimeExceptionIsThrown() { $owner = 'foo'; $name = 'bar'; $repositoryApi = $this->getMockBuilder(Api\Repos::class)->disableOriginalConstructor()->getMock(); $repositoryApi->expects($this->once())->method('contributors')->willThrowException(new Exception\RuntimeException()); $client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock(); $client->expects($this->once())->method('api')->with($this->equalTo('repos'))->willReturn($repositoryApi); $service = new RepositoryRetriever($client); $contributors = $service->getContributors($owner, $name); $this->assertFalse($contributors); }