diff --git a/Classes/Client.php b/Classes/Client.php index 44fe0d3..031fc47 100644 --- a/Classes/Client.php +++ b/Classes/Client.php @@ -7,6 +7,7 @@ namespace Avency\Gitea; use Avency\Gitea\Endpoint\Admin; use Avency\Gitea\Endpoint\EndpointInterface; use Avency\Gitea\Endpoint\Miscellaneous; +use Avency\Gitea\Endpoint\Organizations; use Avency\Gitea\Endpoint\Repositories; use Exception; use Psr\Http\Message\ResponseInterface; @@ -16,6 +17,7 @@ use Psr\Http\Message\ResponseInterface; * * @method Admin admin() * @method Miscellaneous miscellaneous() + * @method Organizations organizations() * @method Repositories repositories() */ class Client diff --git a/Classes/Endpoint/Organizations.php b/Classes/Endpoint/Organizations.php new file mode 100644 index 0000000..13b62bf --- /dev/null +++ b/Classes/Endpoint/Organizations.php @@ -0,0 +1,41 @@ +client = $client; + } +} diff --git a/Classes/Endpoint/Organizations/HooksTrait.php b/Classes/Endpoint/Organizations/HooksTrait.php new file mode 100644 index 0000000..d508b53 --- /dev/null +++ b/Classes/Endpoint/Organizations/HooksTrait.php @@ -0,0 +1,111 @@ +client->request(self::BASE_URI . '/' . $organization . '/hooks'); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $organization + * @param string $type + * @param array $config + * @param bool|null $active + * @param string|null $branchFilter + * @param array|null $events + * @return array + */ + public function createHook( + string $organization, + 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 . '/' . $organization . '/hooks', 'POST', $options); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $organization + * @param int $id + * @return array + */ + public function getHook(string $organization, int $id): array + { + $response = $this->client->request(self::BASE_URI . '/' . $organization . '/hooks/' . $id); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $organization + * @param int $id + * @return bool + */ + public function deleteHook(string $organization, int $id): bool + { + $this->client->request(self::BASE_URI . '/' . $organization . '/hooks/' . $id, 'DELETE'); + + return true; + } + + /** + * @param string $organization + * @param int $id + * @param bool $active + * @param string|null $branchFilter + * @param array|null $config + * @param array|null $events + * @return array + */ + public function updateHook( + string $organization, + int $id, + bool $active, + string $branchFilter = null, + array $config = null, + array $events = null + ): array + { + $options['json'] = [ + 'active' => $active, + 'branch_filter' => $branchFilter, + 'config' => $config, + 'events' => $events, + ]; + $options['json'] = $this->removeNullValues($options['json']); + + $response = $this->client->request(self::BASE_URI . '/' . $organization . '/hooks/' . $id, 'PATCH', $options); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } +} diff --git a/Classes/Endpoint/Organizations/MembersTrait.php b/Classes/Endpoint/Organizations/MembersTrait.php new file mode 100644 index 0000000..ed5028e --- /dev/null +++ b/Classes/Endpoint/Organizations/MembersTrait.php @@ -0,0 +1,95 @@ +client->request(self::BASE_URI . '/' . $organization . '/members'); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $organization + * @param string $username + * @return bool + */ + public function checkMember(string $organization, string $username): bool + { + $this->client->request(self::BASE_URI . '/' . $organization . '/members/' . $username); + + return true; + } + + /** + * @param string $organization + * @param string $username + * @return bool + */ + public function deleteMember(string $organization, string $username): bool + { + $this->client->request(self::BASE_URI . '/' . $organization . '/members/' . $username, 'DELETE'); + + return true; + } + + /** + * @param string $organization + * @return array + */ + public function getPublicMembers(string $organization): array + { + $response = $this->client->request(self::BASE_URI . '/' . $organization . '/public_members'); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $organization + * @param string $username + * @return bool + */ + public function checkPublicMember(string $organization, string $username): bool + { + $this->client->request(self::BASE_URI . '/' . $organization . '/public_members/' . $username); + + return true; + } + + /** + * @param string $organization + * @param string $username + * @return bool + */ + public function addPublicMember(string $organization, string $username): bool + { + $this->client->request(self::BASE_URI . '/' . $organization . '/public_members/' . $username, 'PUT'); + + return true; + } + + /** + * @param string $organization + * @param string $username + * @return bool + */ + public function deletePublicMember(string $organization, string $username): bool + { + $this->client->request(self::BASE_URI . '/' . $organization . '/public_members/' . $username, 'DELETE'); + + return true; + } +} diff --git a/Classes/Endpoint/Organizations/OrganizationTrait.php b/Classes/Endpoint/Organizations/OrganizationTrait.php new file mode 100644 index 0000000..e6c2d71 --- /dev/null +++ b/Classes/Endpoint/Organizations/OrganizationTrait.php @@ -0,0 +1,106 @@ +client->request(self::BASE_URI . '/' . $organization); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $username + * @param string|null $description + * @param string|null $fullName + * @param string|null $location + * @param bool|null $repoAdminChangeTeamAccess + * @param string|null $visibility + * @param string|null $website + * @return array + */ + public function create( + string $username, + string $description = null, + string $fullName = null, + string $location = null, + bool $repoAdminChangeTeamAccess = null, + string $visibility = null, // public, limited, private + string $website = null + ): array + { + $options['json'] = [ + 'username' => $username, + 'description' => $description, + 'full_name' => $fullName, + 'location' => $location, + 'repo_admin_change_team_access' => $repoAdminChangeTeamAccess, + 'visibility' => $visibility, + 'website' => $website, + ]; + $options['json'] = $this->removeNullValues($options['json']); + + $response = $this->client->request(self::BASE_URI, 'POST', $options); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $organization + * @return bool + */ + public function delete(string $organization): bool + { + $this->client->request(self::BASE_URI . '/' . $organization, 'DELETE'); + + return true; + } + + /** + * @param string $organization + * @param string|null $description + * @param string|null $fullName + * @param string|null $location + * @param bool|null $repoAdminChangeTeamAccess + * @param string|null $visibility + * @param string|null $website + * @return array + */ + public function update( + string $organization, + string $description = null, + string $fullName = null, + string $location = null, + bool $repoAdminChangeTeamAccess = null, + string $visibility = null, // public, limited, private + string $website = null + ): array + { + $options['json'] = [ + 'description' => $description, + 'full_name' => $fullName, + 'location' => $location, + 'repo_admin_change_team_access' => $repoAdminChangeTeamAccess, + 'visibility' => $visibility, + 'website' => $website, + ]; + $options['json'] = $this->removeNullValues($options['json']); + + $response = $this->client->request(self::BASE_URI . '/' . $organization, 'PATCH', $options); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } +} diff --git a/Classes/Endpoint/Organizations/RepositoriesTrait.php b/Classes/Endpoint/Organizations/RepositoriesTrait.php new file mode 100644 index 0000000..44f4c96 --- /dev/null +++ b/Classes/Endpoint/Organizations/RepositoriesTrait.php @@ -0,0 +1,65 @@ +client->request(self::BASE_URI . '/' . $organization . '/repos'); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $organization + * @param string $name + * @param bool|null $autoInit + * @param string|null $description + * @param string|null $gitignores + * @param string|null $issueLabels + * @param string|null $license + * @param bool|null $private + * @param string|null $readme + * @return array + */ + public function createRepo( + string $organization, + 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('/org/' . $organization . '/repos', 'POST', $options); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } +} diff --git a/Classes/Endpoint/Organizations/TeamsTrait.php b/Classes/Endpoint/Organizations/TeamsTrait.php new file mode 100644 index 0000000..b0264c5 --- /dev/null +++ b/Classes/Endpoint/Organizations/TeamsTrait.php @@ -0,0 +1,229 @@ +client->request(self::BASE_URI . '/' . $organization . '/teams'); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $organization + * @param string $name + * @param bool|null $canCreateOrgRepo + * @param string|null $description + * @param bool|null $includesAllRepositories + * @param string|null $permission + * @param array|null $units + * @return array + */ + public function createTeam( + string $organization, + string $name, + bool $canCreateOrgRepo = null, + string $description = null, + bool $includesAllRepositories = null, + string $permission = null, // read, write, admin + array $units = null // repo.code, repo.issues, repo.ext_issues, repo.wiki, repo.pulls, repo.releases, repo.ext_wiki + ): array + { + $options['json'] = [ + 'name' => $name, + 'can_create_org_repo' => $canCreateOrgRepo, + 'description' => $description, + 'includes_all_repositories' => $includesAllRepositories, + 'permission' => $permission, + 'units' => $units, + ]; + $options['json'] = $this->removeNullValues($options['json']); + + $response = $this->client->request(self::BASE_URI . '/' . $organization . '/teams', 'POST', $options); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $organization + * @param string $searchTerm + * @param bool|null $includeDesc + * @param int|null $limit + * @param int|null $page + * @return array + */ + public function searchTeams( + string $organization, + string $searchTerm, + bool $includeDesc = null, + int $limit = null, + int $page = null + ): array + { + $options['query'] = [ + 'searchTerm' => $searchTerm, + 'includeDesc' => $includeDesc, + 'limit' => $limit, + 'page' => $page, + ]; + $options['query'] = $this->removeNullValues($options['query']); + + $response = $this->client->request(self::BASE_URI . '/' . $organization . '/teams/search', 'GET', $options); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param int $id + * @return array + */ + public function getTeam(int $id): array + { + $response = $this->client->request('/teams/' . $id); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param int $id + * @return bool + */ + public function deleteTeam(int $id): bool + { + $this->client->request('/teams/' . $id, 'DELETE'); + + return true; + } + + /** + * @param int $id + * @param string $name + * @param bool|null $canCreateOrgRepo + * @param string|null $description + * @param bool|null $includesAllRepositories + * @param string|null $permission + * @param array|null $units + * @return array + */ + public function updateTeam( + int $id, + string $name, + bool $canCreateOrgRepo = null, + string $description = null, + bool $includesAllRepositories = null, + string $permission = null, // read, write, admin + array $units = null // repo.code, repo.issues, repo.ext_issues, repo.wiki, repo.pulls, repo.releases, repo.ext_wiki + ): array + { + $options['json'] = [ + 'name' => $name, + 'can_create_org_repo' => $canCreateOrgRepo, + 'description' => $description, + 'includes_all_repositories' => $includesAllRepositories, + 'permission' => $permission, + 'units' => $units, + ]; + $options['json'] = $this->removeNullValues($options['json']); + + $response = $this->client->request('/teams/' . $id, 'PATCH', $options); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param int $id + * @return array + */ + public function getTeamMembers(int $id): array + { + $response = $this->client->request('/teams/' . $id . '/members'); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param int $id + * @param string $username + * @return array + */ + public function getTeamMember(int $id, string $username): array + { + $response = $this->client->request('/teams/' . $id . '/members/' . $username); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param int $id + * @param string $username + * @return bool + */ + public function addTeamMember(int $id, string $username): bool + { + $this->client->request('/teams/' . $id . '/members/' . $username, 'PUT'); + + return true; + } + + /** + * @param int $id + * @param string $username + * @return bool + */ + public function deleteTeamMember(int $id, string $username): bool + { + $this->client->request('/teams/' . $id . '/members/' . $username, 'DELETE'); + + return true; + } + + /** + * @param int $id + * @return array + */ + public function getTeamRepositories(int $id): array + { + $response = $this->client->request('/teams/' . $id . '/repos'); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param int $id + * @param $organization + * @param $repositoryName + * @return bool + */ + public function addTeamRepository(int $id, $organization, $repositoryName): bool + { + $this->client->request('/teams/' . $id . '/repos/' . $organization . '/' . $repositoryName, 'PUT'); + + return true; + } + + /** + * @param int $id + * @param $organization + * @param $repositoryName + * @return bool + */ + public function deleteTeamRepository(int $id, $organization, $repositoryName): bool + { + $this->client->request('/teams/' . $id . '/repos/' . $organization . '/' . $repositoryName, 'DELETE'); + + return true; + } +} diff --git a/Classes/Endpoint/Organizations/UsersTrait.php b/Classes/Endpoint/Organizations/UsersTrait.php new file mode 100644 index 0000000..929915e --- /dev/null +++ b/Classes/Endpoint/Organizations/UsersTrait.php @@ -0,0 +1,34 @@ +client->request('/user/orgs'); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } + + /** + * @param string $username + * @return array + */ + public function getUserOrganizations(string $username): array + { + $response = $this->client->request('/users/' . $username . '/orgs'); + + return \GuzzleHttp\json_decode($response->getBody(), true); + } +} diff --git a/Classes/Endpoint/Repositories/ForksTrait.php b/Classes/Endpoint/Repositories/ForksTrait.php index a4069d0..14f6647 100644 --- a/Classes/Endpoint/Repositories/ForksTrait.php +++ b/Classes/Endpoint/Repositories/ForksTrait.php @@ -26,13 +26,13 @@ trait ForksTrait /** * @param string $owner * @param string $repositoryName - * @param string|null $organisation + * @param string|null $organization * @return array */ - public function createFork(string $owner, string $repositoryName, string $organisation = null): array + public function createFork(string $owner, string $repositoryName, string $organization = null): array { $options['json'] = [ - 'organization' => $organisation + 'organization' => $organization ]; $options['json'] = $this->removeNullValues($options['json']); diff --git a/README.md b/README.md index 06704fd..851ae32 100644 --- a/README.md +++ b/README.md @@ -111,39 +111,39 @@ Status | Method | Endpoint | Comment Status | Method | Endpoint | Comment --- | --- | --- | --- -❌ | POST | /org/{org}/repos | -❌ | POST | /orgs | -❌ | GET | /orgs/{org} | -❌ | DELETE | /orgs/{org} | -❌ | PATCH | /orgs/{org} | -❌ | GET | /orgs/{org}/hooks | -❌ | POST | /orgs/{org}/hooks/ | -❌ | GET | /orgs/{org}/hooks/{id} | -❌ | DELETE | /orgs/{org}/hooks/{id} | -❌ | PATCH | /orgs/{org}/hooks/{id} | -❌ | GET | /orgs/{org}/members | -❌ | GET | /orgs/{org}/members/{username} | -❌ | DELETE | /orgs/{org}/members/{username} | -❌ | GET | /orgs/{org}/public_members | -❌ | GET | /orgs/{org}/public_members/{username} | -❌ | PUT | /orgs/{org}/public_members/{username} | -❌ | DELETE | /orgs/{org}/public_members/{username} | -❌ | GET | /orgs/{org}/repos | -❌ | GET | /orgs/{org}/teams | -❌ | POST | /orgs/{org}/teams | -❌ | GET | /orgs/{org}/teams/search | -❌ | GET | /teams/{id} | -❌ | DELETE | /teams/{id} | -❌ | PATCH | /teams/{id} | -❌ | GET | /teams/{id}/members | -❌ | GET | /teams/{id}/members/{username} | -❌ | PUT | /teams/{id}/members/{username} | -❌ | DELETE | /teams/{id}/members/{username} | -❌ | GET | /teams/{id}/repos | -❌ | PUT | /teams/{id}/repos/{org}/{repo} | -❌ | DELETE | /teams/{id}/repos/{org}/{repo} | -❌ | GET | /user/orgs | -❌ | GET | /users/{username}/orgs | +✅ | POST | /org/{org}/repos | +✅ | POST | /orgs | +✅ | GET | /orgs/{org} | +✅ | DELETE | /orgs/{org} | +✅ | PATCH | /orgs/{org} | +✅ | GET | /orgs/{org}/hooks | +✅ | POST | /orgs/{org}/hooks/ | +✅ | GET | /orgs/{org}/hooks/{id} | +✅ | DELETE | /orgs/{org}/hooks/{id} | +✅ | PATCH | /orgs/{org}/hooks/{id} | +✅ | GET | /orgs/{org}/members | +✅ | GET | /orgs/{org}/members/{username} | +✅ | DELETE | /orgs/{org}/members/{username} | +✅ | GET | /orgs/{org}/public_members | +✅ | GET | /orgs/{org}/public_members/{username} | +✅ | PUT | /orgs/{org}/public_members/{username} | +✅ | DELETE | /orgs/{org}/public_members/{username} | +✅ | GET | /orgs/{org}/repos | +✅ | GET | /orgs/{org}/teams | +✅ | POST | /orgs/{org}/teams | +✅ | GET | /orgs/{org}/teams/search | +✅ | GET | /teams/{id} | +✅ | DELETE | /teams/{id} | +✅ | PATCH | /teams/{id} | +✅ | GET | /teams/{id}/members | +✅ | GET | /teams/{id}/members/{username} | +✅ | PUT | /teams/{id}/members/{username} | +✅ | DELETE | /teams/{id}/members/{username} | +✅ | GET | /teams/{id}/repos | +✅ | PUT | /teams/{id}/repos/{org}/{repo} | +✅ | DELETE | /teams/{id}/repos/{org}/{repo} | +✅ | GET | /user/orgs | +✅ | GET | /users/{username}/orgs | #### Issue