mirror of
https://github.com/avency/Gitea.git
synced 2025-10-29 10:42:33 +01:00
feat: Add issues endpoint
This commit is contained in:
154
Classes/Endpoint/Issues/LabelsTrait.php
Normal file
154
Classes/Endpoint/Issues/LabelsTrait.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user