Skip to content

Commit 5ffee22

Browse files
committed
Missing repository topics api endpoints
1 parent ba01b38 commit 5ffee22

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

doc/repos.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,15 @@ $milestones = $client->api('repo')->milestones('ornicar', 'php-github-api');
303303
```
304304

305305
Returns a list of milestones.
306+
307+
### List all topics for a repository
308+
309+
```php
310+
$topics = $client->api('repo')->topics('ornicar', 'php-github-api');
311+
```
312+
313+
### Replace all topics for a repository
314+
315+
```php
316+
$currentTopics = $client->api('repo')->replaceTopics('ornicar', 'php-github-api', ['new', 'topics']);
317+
```

lib/Github/Api/Repo.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
class Repo extends AbstractApi
3030
{
31+
use AcceptHeaderTrait;
32+
3133
/**
3234
* Search repositories by keyword.
3335
*
@@ -599,4 +601,20 @@ public function events($username, $repository, $page = 1)
599601
{
600602
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/events', ['page' => $page]);
601603
}
604+
605+
public function topics($username, $repository)
606+
{
607+
//This api is in preview mode, so set the correct accept-header
608+
$this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json';
609+
610+
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics');
611+
}
612+
613+
public function replaceTopics($username, $repository, array $topics)
614+
{
615+
//This api is in preview mode, so set the correct accept-header
616+
$this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json';
617+
618+
return $this->put('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics', ['names' => $topics]);
619+
}
602620
}

test/Github/Tests/Api/RepoTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,40 @@ public function shouldGetRepositoryEvents()
535535
$this->assertEquals($expectedArray, $api->events('KnpLabs', 'php-github-api', 3));
536536
}
537537

538+
/**
539+
* @test
540+
*/
541+
public function shouldGetRepositoryTopics()
542+
{
543+
$expectedArray = ['names' => ['octocat', 'atom', 'electron', 'API']];
544+
545+
$api = $this->getApiMock();
546+
$api->expects($this->once())
547+
->method('get')
548+
->with('/repos/KnpLabs/php-github-api/topics')
549+
->will($this->returnValue($expectedArray));
550+
551+
$this->assertEquals($expectedArray, $api->topics('KnpLabs', 'php-github-api'));
552+
}
553+
554+
/**
555+
* @test
556+
*/
557+
public function shouldReplaceRepositoryTopics()
558+
{
559+
$expectedArray = array('id' => 6122723754, 'type' => 'ForkEvent');
560+
561+
$api = $this->getApiMock();
562+
$api->expects($this->once())
563+
->method('put')
564+
->with('/repos/KnpLabs/php-github-api/topics', array(
565+
'names' => ['octocat', 'atom', 'electron', 'API'],
566+
))
567+
->will($this->returnValue($expectedArray));
568+
569+
$this->assertEquals($expectedArray, $api->replaceTopics('KnpLabs', 'php-github-api', ['octocat', 'atom', 'electron', 'API']));
570+
}
571+
538572
/**
539573
* @return string
540574
*/

0 commit comments

Comments
 (0)