feat: Add issues endpoint

This commit is contained in:
Michael Gerdemann
2020-01-20 07:59:23 +01:00
parent 53c5c232d2
commit dcc8a2aac8
12 changed files with 949 additions and 42 deletions

View File

@ -0,0 +1,154 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Issues;
use Avency\Gitea\Client;
/**
* Issues Labels Trait
*/
trait LabelsTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @param int $index
* @return array
*/
public function getLabels(string $owner, string $repositoryName, int $index): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/' . $index . '/labels');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $index
* @param array $labels
* @return array
*/
public function replaceLabels(string $owner, string $repositoryName, int $index, array $labels): array
{
$options['json'] = [
'labels' => $labels
];
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/' . $index . '/labels', 'PUT', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $index
* @param array $labels
* @return array
*/
public function addLabels(string $owner, string $repositoryName, int $index, array $labels): array
{
$options['json'] = [
'labels' => $labels
];
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/' . $index . '/labels', 'POST', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $index
* @return bool
*/
public function deleteAllLabels(string $owner, string $repositoryName, int $index): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/' . $index . '/labels', 'DELETE');
return true;
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $index
* @param int $id
* @return bool
*/
public function deleteLabel(string $owner, string $repositoryName, int $index, int $id): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/issues/' . $index . '/labels/' . $id, 'DELETE');
return true;
}
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getRepositoryLabels(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/labels');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return array
*/
public function getRepositoryLabel(string $owner, string $repositoryName, int $id): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/labels/' . $id);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return array
*/
public function updateRepositoryLabel(
string $owner,
string $repositoryName,
int $id,
string $name = null,
string $description = null,
string $color = null
): array
{
$options['json'] = [
'name' => $name,
'description' => $description,
'color' => $color,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/labels/' . $id, 'PATCH', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return bool
*/
public function deleteRepositoryLabel(string $owner, string $repositoryName, int $id): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/labels/' . $id, 'DELETE');
return true;
}
}