-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/mg-issuesEndpoint' of AVENCY/Gitea into master
Reviewed-by: Lisa Kampert <[email protected]>
- Loading branch information
Showing
12 changed files
with
949 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Avency\Gitea\Endpoint; | ||
|
||
use Avency\Gitea\Client; | ||
use Avency\Gitea\Endpoint\Issues\CommentsTrait; | ||
use Avency\Gitea\Endpoint\Issues\IssuesTrait; | ||
use Avency\Gitea\Endpoint\Issues\IssueTrait; | ||
use Avency\Gitea\Endpoint\Issues\LabelsTrait; | ||
use Avency\Gitea\Endpoint\Issues\MilestonesTrait; | ||
use Avency\Gitea\Endpoint\Issues\ReactionsTrait; | ||
use Avency\Gitea\Endpoint\Issues\StopwatchTrait; | ||
use Avency\Gitea\Endpoint\Issues\SubscriptionsTrait; | ||
use Avency\Gitea\Endpoint\Issues\TimesTrait; | ||
|
||
/** | ||
* Issues endpoint | ||
*/ | ||
class Issues extends AbstractEndpoint implements EndpointInterface | ||
{ | ||
use CommentsTrait; | ||
use IssueTrait; | ||
use IssuesTrait; | ||
use LabelsTrait; | ||
use MilestonesTrait; | ||
use ReactionsTrait; | ||
use StopwatchTrait; | ||
use SubscriptionsTrait; | ||
use TimesTrait; | ||
|
||
const BASE_URI = '/repos'; | ||
|
||
/** | ||
* @var Client | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @param Client $client | ||
*/ | ||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Avency\Gitea\Endpoint\Issues; | ||
|
||
use Avency\Gitea\Client; | ||
|
||
/** | ||
* Issues Comments Trait | ||
*/ | ||
trait CommentsTrait | ||
{ | ||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @return array | ||
*/ | ||
public function getComments(string $owner, string $repositoryName): array | ||
{ | ||
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/comments'); | ||
|
||
return \GuzzleHttp\json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @param int $id | ||
* @return bool | ||
*/ | ||
public function deleteComment(string $owner, string $repositoryName, int $id): bool | ||
{ | ||
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/comments/' . $id, 'DELETE'); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @param int $id | ||
* @param string $body | ||
* @return array | ||
*/ | ||
public function updateComment(string $owner, string $repositoryName, int $id, string $body): array | ||
{ | ||
$options['json'] = [ | ||
'body' => $body | ||
]; | ||
|
||
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/comments/' . $id, 'PATCH', $options); | ||
|
||
return \GuzzleHttp\json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @param int $id | ||
* @return array | ||
*/ | ||
public function getCommentReactions(string $owner, string $repositoryName, int $id): array | ||
{ | ||
$options['json'] = [ | ||
'body' => $body | ||
]; | ||
|
||
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/comments/' . $id . '/reactions'); | ||
|
||
return \GuzzleHttp\json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @param int $id | ||
* @param string $reaction | ||
* @return array | ||
*/ | ||
public function addCommentReaction(string $owner, string $repositoryName, int $id, string $reaction): array | ||
{ | ||
$options['json'] = [ | ||
'content' => $reaction | ||
]; | ||
|
||
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/comments/' . $id . '/reactions', 'POST', $options); | ||
|
||
return \GuzzleHttp\json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @param int $id | ||
* @param string $reaction | ||
* @return bool | ||
*/ | ||
public function deleteCommentReaction(string $owner, string $repositoryName, int $id, string $reaction): bool | ||
{ | ||
$options['json'] = [ | ||
'content' => $reaction | ||
]; | ||
|
||
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/comments/' . $id . '/reactions', 'DELETE', $options); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @param int $index | ||
* @return array | ||
*/ | ||
public function getIssueComments(string $owner, string $repositoryName, int $index): array | ||
{ | ||
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/' . $index . '/comments'); | ||
|
||
return \GuzzleHttp\json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @param int $index | ||
* @param string $body | ||
* @return array | ||
*/ | ||
public function addIssueComment(string $owner, string $repositoryName, int $index, string $body): array | ||
{ | ||
$options['json'] = [ | ||
'body' => $body | ||
]; | ||
|
||
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/' . $index . '/comments', 'POST', $options); | ||
|
||
return \GuzzleHttp\json_decode($response->getBody(), true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Avency\Gitea\Endpoint\Issues; | ||
|
||
use Avency\Gitea\Client; | ||
|
||
/** | ||
* Issues Issue Trait | ||
*/ | ||
trait IssueTrait | ||
{ | ||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @param int $index | ||
* @return array | ||
*/ | ||
public function get(string $owner, string $repositoryName, int $index): array | ||
{ | ||
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/' . $index); | ||
|
||
return \GuzzleHttp\json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @param int $index | ||
* @param string|null $assignee | ||
* @param array|null $assignees | ||
* @param string|null $body | ||
* @param \DateTime|null $dueDate | ||
* @param int|null $milestone | ||
* @param string|null $state | ||
* @param string|null $title | ||
* @param bool|null $unsetDueDate | ||
* @return array | ||
*/ | ||
public function update( | ||
string $owner, | ||
string $repositoryName, | ||
int $index, | ||
string $assignee = null, | ||
array $assignees = null, | ||
string $body = null, | ||
\DateTime $dueDate = null, | ||
int $milestone = null, | ||
string $state = null, | ||
string $title = null, | ||
bool $unsetDueDate = null | ||
): array | ||
{ | ||
$options['json'] = [ | ||
'assignee' => $assignee, | ||
'assignees' => $assignees, | ||
'body' => $body, | ||
'due_date' => $dueDate ? $dueDate->format(\DateTime::ATOM) : null, | ||
'mileston' => $milestone, | ||
'state' => $state, | ||
'title' => $title, | ||
'unset_due_date' => $unsetDueDate, | ||
]; | ||
$options['json'] = $this->removeNullValues($options['json']); | ||
|
||
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/' . $index, 'PATCH', $options); | ||
|
||
return \GuzzleHttp\json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* @param string $owner | ||
* @param string $repositoryName | ||
* @param int $index | ||
* @param string|null $assignee | ||
* @param array|null $assignees | ||
* @param string|null $body | ||
* @param \DateTime|null $dueDate | ||
* @param int|null $milestone | ||
* @param string|null $state | ||
* @param string|null $title | ||
* @param bool|null $unsetDueDate | ||
* @return array | ||
*/ | ||
public function setDeadline( | ||
string $owner, | ||
string $repositoryName, | ||
int $index, | ||
\DateTime $dueDate | ||
): array | ||
{ | ||
$options['json'] = [ | ||
'due_date' => $dueDate->format(\DateTime::ATOM), | ||
]; | ||
|
||
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/' . $index . '/deadline', 'POST', $options); | ||
|
||
return \GuzzleHttp\json_decode($response->getBody(), true); | ||
} | ||
} |
Oops, something went wrong.