mirror of
https://github.com/avency/Gitea.git
synced 2025-10-30 03:02:32 +01:00
feat: add further Repo endpoints
This commit is contained in:
69
Classes/Endpoint/Repositories/CollaboratorsTrait.php
Normal file
69
Classes/Endpoint/Repositories/CollaboratorsTrait.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Avency\Gitea\Endpoint\Repositories;
|
||||
|
||||
use Avency\Gitea\Client;
|
||||
|
||||
/**
|
||||
* Repositories Collaborators Trait
|
||||
*/
|
||||
trait CollaboratorsTrait
|
||||
{
|
||||
/**
|
||||
* @param string $owner
|
||||
* @param string $repositoryName
|
||||
* @return array
|
||||
*/
|
||||
public function getCollaborators(string $owner, string $repositoryName): array
|
||||
{
|
||||
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/collaborators');
|
||||
|
||||
return \GuzzleHttp\json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $owner
|
||||
* @param string $repositoryName
|
||||
* @param string $collaborator
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCollaborator(string $owner, string $repositoryName, string $collaborator): bool
|
||||
{
|
||||
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/collaborators/' . $collaborator);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $owner
|
||||
* @param string $repositoryName
|
||||
* @param string $collaborator
|
||||
* @param string $permission
|
||||
* @return bool
|
||||
*/
|
||||
public function addCollaborator(string $owner, string $repositoryName, string $collaborator, string $permission = 'write'): bool
|
||||
{
|
||||
$options['json'] = [
|
||||
'permission' => $permission
|
||||
];
|
||||
|
||||
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/collaborators/' . $collaborator, 'PUT', $options);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $owner
|
||||
* @param string $repositoryName
|
||||
* @param string $collaborator
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteCollaborator(string $owner, string $repositoryName, string $collaborator): bool
|
||||
{
|
||||
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/collaborators/' . $collaborator, 'DELETE');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user