feat: add further Repo endpoints

This commit is contained in:
Michael Gerdemann
2020-01-19 11:06:00 +01:00
parent bfb83eb719
commit eeb2655889
19 changed files with 1779 additions and 221 deletions

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Branches Trait
*/
trait BranchesTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getBranches(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/branches');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param $branch
* @return array
*/
public function getBranche(string $owner, string $repositoryName, string $branch): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/branches/' . $branch);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
}

View 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;
}
}

View File

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Commits Trait
*/
trait CommitsTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @param string|null $sha
* @param int|null $page
* @return array
*/
public function getCommits(string $owner, string $repositoryName, string $sha = null, int $page = null): array
{
$options['query'] = [
'sha' => $sha,
'page' => $page
];
$options['query'] = $this->removeNullValues($options['query']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/commits', 'GET', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $ref
* @param int|null $page
* @return array
*/
public function getCommitStatuses(string $owner, string $repositoryName, string $ref, int $page = null): array
{
$options['query'] = [
'page' => $page
];
$options['query'] = $this->removeNullValues($options['query']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/commits/' . $ref . '/statuses', 'GET', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
}

View File

@ -0,0 +1,250 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Contents Trait
*/
trait ContentsTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @param string|null $ref
* @return array
*/
public function getContents(string $owner, string $repositoryName, string $ref = null): array
{
$options['query'] = [
'ref' => $ref
];
$options['query'] = $this->removeNullValues($options['query']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/contents');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $filepath
* @param string|null $ref
* @return array
*/
public function getContent(string $owner, string $repositoryName, string $filepath, string $ref = null): array
{
$options['query'] = [
'ref' => $ref
];
$options['query'] = $this->removeNullValues($options['query']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/contents/' . $filepath);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $filepath
* @param string $sha
* @param string $content
* @param string|null $authorEmail
* @param string|null $authorName
* @param string|null $branch
* @param string|null $committerEmail
* @param string|null $committerName
* @param \DateTime|null $authorDate
* @param \DateTime|null $committerDate
* @param string|null $message
* @param string|null $newBranch
* @return array
*/
public function updateContent(
string $owner,
string $repositoryName,
string $filepath,
string $sha,
string $content,
string $authorEmail = null,
string $authorName = null,
string $branch = null,
string $committerEmail = null,
string $committerName = null,
\DateTime $authorDate = null,
\DateTime $committerDate = null,
string $message = null,
string $newBranch = null
): array
{
$options['json'] = [
'sha' => $sha,
'content' => base64_encode($content),
'author' => [
'email' => $authorEmail,
'name' => $authorName,
],
'branch' => $branch,
'committer' => [
'email' => $committerEmail,
'name' => $committerName,
],
'dates' => [
'author' => $authorDate ? $authorDate->format(\DateTime::ATOM) : null,
'committer' => $committerDate ? $committerDate->format(\DateTime::ATOM) : null,
],
'message' => $message,
'new_branch' => $newBranch,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/contents/' . $filepath, 'PUT', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $filepath
* @param string $content
* @param string|null $authorEmail
* @param string|null $authorName
* @param string|null $branch
* @param string|null $committerEmail
* @param string|null $committerName
* @param \DateTime|null $authorDate
* @param \DateTime|null $committerDate
* @param string|null $message
* @param string|null $newBranch
* @return array
*/
public function addContent(
string $owner,
string $repositoryName,
string $filepath,
string $content,
string $authorEmail = null,
string $authorName = null,
string $branch = null,
string $committerEmail = null,
string $committerName = null,
\DateTime $authorDate = null,
\DateTime $committerDate = null,
string $message = null,
string $newBranch = null
): array
{
$options['json'] = [
'content' => base64_encode($content),
'author' => [
'email' => $authorEmail,
'name' => $authorName,
],
'branch' => $branch,
'committer' => [
'email' => $committerEmail,
'name' => $committerName,
],
'dates' => [
'author' => $authorDate ? $authorDate->format(\DateTime::ATOM) : null,
'committer' => $committerDate ? $committerDate->format(\DateTime::ATOM) : null,
],
'message' => $message,
'new_branch' => $newBranch,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/contents/' . $filepath, 'POST', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $filepath
* @param string $sha
* @param string $content
* @param string|null $authorEmail
* @param string|null $authorName
* @param string|null $branch
* @param string|null $committerEmail
* @param string|null $committerName
* @param \DateTime|null $authorDate
* @param \DateTime|null $committerDate
* @param string|null $message
* @param string|null $newBranch
* @return array
*/
public function deleteContent(
string $owner,
string $repositoryName,
string $filepath,
string $sha,
string $authorEmail = null,
string $authorName = null,
string $branch = null,
string $committerEmail = null,
string $committerName = null,
\DateTime $authorDate = null,
\DateTime $committerDate = null,
string $message = null,
string $newBranch = null
): array
{
$options['json'] = [
'sha' => $sha,
'author' => [
'email' => $authorEmail,
'name' => $authorName,
],
'branch' => $branch,
'committer' => [
'email' => $committerEmail,
'name' => $committerName,
],
'dates' => [
'author' => $authorDate ? $authorDate->format(\DateTime::ATOM) : null,
'committer' => $committerDate ? $committerDate->format(\DateTime::ATOM) : null,
],
'message' => $message,
'new_branch' => $newBranch,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/contents/' . $filepath, 'DELETE', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $filepath
* @return array
*/
public function getEditorConfig(string $owner, string $repositoryName, string $filepath): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/editorconfig/' . $filepath);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @return string
*/
public function getRawContent(string $owner, string $repositoryName, string $filepath): string
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/raw/' . $filepath);
return (string)$response->getBody();
}
}

View File

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Forks Trait
*/
trait ForksTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getForks(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/forks');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string|null $organisation
* @return array
*/
public function createFork(string $owner, string $repositoryName, string $organisation = null): array
{
$options['json'] = [
'organization' => $organisation
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/forks', 'POST', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
}

View File

@ -0,0 +1,107 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Git Trait
*/
trait GitTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @param string $sha
* @return array
*/
public function getBlob(string $owner, string $repositoryName, string $sha): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/git/blobs/' . $sha);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $sha
* @return array
*/
public function getCommit(string $owner, string $repositoryName, string $sha): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/git/commits/' . $sha);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getRefs(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/git/refs');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $ref
* @return array
*/
public function getRef(string $owner, string $repositoryName, string $ref): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/git/refs/' . $ref);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $sha
* @return array
*/
public function getTag(string $owner, string $repositoryName, string $sha): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/git/tags/' . $sha);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $sha
* @param bool|null $recursive
* @param int|null $page
* @param int|null $perPage
* @return array
*/
public function getTree(
string $owner,
string $repositoryName,
string $sha,
bool $recursive = null,
int $page = null,
int $perPage = null
): array
{
$options['query'] = [
'recursive' => $recursive,
'page' => $page,
'per_page' => $perPage,
];
$options['query'] = $this->removeNullValues($options['query']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/git/trees/' . $sha, 'GET', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
}

View File

@ -0,0 +1,191 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Hooks Trait
*/
trait HooksTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getHooks(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/hooks');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $type
* @param array $config
* @param bool|null $active
* @param string|null $branchFilter
* @param array|null $events
* @return array
*/
public function addHook(
string $owner,
string $repositoryName,
string $type,
array $config,
bool $active = null,
string $branchFilter = null,
array $events = null
): array
{
$options['json'] = [
'type' => $type,
'config' => $config,
'active' => $active,
'branch_filter' => $branchFilter,
'events' => $events,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/hooks', 'POST', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getGitHooks(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/hooks/git');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return array
*/
public function getGitHook(string $owner, string $repositoryName, int $id): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/hooks/git/' . $id);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return bool
*/
public function deleteGitHook(string $owner, string $repositoryName, int $id): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/hooks/git/' . $id, 'DELETE');
return true;
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @param string $content
* @return array
*/
public function updateGitHook(string $owner, string $repositoryName, int $id, string $content): array
{
$options['json'] = [
'content' => $content
];
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/hooks/git/' . $id, 'PATCH', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return array
*/
public function getHook(string $owner, string $repositoryName, int $id): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/hooks/' . $id);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return bool
*/
public function deleteHook(string $owner, string $repositoryName, int $id): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/hooks/' . $id, 'DELETE');
return true;
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @param array|null $config
* @param bool|null $active
* @param string|null $branchFilter
* @param array|null $events
* @return array
*/
public function updateHook(
string $owner,
string $repositoryName,
int $id,
array $config = null,
bool $active = null,
string $branchFilter = null,
array $events = null
): array
{
$options['json'] = [
'config' => $config,
'active' => $active,
'branch_filter' => $branchFilter,
'events' => $events,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/hooks/' . $id, 'PATCH', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return array
*/
public function testHook(
string $owner,
string $repositoryName,
int $id
): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/hooks/' . $id . '/tests', 'POST');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
}

View File

@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Keys Trait
*/
trait KeysTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @param int|null $keyId
* @param string|null $fingerprint
* @return array
*/
public function getKeys(string $owner, string $repositoryName, int $keyId = null, string $fingerprint = null): array
{
$options['query'] = [
'key_id' => $keyId,
'fingerprint' => $fingerprint
];
$options['query'] = $this->removeNullValues($options['query']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/keys', 'GET', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $title
* @param string $key
* @param bool|null $readOnly
* @return array
*/
public function addKey(
string $owner,
string $repositoryName,
string $title,
string $key,
bool $readOnly = null
): array
{
$options['json'] = [
'title' => $title,
'key' => $key,
'read_only' => $readOnly,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/keys', 'POST', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $keyId
* @return array
*/
public function getKey(string $owner, string $repositoryName, int $keyId): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/keys/' . $keyId);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $keyId
* @return bool
*/
public function deleteKey(string $owner, string $repositoryName, int $keyId): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/keys/' . $keyId, 'DELETE');
return true;
}
}

View File

@ -0,0 +1,205 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Pulls Trait
*/
trait PullsTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @param int|null $page
* @param string|null $state
* @param string|null $sort
* @param int|null $milestone
* @param array|null $lables
* @return array
*/
public function getPulls(
string $owner,
string $repositoryName,
int $page = null,
string $state = null,
string $sort = null,
int $milestone = null,
array $lables = null
): array
{
$options['query'] = [
'page' => $page,
'state' => $state,
'sort' => $sort,
'milestone' => $milestone,
'lables' => $lables,
];
$options['query'] = $this->removeNullValues($options['query']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/pulls', 'GET', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $assignee
* @param string $base
* @param string $head
* @param array|null $assignees
* @param string|null $title
* @param string|null $body
* @param \DateTime|null $dueDate
* @param array|null $labels
* @param int|null $milestone
* @return array
*/
public function createPull(
string $owner,
string $repositoryName,
string $assignee,
string $base,
string $head,
string $title,
array $assignees = null,
string $body = null,
\DateTime $dueDate = null,
array $labels = null,
int $milestone = null
): array
{
$options['json'] = [
'assignee' => $assignee,
'base' => $base,
'head' => $head,
'assignees' => $assignees,
'title' => $title,
'body' => $body,
'due_date' => $dueDate ? $dueDate->format(\DateTime::ATOM) : null,
'labels' => $labels,
'milestone' => $milestone,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/pulls', 'POST', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $index
* @return array
*/
public function getPull(
string $owner,
string $repositoryName,
int $index
): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/pulls/' . $index, 'GET');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $index
* @param string|null $assignee
* @param string|null $title
* @param string|null $state
* @param array|null $assignees
* @param string|null $body
* @param \DateTime|null $dueDate
* @param bool|null $unsetDueDate
* @param array|null $labels
* @param int|null $milestone
* @return array
*/
public function updatePull(
string $owner,
string $repositoryName,
int $index,
string $assignee = null,
string $title = null,
string $state = null,
array $assignees = null,
string $body = null,
\DateTime $dueDate = null,
bool $unsetDueDate = null,
array $labels = null,
int $milestone = null
): array
{
$options['json'] = [
'assignee' => $assignee,
'assignees' => $assignees,
'title' => $title,
'state' => $state,
'body' => $body,
'due_date' => $dueDate ? $dueDate->format(\DateTime::ATOM) : null,
'unsetDueDate' => $unsetDueDate,
'labels' => $labels,
'milestone' => $milestone,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/pulls/' . $index, 'PATCH', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $index
* @return bool
*/
public function checkMerged(
string $owner,
string $repositoryName,
int $index
): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/pulls/' . $index . '/merge', 'GET');
return true;
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $index
* @param string $do
* @param string|null $mergeMessage
* @param string|null $mergeTitle
* @return bool
*/
public function mergePull(
string $owner,
string $repositoryName,
int $index,
string $do,
string $mergeMessage = null,
string $mergeTitle = null
): bool
{
$options['json'] = [
'Do' => $do,
'MergeMessageField' => $mergeMessage,
'MergeTitleField' => $mergeTitle,
];
$options['json'] = $this->removeNullValues($options['json']);
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/pulls/' . $index . '/merge', 'POST', $options);
return true;
}
}

View File

@ -0,0 +1,184 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Releases Trait
*/
trait ReleasesTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getReleases(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/releases');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $tagName
* @param string|null $body
* @param bool|null $draft
* @param string|null $name
* @param bool|null $prerelease
* @param string|null $targetCommitish
* @return array
*/
public function createRelease(
string $owner,
string $repositoryName,
string $tagName,
string $body = null,
bool $draft = null,
string $name = null,
bool $prerelease = null,
string $targetCommitish = null
): array
{
$options['json'] = [
'tag_name' => $tagName,
'body' => $body,
'draft' => $draft,
'name' => $name,
'prerelease' => $prerelease,
'target_commitish' => $targetCommitish,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/releases', 'POST', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return array
*/
public function getRelease(string $owner, string $repositoryName, int $id): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/releases/' . $id);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return bool
*/
public function deleteRelease(string $owner, string $repositoryName, int $id): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/releases/' . $id, 'DELETE');
return true;
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @param string|null $tagName
* @param string|null $body
* @param bool|null $draft
* @param string|null $name
* @param bool|null $prerelease
* @param string|null $targetCommitish
* @return array
*/
public function updateRelease(
string $owner,
string $repositoryName,
int $id,
string $tagName = null,
string $body = null,
bool $draft = null,
string $name = null,
bool $prerelease = null,
string $targetCommitish = null
): array
{
$options['json'] = [
'tag_name' => $tagName,
'body' => $body,
'draft' => $draft,
'name' => $name,
'prerelease' => $prerelease,
'target_commitish' => $targetCommitish,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/releases/' . $id, 'PATCH', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return array
*/
public function getReleaseAssets(string $owner, string $repositoryName, int $id): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/releases/' . $id . '/assets');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return array
*/
public function getReleaseAsset(string $owner, string $repositoryName, int $id, int $assetId): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/releases/' . $id . '/assets/' . $assetId);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @return bool
*/
public function deleteReleaseAsset(string $owner, string $repositoryName, int $id, int $assetId): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/releases/' . $id . '/assets/' . $assetId, 'DELETE');
return true;
}
/**
* @param string $owner
* @param string $repositoryName
* @param int $id
* @param string $name
* @return array
*/
public function updateReleaseAsset(string $owner, string $repositoryName, int $id, int $assetId, string $name): array
{
$options['json'] = [
'name' => $name
];
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/releases/' . $id . '/assets/' . $assetId, 'PATCH', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
}

View File

@ -248,4 +248,116 @@ trait RepositoryTrait
return true;
}
/**
* @param string $owner
* @param string $repositoryName
* @return string
*/
public function getSigningKeyGPG(string $owner, string $repositoryName): string
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/signing-key.gpg');
return (string)$response->getBody();
}
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getStargazers(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/stargazers');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getTags(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/tags');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getTimes(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/times');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param int $id
* @return array
*/
public function getById(int $id): array
{
$response = $this->client->request('/repositories/' . $id);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $searchTerm
* @return array
*/
public function topicsSearch(string $searchTerm): array
{
$options['query'] = [
'q' => $searchTerm
];
$response = $this->client->request('/topics/search', 'GET', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $name
* @param bool $autoInit
* @param string $description
* @param string $gitignores
* @param string $issueLabels
* @param string $license
* @param bool $private
* @param string $readme
* @return array
*/
public function create(
string $name,
bool $autoInit = null,
string $description = null,
string $gitignores = null,
string $issueLabels = null,
string $license = null,
bool $private = null,
string $readme = null
): array
{
$options['json'] = [
'name' => $name,
'auto_init' => $autoInit,
'description' => $description,
'gitignores' => $gitignores,
'issue_labels' => $issueLabels,
'license' => $license,
'private' => $private,
'readme' => $readme,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request('/user/repos', 'POST', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
}

View File

@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Statuses Trait
*/
trait StatusesTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @param string $sha
* @param int|null $page
* @param int|null $sort
* @param int|null $state
* @return array
*/
public function getStatuses(
string $owner,
string $repositoryName,
string $sha,
int $page = null,
int $sort = null,
int $state = null
): array
{
$options['query'] = [
'page' => $page,
'sort' => $sort,
'state' => $state,
];
$options['query'] = $this->removeNullValues($options['query']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/statuses/' . $sha, 'GET', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $sha
* @param string $state // pending, success, error, failure, warning
* @param string|null $description
* @param string|null $context
* @param string|null $targetUrl
* @return array
*/
public function createStatus(
string $owner,
string $repositoryName,
string $sha,
string $state,
string $description = null,
string $context = null,
string $targetUrl = null
): array
{
$options['json'] = [
'state' => $state,
'description' => $description,
'context' => $context,
'target_url' => $targetUrl,
];
$options['json'] = $this->removeNullValues($options['json']);
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/statuses/' . $sha, 'POST', $options);
return \GuzzleHttp\json_decode($response->getBody(), true);
}
}

View File

@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Subscription Trait
*/
trait SubscriptionTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getSubscribers(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/subscribers');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function checkSubscription(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/subscription');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function addSubscription(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/subscription', 'PUT');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @return bool
*/
public function deleteSubscription(string $owner, string $repositoryName): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/subscription', 'DELETE');
return true;
}
}

View File

@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace Avency\Gitea\Endpoint\Repositories;
use Avency\Gitea\Client;
/**
* Repositories Topics Trait
*/
trait TopicsTrait
{
/**
* @param string $owner
* @param string $repositoryName
* @return array
*/
public function getTopics(string $owner, string $repositoryName): array
{
$response = $this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/topics');
return \GuzzleHttp\json_decode($response->getBody(), true);
}
/**
* @param string $owner
* @param string $repositoryName
* @param array $topics
* @return bool
*/
public function replaceTopics(string $owner, string $repositoryName, array $topics): bool
{
$options['json'] = [
'topics' => $topics
];
$options['json'] = $this->removeNullValues($options['json']);
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/topics', 'PUT', $options);
return true;
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $topic
* @return bool
*/
public function addTopic(string $owner, string $repositoryName, string $topic): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/topics/' . $topic, 'PUT');
return true;
}
/**
* @param string $owner
* @param string $repositoryName
* @param string $topic
* @return bool
*/
public function deleteTopic(string $owner, string $repositoryName, string $topic): bool
{
$this->client->request(self::BASE_URI . '/' . $owner . '/' . $repositoryName . '/topics/' . $topic, 'DELETE');
return true;
}
}