Skip to content

Missing repository topics api endpoints #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2017
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