Skip to content

Commit 95e66ef

Browse files
acrobatNyholm
authored andcommitted
Missing repository topics api endpoints (KnpLabs#657)
1 parent 1d4d360 commit 95e66ef

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

doc/repos.md

+12
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,15 @@ Returns a list of milestones.
309309
```php
310310
$codeOfConduct = $client->api('repo')->codeOfConduct('ornicar', 'php-github-api');
311311
```
312+
313+
### List all topics for a repository
314+
315+
```php
316+
$topics = $client->api('repo')->topics('ornicar', 'php-github-api');
317+
```
318+
319+
### Replace all topics for a repository
320+
321+
```php
322+
$currentTopics = $client->api('repo')->replaceTopics('ornicar', 'php-github-api', ['new', 'topics']);
323+
```

lib/Github/Api/Repo.php

+37
Original file line numberDiff line numberDiff line change
@@ -621,4 +621,41 @@ public function codeOfConduct($username, $repository)
621621

622622
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/community/code_of_conduct');
623623
}
624+
625+
/**
626+
* List all topics for a repository
627+
*
628+
* @link https://developer.github.com/v3/repos/#list-all-topics-for-a-repository
629+
*
630+
* @param string $username
631+
* @param string $repository
632+
*
633+
* @return array
634+
*/
635+
public function topics($username, $repository)
636+
{
637+
//This api is in preview mode, so set the correct accept-header
638+
$this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json';
639+
640+
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics');
641+
}
642+
643+
/**
644+
* Replace all topics for a repository
645+
*
646+
* @link https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository
647+
*
648+
* @param string $username
649+
* @param string $repository
650+
* @param array $topics
651+
*
652+
* @return array
653+
*/
654+
public function replaceTopics($username, $repository, array $topics)
655+
{
656+
//This api is in preview mode, so set the correct accept-header
657+
$this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json';
658+
659+
return $this->put('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics', ['names' => $topics]);
660+
}
624661
}

test/Github/Tests/Api/RepoTest.php

+34
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,40 @@ public function shouldGetRepositoryCodeOfConduct()
551551
$this->assertEquals($expectedArray, $api->codeOfConduct('KnpLabs', 'php-github-api'));
552552
}
553553

554+
/**
555+
* @test
556+
*/
557+
public function shouldGetRepositoryTopics()
558+
{
559+
$expectedArray = ['names' => ['octocat', 'atom', 'electron', 'API']];
560+
561+
$api = $this->getApiMock();
562+
$api->expects($this->once())
563+
->method('get')
564+
->with('/repos/KnpLabs/php-github-api/topics')
565+
->will($this->returnValue($expectedArray));
566+
567+
$this->assertEquals($expectedArray, $api->topics('KnpLabs', 'php-github-api'));
568+
}
569+
570+
/**
571+
* @test
572+
*/
573+
public function shouldReplaceRepositoryTopics()
574+
{
575+
$expectedArray = array('id' => 6122723754, 'type' => 'ForkEvent');
576+
577+
$api = $this->getApiMock();
578+
$api->expects($this->once())
579+
->method('put')
580+
->with('/repos/KnpLabs/php-github-api/topics', array(
581+
'names' => ['octocat', 'atom', 'electron', 'API'],
582+
))
583+
->will($this->returnValue($expectedArray));
584+
585+
$this->assertEquals($expectedArray, $api->replaceTopics('KnpLabs', 'php-github-api', ['octocat', 'atom', 'electron', 'API']));
586+
}
587+
554588
/**
555589
* @return string
556590
*/

0 commit comments

Comments
 (0)