Example #1
0
 /**
  * @param $keywords
  * @param null $sort
  * @param string $order
  * @throws \InvalidArgumentException
  * @return Repository[]
  */
 public function findRepositories($keywords, $sort = self::SORT_BY_BEST_MATCH, $order = self::ORDER_DESC)
 {
     $query = ['q' => $keywords];
     if ($sort !== self::SORT_BY_BEST_MATCH) {
         $allowed = [self::SORT_BY_STARS, self::SORT_BY_FORKS, self::SORT_BY_LAST_UPDATED];
         if (!in_array($sort, $allowed)) {
             throw new \InvalidArgumentException(sprintf('Invalid sort argument %s. Should be one of %s', $sort, implode(', ', $allowed)));
         }
         $query['sort'] = $sort;
     }
     if ($order !== self::ORDER_DESC) {
         $query['order'] = $order;
     }
     $request = $this->client->get('search/repositories');
     $request->getQuery()->merge($query);
     return new PaginationIterator($this->client, $request, function ($response, $client) {
         $repositories = [];
         foreach ($response['items'] as $data) {
             $repository = new Repository($client);
             $repository->populate($data);
             $repositories[] = $repository;
         }
         return $repositories;
     });
 }
Example #2
0
 public function testAddKey()
 {
     $this->mockSimpleRequest($this->httpClient, 'post', json_encode($this->loadJsonFixture('fixture_key.json')));
     $repository = new Repository($this->httpClient);
     $repository->populate($this->loadJsonFixture('fixture_repository.json'));
     $key = new Key();
     $key->setTitle('hello word');
     $key->setKey('123');
     $this->assertNull($key->getId());
     $repository->addKey($key);
     $this->assertEquals(1, $key->getId());
 }
Example #3
0
 /**
  * @param $owner string The login name of the repository owner, e.g. "octocat"
  * @param $name string The repository name, e.g. "Hello-World"
  * @throws Exception\GithubException In case the repository was not found
  * @return Repository
  */
 public function getRepository($owner, $name)
 {
     $repository = new Repository($this->client);
     $repository->populate(['owner' => ['login' => $owner], 'name' => $name]);
     try {
         $repository->getId();
     } catch (GithubException $e) {
         throw new GithubException(sprintf('Repository %s was not found.', $name), 0, $e);
     }
     return $repository;
 }