From 64315d7145747008ad76a6a015ff0b7b4b2e5cd8 Mon Sep 17 00:00:00 2001 From: Benjamin Blake Date: Tue, 25 Feb 2020 12:13:05 -0700 Subject: [PATCH] Created two new API requester + Created a new Tags API requester to allow us to make tag related API requests + Created a new Branches API requester to allow us to make branch related API requests --- src/Api/Branches.php | 63 ++++++++++++++++++++++++++++++++++++++++++++ src/Api/Tags.php | 63 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 src/Api/Branches.php create mode 100644 src/Api/Tags.php diff --git a/src/Api/Branches.php b/src/Api/Branches.php new file mode 100644 index 0000000..5321963 --- /dev/null +++ b/src/Api/Branches.php @@ -0,0 +1,63 @@ +tags()->fromRepository("username", "test-repository"); + * + * // Get all tags from a repository owned by an organization + * $giteaClient->tags()->fromRepository("organizationName", "test-repository"); + * ``` + * + * @param string $owner The name of the user or organization that owns the repository + * @param string $repository The name of the repository + * @author Benjamin Blake (sitelease.ca) + * + * @return ApiItemCollection + */ + public function fromRepository(string $owner, string $repository) + { + $client = $this->getClient(); + + $repositoryCollection = new ApiItemCollection(); + try { + $response = $this->get("repos/$owner/$repository/branches"); + $statusCode = $response->getStatusCode(); + $body = $response->getBody(); + if ($statusCode == 200) { + $jsonItemList = json_decode($body, true); + if (count($jsonItemList) > 0) { + foreach ($jsonItemList as $jsonItem) { + $encodedItem = json_encode($jsonItem); + $itemObject = Branch::fromJson( + $this->getClient(), + $this, + json_decode($encodedItem) + ); + $repositoryCollection->addItem($itemObject, $itemObject->getName()); + } + } + } + return $repositoryCollection; + } catch (ServerException $serverError) { + return $repositoryCollection; + } + } + +} diff --git a/src/Api/Tags.php b/src/Api/Tags.php new file mode 100644 index 0000000..3551fa6 --- /dev/null +++ b/src/Api/Tags.php @@ -0,0 +1,63 @@ +tags()->fromRepository("username", "test-repository"); + * + * // Get all tags from a repository owned by an organization + * $giteaClient->tags()->fromRepository("organizationName", "test-repository"); + * ``` + * + * @param string $owner The name of the user or organization that owns the repository + * @param string $repository The name of the repository + * @author Benjamin Blake (sitelease.ca) + * + * @return ApiItemCollection + */ + public function fromRepository(string $owner, string $repository) + { + $client = $this->getClient(); + + $repositoryCollection = new ApiItemCollection(); + try { + $response = $this->get("repos/$owner/$repository/tags"); + $statusCode = $response->getStatusCode(); + $body = $response->getBody(); + if ($statusCode == 200) { + $jsonItemList = json_decode($body, true); + if (count($jsonItemList) > 0) { + foreach ($jsonItemList as $jsonItem) { + $encodedItem = json_encode($jsonItem); + $itemObject = Tag::fromJson( + $this->getClient(), + $this, + json_decode($encodedItem) + ); + $repositoryCollection->addItem($itemObject, $itemObject->getId()); + } + } + } + return $repositoryCollection; + } catch (ServerException $serverError) { + return $repositoryCollection; + } + } + +}