Skip to content
Open
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
68 changes: 68 additions & 0 deletions lib/Github/Api/AbstractReactionsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Github\Api;

use Github\Exception\MissingArgumentException;

abstract class AbstractReactionsApi extends AbstractApi
{
/**
* List reactions for a resource.
*
* @param string $username
* @param string $repository
* @param string $id
* @param array $params
*
* @return array
*/
public function all($username, $repository, $id, array $params = [])
{
return $this->get($this->getReactionsPath($username, $repository, $id), $params);
}

/**
* Create a reaction for a resource.
*
* @param string $username
* @param string $repository
* @param string $id
* @param array $params
*
* @throws MissingArgumentException
*
* @return array
*/
public function create($username, $repository, $id, array $params)
{
if (!isset($params['content'])) {
throw new MissingArgumentException('content');
}

return $this->post($this->getReactionsPath($username, $repository, $id), $params);
}

/**
* Delete a reaction from a resource.
*
* @param string $username
* @param string $repository
* @param string $id
* @param string $reaction
*
* @return array|string
*/
public function remove($username, $repository, $id, $reaction)
{
return $this->delete($this->getReactionsPath($username, $repository, $id).'/'.rawurlencode($reaction));
}

/**
* @param string $username
* @param string $repository
* @param string $id
*
* @return string
*/
abstract protected function getReactionsPath($username, $repository, $id);
}
13 changes: 13 additions & 0 deletions lib/Github/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Github\Api\Issue\Events;
use Github\Api\Issue\Labels;
use Github\Api\Issue\Milestones;
use Github\Api\Issue\Reactions;
use Github\Api\Issue\Timeline;
use Github\Exception\MissingArgumentException;

Expand Down Expand Up @@ -179,6 +180,18 @@ public function comments()
return new Comments($this->getClient());
}

/**
* Manage issue reactions.
*
* @link https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-an-issue
*
* @return Reactions
*/
public function reactions()
{
return new Reactions($this->getClient());
}

/**
* List all project events.
*
Expand Down
13 changes: 13 additions & 0 deletions lib/Github/Api/Issue/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Api\Issue\Comments\Reactions;
use Github\Exception\MissingArgumentException;

/**
Expand Down Expand Up @@ -130,4 +131,16 @@ public function remove($username, $repository, $comment)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.$comment);
}

/**
* Manage issue comment reactions.
*
* @link https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-an-issue-comment
*
* @return Reactions
*/
public function reactions()
{
return new Reactions($this->getClient());
}
}
20 changes: 20 additions & 0 deletions lib/Github/Api/Issue/Comments/Reactions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Github\Api\Issue\Comments;

use Github\Api\AbstractReactionsApi;

class Reactions extends AbstractReactionsApi
{
/**
* @param string $username
* @param string $repository
* @param string $id
*
* @return string
*/
protected function getReactionsPath($username, $repository, $id)
{
return '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($id).'/reactions';
}
}
20 changes: 20 additions & 0 deletions lib/Github/Api/Issue/Reactions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Github\Api\Issue;

use Github\Api\AbstractReactionsApi;

class Reactions extends AbstractReactionsApi
{
/**
* @param string $username
* @param string $repository
* @param string $id
*
* @return string
*/
protected function getReactionsPath($username, $repository, $id)
{
return '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/reactions';
}
}
13 changes: 13 additions & 0 deletions lib/Github/Api/PullRequest/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Api\PullRequest\Comments\Reactions;
use Github\Exception\MissingArgumentException;

/**
Expand Down Expand Up @@ -150,4 +151,16 @@ public function remove($username, $repository, $comment)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.$comment);
}

/**
* Manage pull request review comment reactions.
*
* @link https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-a-pull-request-review-comment
*
* @return Reactions
*/
public function reactions()
{
return new Reactions($this->getClient());
}
}
20 changes: 20 additions & 0 deletions lib/Github/Api/PullRequest/Comments/Reactions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Github\Api\PullRequest\Comments;

use Github\Api\AbstractReactionsApi;

class Reactions extends AbstractReactionsApi
{
/**
* @param string $username
* @param string $repository
* @param string $id
*
* @return string
*/
protected function getReactionsPath($username, $repository, $id)
{
return '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($id).'/reactions';
}
}
13 changes: 13 additions & 0 deletions lib/Github/Api/Repository/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Api\Repository\Comments\Reactions;
use Github\Exception\MissingArgumentException;

/**
Expand Down Expand Up @@ -72,4 +73,16 @@ public function remove($username, $repository, $comment)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment));
}

/**
* Manage commit comment reactions.
*
* @link https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-a-commit-comment
*
* @return Reactions
*/
public function reactions()
{
return new Reactions($this->getClient());
}
}
20 changes: 20 additions & 0 deletions lib/Github/Api/Repository/Comments/Reactions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Github\Api\Repository\Comments;

use Github\Api\AbstractReactionsApi;

class Reactions extends AbstractReactionsApi
{
/**
* @param string $username
* @param string $repository
* @param string $id
*
* @return string
*/
protected function getReactionsPath($username, $repository, $id)
{
return '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($id).'/reactions';
}
}
13 changes: 13 additions & 0 deletions lib/Github/Api/Repository/Releases.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Github\Api\Repository;

use Github\Api\AbstractApi;
use Github\Api\Repository\Releases\Reactions;
use Github\Exception\MissingArgumentException;

/**
Expand Down Expand Up @@ -138,4 +139,16 @@ public function assets()
{
return new Assets($this->getClient());
}

/**
* Manage release reactions.
*
* @link https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-a-release
*
* @return Reactions
*/
public function reactions()
{
return new Reactions($this->getClient());
}
}
20 changes: 20 additions & 0 deletions lib/Github/Api/Repository/Releases/Reactions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Github\Api\Repository\Releases;

use Github\Api\AbstractReactionsApi;

class Reactions extends AbstractReactionsApi
{
/**
* @param string $username
* @param string $repository
* @param string $id
*
* @return string
*/
protected function getReactionsPath($username, $repository, $id)
{
return '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/reactions';
}
}
81 changes: 81 additions & 0 deletions test/Github/Tests/Api/Issue/Comments/ReactionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Github\Tests\Api\Issue\Comments;

use Github\Exception\MissingArgumentException;
use Github\Tests\Api\TestCase;

class ReactionsTest extends TestCase
{
/**
* @test
*/
public function shouldGetAllIssueCommentReactions()
{
$expectedValue = [['reaction1data'], ['reaction2data']];
$parameters = ['content' => 'rocket'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/issues/comments/123/reactions', $parameters)
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123, $parameters));
}

/**
* @test
*/
public function shouldNotCreateIssueCommentReactionWithoutContent()
{
$this->expectException(MissingArgumentException::class);

$api = $this->getApiMock();
$api->expects($this->never())
->method('post');

$api->create('KnpLabs', 'php-github-api', 123, []);
}

/**
* @test
*/
public function shouldCreateIssueCommentReaction()
{
$expectedValue = ['reaction1data'];
$data = ['content' => 'rocket'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('/repos/KnpLabs/php-github-api/issues/comments/123/reactions', $data)
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 123, $data));
}

/**
* @test
*/
public function shouldRemoveIssueCommentReaction()
{
$expectedValue = ['someOutput'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('/repos/KnpLabs/php-github-api/issues/comments/123/reactions/456')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 123, 456));
}

/**
* @return string
*/
protected function getApiClass()
{
return \Github\Api\Issue\Comments\Reactions::class;
}
}
10 changes: 10 additions & 0 deletions test/Github/Tests/Api/Issue/CommentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ public function shouldRemoveComment()
$this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 123));
}

/**
* @test
*/
public function shouldGetReactionsApiObject()
{
$api = $this->getApiMock();

$this->assertInstanceOf(\Github\Api\Issue\Comments\Reactions::class, $api->reactions());
}

/**
* @return string
*/
Expand Down
Loading
Loading