Skip to content

Commit

Permalink
Merge branch 'feature/mg-issuesEndpoint' of AVENCY/Gitea into master
Browse files Browse the repository at this point in the history
Reviewed-by: Lisa Kampert <[email protected]>
  • Loading branch information
gerdemann committed Jan 21, 2020
2 parents 43d6a4b + 2b7abe5 commit 0ae1cba
Show file tree
Hide file tree
Showing 12 changed files with 949 additions and 44 deletions.
2 changes: 2 additions & 0 deletions Classes/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Avency\Gitea\Endpoint\Admin;
use Avency\Gitea\Endpoint\EndpointInterface;
use Avency\Gitea\Endpoint\Issues;
use Avency\Gitea\Endpoint\Miscellaneous;
use Avency\Gitea\Endpoint\Organizations;
use Avency\Gitea\Endpoint\Repositories;
Expand All @@ -18,6 +19,7 @@
* Gitea Client
*
* @method Admin admin()
* @method Issues issues()
* @method Miscellaneous miscellaneous()
* @method Organizations organizations()
* @method Repositories repositories()
Expand Down
47 changes: 47 additions & 0 deletions Classes/Endpoint/Issues.php
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;
}
}
140 changes: 140 additions & 0 deletions Classes/Endpoint/Issues/CommentsTrait.php
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);
}
}
101 changes: 101 additions & 0 deletions Classes/Endpoint/Issues/IssueTrait.php
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);
}
}
Loading

0 comments on commit 0ae1cba

Please sign in to comment.