Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,15 @@ Returns a list of milestones.
```php
$codeOfConduct = $client->api('repo')->codeOfConduct('ornicar', 'php-github-api');
```

### List all topics for a repository

```php
$topics = $client->api('repo')->topics('ornicar', 'php-github-api');
```

### Replace all topics for a repository

```php
$currentTopics = $client->api('repo')->replaceTopics('ornicar', 'php-github-api', ['new', 'topics']);
```
37 changes: 37 additions & 0 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,41 @@ public function codeOfConduct($username, $repository)

return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/community/code_of_conduct');
}

/**
* List all topics for a repository
*
* @link https://developer.github.com/v3/repos/#list-all-topics-for-a-repository
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function topics($username, $repository)
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json';

return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics');
}

/**
* Replace all topics for a repository
*
* @link https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository
*
* @param string $username
* @param string $repository
* @param array $topics
*
* @return array
*/
public function replaceTopics($username, $repository, array $topics)
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json';

return $this->put('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics', ['names' => $topics]);
}
}
34 changes: 34 additions & 0 deletions test/Github/Tests/Api/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,40 @@ public function shouldGetRepositoryCodeOfConduct()
$this->assertEquals($expectedArray, $api->codeOfConduct('KnpLabs', 'php-github-api'));
}

/**
* @test
*/
public function shouldGetRepositoryTopics()
{
$expectedArray = ['names' => ['octocat', 'atom', 'electron', 'API']];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/topics')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->topics('KnpLabs', 'php-github-api'));
}

/**
* @test
*/
public function shouldReplaceRepositoryTopics()
{
$expectedArray = array('id' => 6122723754, 'type' => 'ForkEvent');

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('/repos/KnpLabs/php-github-api/topics', array(
'names' => ['octocat', 'atom', 'electron', 'API'],
))
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->replaceTopics('KnpLabs', 'php-github-api', ['octocat', 'atom', 'electron', 'API']));
}

/**
* @return string
*/
Expand Down