Release of v4.1.1-beta2
Adds new JCB package engine. Fix issue with loading the Component Builder Wiki. Adds advanced version update notice to the Component Builder Dashboard. Completely refactors the class that builds the Component Dashboard. #1134. Adds Initialize, Reset, and Push functionality to the Repository entities. Completely refactors the SQL teaks and SQL dump classes. Changes J4 fields to allow NULL. Fix a bug in Dynamic Get JavaScript that causes table columns to not load.
This commit is contained in:
1
libraries/vendor_jcb/VDM.Joomla.Github/index.html
Normal file
1
libraries/vendor_jcb/VDM.Joomla.Github/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
158
libraries/vendor_jcb/VDM.Joomla.Github/src/Abstraction/Api.php
Normal file
158
libraries/vendor_jcb/VDM.Joomla.Github/src/Abstraction/Api.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Github\Abstraction;
|
||||
|
||||
|
||||
use VDM\Joomla\Github\Utilities\Http;
|
||||
use VDM\Joomla\Github\Utilities\Uri;
|
||||
use VDM\Joomla\Github\Utilities\Response;
|
||||
use VDM\Joomla\Interfaces\Git\ApiInterface;
|
||||
|
||||
|
||||
/**
|
||||
* The Github Api
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
abstract class Api implements ApiInterface
|
||||
{
|
||||
/**
|
||||
* The Http class
|
||||
*
|
||||
* @var Http
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Http $http;
|
||||
|
||||
/**
|
||||
* The Uri class
|
||||
*
|
||||
* @var Uri
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Uri $uri;
|
||||
|
||||
/**
|
||||
* The Response class
|
||||
*
|
||||
* @var Response
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Response $response;
|
||||
|
||||
/**
|
||||
* The Url string
|
||||
*
|
||||
* @var string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?string $url = null;
|
||||
|
||||
/**
|
||||
* The token string
|
||||
*
|
||||
* @var string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?string $token = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Http $http The http class.
|
||||
* @param Uri $uri The uri class.
|
||||
* @param Response $response The response class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function __construct(Http $http, Uri $uri, Response $response)
|
||||
{
|
||||
$this->http = $http;
|
||||
$this->uri = $uri;
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load/Reload API.
|
||||
*
|
||||
* @param string|null $url The url.
|
||||
* @param token|null $token The token.
|
||||
* @param bool $backup The backup swapping switch.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function load_(?string $url = null, ?string $token = null, bool $backup = true): void
|
||||
{
|
||||
// we keep the old values
|
||||
// so we can reset after our call
|
||||
// for the rest of the container
|
||||
if ($backup)
|
||||
{
|
||||
// Github has only one URL
|
||||
// if ($url !== null)
|
||||
// {
|
||||
// $this->url = $this->uri->getUrl();
|
||||
// }
|
||||
|
||||
if ($token !== null)
|
||||
{
|
||||
$this->token = $this->http->getToken();
|
||||
}
|
||||
}
|
||||
|
||||
// Github has only one URL
|
||||
// if ($url !== null)
|
||||
// {
|
||||
// $this->uri->setUrl($url);
|
||||
// }
|
||||
|
||||
if ($token !== null)
|
||||
{
|
||||
$this->http->setToken($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset to previous toke, url it set
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function reset_(): void
|
||||
{
|
||||
// Github has only one URL
|
||||
// if ($this->url !== null)
|
||||
// {
|
||||
// $this->uri->setUrl($this->url);
|
||||
// $this->url = null;
|
||||
// }
|
||||
|
||||
if ($this->token !== null)
|
||||
{
|
||||
$this->http->setToken($this->token);
|
||||
$this->token = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the API url
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function api()
|
||||
{
|
||||
return $this->uri->api();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
51
libraries/vendor_jcb/VDM.Joomla.Github/src/Factory.php
Normal file
51
libraries/vendor_jcb/VDM.Joomla.Github/src/Factory.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Github;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use VDM\Joomla\Github\Service\Utilities;
|
||||
use VDM\Joomla\Componentbuilder\Power\Service\Github;
|
||||
use VDM\Joomla\Interfaces\FactoryInterface;
|
||||
use VDM\Joomla\Abstraction\Factory as ExtendingFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Github Factory
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
abstract class Factory extends ExtendingFactory implements FactoryInterface
|
||||
{
|
||||
/**
|
||||
* Package Container
|
||||
*
|
||||
* @var Container|null
|
||||
* @since 5.0.3
|
||||
**/
|
||||
protected static ?Container $container = null;
|
||||
|
||||
/**
|
||||
* Create a container object
|
||||
*
|
||||
* @return Container
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected static function createContainer(): Container
|
||||
{
|
||||
return (new Container())
|
||||
->registerServiceProvider(new Utilities())
|
||||
->registerServiceProvider(new Github());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,482 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Github\Repository;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\Git\Repository\ContentsInterface;
|
||||
use VDM\Joomla\Github\Abstraction\Api;
|
||||
|
||||
|
||||
/**
|
||||
* The Github Repository Contents
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
final class Contents extends Api implements ContentsInterface
|
||||
{
|
||||
/**
|
||||
* Get a file from a repository.
|
||||
*
|
||||
* @param string $owner The owner name.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $filepath The file path.
|
||||
* @param string|null $ref Optional. The name of the commit/branch/tag.
|
||||
* Default the repository's default branch (usually master).
|
||||
*
|
||||
* @return mixed
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function get(string $owner, string $repo, string $filepath, ?string $ref = null)
|
||||
{
|
||||
// Build the request path.
|
||||
$path = "/repos/{$owner}/{$repo}/contents/{$filepath}";
|
||||
|
||||
// Get the URI with the specified path.
|
||||
$uri = $this->uri->get($path);
|
||||
|
||||
// Add the ref parameter if provided.
|
||||
if ($ref !== null)
|
||||
{
|
||||
$uri->setVar('ref', $ref);
|
||||
}
|
||||
|
||||
// Send the get request.
|
||||
return $this->response->get(
|
||||
$this->http->raw()->get($uri)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metadata and contents (if a file) of an entry in a repository,
|
||||
* or a list of entries if a directory.
|
||||
*
|
||||
* @param string $owner The owner name.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $filepath The file or directory path.
|
||||
* @param string|null $ref Optional. The name of the commit/branch/tag.
|
||||
* Default the repository's default branch (usually master).
|
||||
*
|
||||
* @return null|array|object
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function metadata(string $owner, string $repo, string $filepath, ?string $ref = null): null|array|object
|
||||
{
|
||||
// Build the request path.
|
||||
$path = "/repos/{$owner}/{$repo}/contents/{$filepath}";
|
||||
|
||||
// Get the URI with the specified path.
|
||||
$uri = $this->uri->get($path);
|
||||
|
||||
// Add the ref parameter if provided.
|
||||
if ($ref !== null)
|
||||
{
|
||||
$uri->setVar('ref', $ref);
|
||||
}
|
||||
|
||||
// Send the get request.
|
||||
return $this->response->get(
|
||||
$this->http->json()->get($uri)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a file in a repository.
|
||||
*
|
||||
* @param string $owner The owner name.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $filepath The file path.
|
||||
* @param string $content The file content.
|
||||
* @param string $message The commit message.
|
||||
* @param string $branch The branch name. Defaults to the repository's default branch.
|
||||
* @param string|null $authorName The author's name.
|
||||
* @param string|null $authorEmail The author's email.
|
||||
* @param string|null $committerName The committer's name.
|
||||
* @param string|null $committerEmail The committer's email.
|
||||
* @param string|null $newBranch Whether to create a new branch. Defaults to null.
|
||||
* @param string|null $authorDate The author's date.
|
||||
* @param string|null $committerDate The committer's date.
|
||||
* @param bool|null $signoff Add a Signed-off-by trailer. Defaults to null.
|
||||
*
|
||||
* @return object|null
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function create(
|
||||
string $owner,
|
||||
string $repo,
|
||||
string $filepath,
|
||||
string $content,
|
||||
string $message,
|
||||
string $branch = 'master',
|
||||
?string $authorName = null,
|
||||
?string $authorEmail = null,
|
||||
?string $committerName = null,
|
||||
?string $committerEmail = null,
|
||||
?string $newBranch = null,
|
||||
?string $authorDate = null,
|
||||
?string $committerDate = null,
|
||||
?bool $signoff = null
|
||||
): ?object {
|
||||
// Build the request path.
|
||||
$path = "/repos/{$owner}/{$repo}/contents/{$filepath}";
|
||||
|
||||
// Set the post data
|
||||
$data = new \stdClass();
|
||||
$data->content = base64_encode($content);
|
||||
$data->message = $message;
|
||||
$data->branch = $branch;
|
||||
|
||||
if ($authorName !== null || $authorEmail !== null)
|
||||
{
|
||||
$data->author = new \stdClass();
|
||||
if ($authorName !== null)
|
||||
{
|
||||
$data->author->name = $authorName;
|
||||
}
|
||||
if ($authorEmail !== null)
|
||||
{
|
||||
$data->author->email = $authorEmail;
|
||||
}
|
||||
}
|
||||
|
||||
if ($committerName !== null || $committerEmail !== null)
|
||||
{
|
||||
$data->committer = new \stdClass();
|
||||
if ($committerName !== null)
|
||||
{
|
||||
$data->committer->name = $committerName;
|
||||
}
|
||||
if ($committerEmail !== null)
|
||||
{
|
||||
$data->committer->email = $committerEmail;
|
||||
}
|
||||
}
|
||||
|
||||
if ($newBranch !== null)
|
||||
{
|
||||
$data->new_branch = $newBranch;
|
||||
}
|
||||
|
||||
if ($authorDate !== null || $committerDate !== null)
|
||||
{
|
||||
$data->dates = new \stdClass();
|
||||
if ($authorDate !== null)
|
||||
{
|
||||
$data->dates->author = $authorDate;
|
||||
}
|
||||
if ($committerDate !== null)
|
||||
{
|
||||
$data->dates->committer = $committerDate;
|
||||
}
|
||||
}
|
||||
|
||||
if ($signoff !== null)
|
||||
{
|
||||
$data->signoff = $signoff;
|
||||
}
|
||||
|
||||
// Send the post request.
|
||||
return $this->response->get(
|
||||
$this->http->json()->put(
|
||||
$this->uri->get($path), json_encode($data)
|
||||
), 201
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the metadata of all the entries of the root directory.
|
||||
*
|
||||
* @param string $owner The owner name.
|
||||
* @param string $repo The repository name.
|
||||
* @param string|null $ref The name of the commit/branch/tag. Default the repository's default branch (usually master).
|
||||
*
|
||||
* @return array|null
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function root(string $owner, string $repo, ?string $ref = null): ?array
|
||||
{
|
||||
return $this->metadata($owner, $repo, '', $ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a file in a repository.
|
||||
*
|
||||
* @param string $owner The owner name.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $filepath The file path.
|
||||
* @param string $content The file content.
|
||||
* @param string $message The commit message.
|
||||
* @param string $sha The blob SHA of the file.
|
||||
* @param string $branch The branch name. Defaults to the repository's default branch.
|
||||
* @param string|null $authorName The author name. Defaults to the authenticated user.
|
||||
* @param string|null $authorEmail The author email. Defaults to the authenticated user.
|
||||
* @param string|null $committerName The committer name. Defaults to the authenticated user.
|
||||
* @param string|null $committerEmail The committer email. Defaults to the authenticated user.
|
||||
* @param string|null $authorDate The author date.
|
||||
* @param string|null $committerDate The committer date.
|
||||
* @param string|null $fromPath The original file path to move/rename.
|
||||
* @param string|null $newBranch The new branch to create from the specified branch.
|
||||
* @param bool|null $signoff Add a Signed-off-by trailer.
|
||||
*
|
||||
* @return object|null
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function update(
|
||||
string $owner,
|
||||
string $repo,
|
||||
string $filepath,
|
||||
string $content,
|
||||
string $message,
|
||||
string $sha,
|
||||
string $branch = 'master',
|
||||
?string $authorName = null,
|
||||
?string $authorEmail = null,
|
||||
?string $committerName = null,
|
||||
?string $committerEmail = null,
|
||||
?string $authorDate = null,
|
||||
?string $committerDate = null,
|
||||
?string $fromPath = null,
|
||||
?string $newBranch = null,
|
||||
?bool $signoff = null
|
||||
): ?object {
|
||||
// Build the request path.
|
||||
$path = "/repos/{$owner}/{$repo}/contents/{$filepath}";
|
||||
|
||||
// Set the file data.
|
||||
$data = new \stdClass();
|
||||
$data->content = base64_encode($content);
|
||||
$data->message = $message;
|
||||
$data->branch = $branch;
|
||||
$data->sha = $sha;
|
||||
|
||||
if ($authorName !== null || $authorEmail !== null)
|
||||
{
|
||||
$data->author = new \stdClass();
|
||||
|
||||
if ($authorName !== null)
|
||||
{
|
||||
$data->author->name = $authorName;
|
||||
}
|
||||
|
||||
if ($authorEmail !== null)
|
||||
{
|
||||
$data->author->email = $authorEmail;
|
||||
}
|
||||
}
|
||||
|
||||
if ($committerName !== null || $committerEmail !== null)
|
||||
{
|
||||
$data->committer = new \stdClass();
|
||||
|
||||
if ($committerName !== null)
|
||||
{
|
||||
$data->committer->name = $committerName;
|
||||
}
|
||||
|
||||
if ($committerEmail !== null)
|
||||
{
|
||||
$data->committer->email = $committerEmail;
|
||||
}
|
||||
}
|
||||
|
||||
if ($authorDate !== null || $committerDate !== null)
|
||||
{
|
||||
$data->dates = new \stdClass();
|
||||
|
||||
if ($authorDate !== null)
|
||||
{
|
||||
$data->dates->author = $authorDate;
|
||||
}
|
||||
|
||||
if ($committerDate !== null)
|
||||
{
|
||||
$data->dates->committer = $committerDate;
|
||||
}
|
||||
}
|
||||
|
||||
if ($fromPath !== null)
|
||||
{
|
||||
$data->from_path = $fromPath;
|
||||
}
|
||||
|
||||
if ($newBranch !== null)
|
||||
{
|
||||
$data->new_branch = $newBranch;
|
||||
}
|
||||
|
||||
if ($signoff !== null)
|
||||
{
|
||||
$data->signoff = $signoff;
|
||||
}
|
||||
|
||||
// Send the put request.
|
||||
return $this->response->get(
|
||||
$this->http->json()->put(
|
||||
$this->uri->get($path),
|
||||
json_encode($data)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a file in a repository.
|
||||
*
|
||||
* @param string $owner The owner name.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $filepath The file path.
|
||||
* @param string $message The commit message.
|
||||
* @param string $sha The blob SHA of the file.
|
||||
* @param string|null $branch The branch name (optional).
|
||||
* @param string|null $authorName The author name (optional).
|
||||
* @param string|null $authorEmail The author email (optional).
|
||||
* @param string|null $committerName The committer name (optional).
|
||||
* @param string|null $committerEmail The committer email (optional).
|
||||
* @param string|null $authorDate The author date (optional).
|
||||
* @param string|null $committerDate The committer date (optional).
|
||||
* @param string|null $newBranch The new branch name (optional).
|
||||
* @param bool|null $signoff Add a Signed-off-by trailer (optional).
|
||||
*
|
||||
* @return object|null
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function delete(
|
||||
string $owner,
|
||||
string $repo,
|
||||
string $filepath,
|
||||
string $message,
|
||||
string $sha,
|
||||
?string $branch = null,
|
||||
?string $authorName = null,
|
||||
?string $authorEmail = null,
|
||||
?string $committerName = null,
|
||||
?string $committerEmail = null,
|
||||
?string $authorDate = null,
|
||||
?string $committerDate = null,
|
||||
?string $newBranch = null,
|
||||
?bool $signoff = null
|
||||
): ?object {
|
||||
// Build the request path.
|
||||
$path = "/repos/{$owner}/{$repo}/contents/{$filepath}";
|
||||
|
||||
// Set the file data.
|
||||
$data = new \stdClass();
|
||||
$data->message = $message;
|
||||
$data->sha = $sha;
|
||||
|
||||
if ($branch !== null) {
|
||||
$data->branch = $branch;
|
||||
}
|
||||
|
||||
if ($authorName !== null || $authorEmail !== null)
|
||||
{
|
||||
$data->author = new \stdClass();
|
||||
|
||||
if ($authorName !== null)
|
||||
{
|
||||
$data->author->name = $authorName;
|
||||
}
|
||||
|
||||
if ($authorEmail !== null)
|
||||
{
|
||||
$data->author->email = $authorEmail;
|
||||
}
|
||||
}
|
||||
|
||||
if ($committerName !== null || $committerEmail !== null)
|
||||
{
|
||||
$data->committer = new \stdClass();
|
||||
|
||||
if ($committerName !== null)
|
||||
{
|
||||
$data->committer->name = $committerName;
|
||||
}
|
||||
|
||||
if ($committerEmail !== null)
|
||||
{
|
||||
$data->committer->email = $committerEmail;
|
||||
}
|
||||
}
|
||||
|
||||
if ($authorDate !== null || $committerDate !== null)
|
||||
{
|
||||
$data->dates = new \stdClass();
|
||||
|
||||
if ($authorDate !== null)
|
||||
{
|
||||
$data->dates->author = $authorDate;
|
||||
}
|
||||
|
||||
if ($committerDate !== null)
|
||||
{
|
||||
$data->dates->committer = $committerDate;
|
||||
}
|
||||
}
|
||||
|
||||
if ($newBranch !== null)
|
||||
{
|
||||
$data->new_branch = $newBranch;
|
||||
}
|
||||
|
||||
if ($signoff !== null)
|
||||
{
|
||||
$data->signoff = $signoff;
|
||||
}
|
||||
|
||||
// Send the delete request.
|
||||
return $this->response->get(
|
||||
$this->http->json()->delete(
|
||||
$this->uri->get($path), [], null,
|
||||
json_encode($data)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the EditorConfig definitions of a file in a repository.
|
||||
*
|
||||
* @param string $owner The owner name.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $filepath The file path.
|
||||
* @param string|null $ref The name of the commit/branch/tag.
|
||||
*
|
||||
* @return string|null
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function editor(string $owner, string $repo, string $filepath, string $ref = null): ?string
|
||||
{
|
||||
// Not supported in GitHub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blob of a repository.
|
||||
*
|
||||
* @param string $owner The owner name.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $sha The SHA hash of the blob.
|
||||
*
|
||||
* @return object|null
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function blob(string $owner, string $repo, string $sha): ?object
|
||||
{
|
||||
// Build the request path.
|
||||
$path = "/repos/{$owner}/{$repo}/git/blobs/{$sha}";
|
||||
|
||||
// Send the get request.
|
||||
return $this->response->get(
|
||||
$this->http->json()->get(
|
||||
$this->uri->get($path)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
186
libraries/vendor_jcb/VDM.Joomla.Github/src/Repository/Tags.php
Normal file
186
libraries/vendor_jcb/VDM.Joomla.Github/src/Repository/Tags.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Github\Repository;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\Git\Repository\TagsInterface;
|
||||
use VDM\Joomla\Github\Abstraction\Api;
|
||||
|
||||
|
||||
/**
|
||||
* The Github Repository Tags
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
final class Tags extends Api implements TagsInterface
|
||||
{
|
||||
/**
|
||||
* List a repository's tags
|
||||
*
|
||||
* @param string $owner The owner of the repo.
|
||||
* @param string $repo The name of the repo.
|
||||
* @param int|null $page The page number of results to return (1-based).
|
||||
* @param int|null $limit The page size of results. GitHub default is 30, max 100. Here we fix it to 10.
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function list(
|
||||
string $owner,
|
||||
string $repo,
|
||||
?int $page = 1,
|
||||
?int $limit = 10
|
||||
): ?array {
|
||||
$path = "/repos/{$owner}/{$repo}/tags";
|
||||
$uri = $this->uri->get($path);
|
||||
|
||||
$uri->setVar('page', $page ?? 1);
|
||||
$uri->setVar('per_page', $limit ?? 10);
|
||||
|
||||
return $this->response->get(
|
||||
$this->http->get($uri)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tag object by tag name (loop until found or exhausted).
|
||||
*
|
||||
* @param string $owner The owner name.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $tag The tag name to find.
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $owner, string $repo, string $tag): ?object
|
||||
{
|
||||
$page = 1;
|
||||
$limit = 10;
|
||||
|
||||
do {
|
||||
$tags = $this->list($owner, $repo, $page, $limit);
|
||||
|
||||
if (empty($tags))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($tags as $entry)
|
||||
{
|
||||
if (isset($entry->name) && $entry->name === $tag)
|
||||
{
|
||||
return $entry;
|
||||
}
|
||||
}
|
||||
|
||||
$page++;
|
||||
} while (count($tags) === $limit);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the annotated tag object by SHA.
|
||||
*
|
||||
* @param string $owner The owner of the repo.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $sha The tag object SHA.
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function sha(string $owner, string $repo, string $sha): ?object
|
||||
{
|
||||
$path = "/repos/{$owner}/{$repo}/git/tags/{$sha}";
|
||||
return $this->response->get(
|
||||
$this->http->get($this->uri->get($path))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new annotated tag and attach it to the repository.
|
||||
*
|
||||
* GitHub requires two steps to create a tag:
|
||||
* 1. Create an annotated tag object.
|
||||
* 2. Create a reference to the tag under `refs/tags/*`.
|
||||
*
|
||||
* @param string $owner The owner of the repo.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $tagName The name of the tag.
|
||||
* @param string $target The SHA the tag points to (usually a commit SHA).
|
||||
* @param string $message The tag message.
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function create(string $owner, string $repo, string $tagName, string $target, string $message): ?object
|
||||
{
|
||||
// Step 1: Create the tag object
|
||||
$tagObject = (object) [
|
||||
'tag' => $tagName,
|
||||
'message' => $message,
|
||||
'object' => $target,
|
||||
'type' => 'commit'
|
||||
];
|
||||
|
||||
$tagResponse = $this->response->get(
|
||||
$this->http->post(
|
||||
$this->uri->get("/repos/{$owner}/{$repo}/git/tags"),
|
||||
json_encode($tagObject)
|
||||
)
|
||||
);
|
||||
|
||||
if (!isset($tagResponse->sha))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Step 2: Create the ref pointing to the tag object
|
||||
$refData = (object) [
|
||||
'ref' => "refs/tags/{$tagName}",
|
||||
'sha' => $tagResponse->sha
|
||||
];
|
||||
|
||||
return $this->response->get(
|
||||
$this->http->post(
|
||||
$this->uri->get("/repos/{$owner}/{$repo}/git/refs"),
|
||||
json_encode($refData)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a tag reference by tag name.
|
||||
*
|
||||
* GitHub deletes tags via refs.
|
||||
*
|
||||
* @param string $owner The owner name.
|
||||
* @param string $repo The repository name.
|
||||
* @param string $tag The tag name to delete.
|
||||
*
|
||||
* @return string Returns 'success' on successful deletion.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function delete(string $owner, string $repo, string $tag): string
|
||||
{
|
||||
$path = "/repos/{$owner}/{$repo}/git/refs/tags/{$tag}";
|
||||
|
||||
return $this->response->get(
|
||||
$this->http->delete(
|
||||
$this->uri->get($path)
|
||||
),
|
||||
204,
|
||||
'success'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
166
libraries/vendor_jcb/VDM.Joomla.Github/src/Repository/Wiki.php
Normal file
166
libraries/vendor_jcb/VDM.Joomla.Github/src/Repository/Wiki.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Github\Repository;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\Git\Repository\WikiInterface;
|
||||
use VDM\Joomla\Github\Abstraction\Api;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
|
||||
/**
|
||||
* The Github Repository Wiki
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
class Wiki extends Api implements WikiInterface
|
||||
{
|
||||
/**
|
||||
* Create a new wiki page or update it if it already exists.
|
||||
*
|
||||
* @param string $owner Repository owner (user or organization).
|
||||
* @param string $repo Repository name (without `.wiki`).
|
||||
* @param string $title Title of the wiki page.
|
||||
* @param string $contentBase64 Base64-encoded Markdown content.
|
||||
* @param string|null $message Optional commit message.
|
||||
*
|
||||
* @return object|null API response object or null on failure.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function create(
|
||||
string $owner,
|
||||
string $repo,
|
||||
string $title,
|
||||
string $contentBase64,
|
||||
?string $message = null
|
||||
): ?object
|
||||
{
|
||||
return null; // github does not support wiki over API
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the content of a specific wiki page.
|
||||
*
|
||||
* @param string $owner Repository owner (user or organization).
|
||||
* @param string $repo Repository name (without `.wiki`).
|
||||
* @param string $pageName Name of the page (excluding `.md`).
|
||||
*
|
||||
* @return object|null Page details including content and metadata, or null on failure.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function get(
|
||||
string $owner,
|
||||
string $repo,
|
||||
string $pageName
|
||||
): ?object
|
||||
{
|
||||
// Build the raw wiki URL
|
||||
$url = "https://raw.githubusercontent.com/wiki/{$owner}/{$repo}/{$pageName}.md";
|
||||
|
||||
// Use a direct HTTP GET request (bypasses GitHub API)
|
||||
$body = $this->response->get(
|
||||
$this->http->get(new Uri($url), [])
|
||||
);
|
||||
|
||||
return (object) [
|
||||
'name' => "{$pageName}.md",
|
||||
'content' => base64_encode($body),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* List all wiki pages in the repository.
|
||||
*
|
||||
* @param string $owner Repository owner (user or organization).
|
||||
* @param string $repo Repository name (without `.wiki`).
|
||||
* @param int $page Pagination index (1-based).
|
||||
* @param int $limit Number of results per page.
|
||||
*
|
||||
* @return array|null List of page metadata or null on failure.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function pages(
|
||||
string $owner,
|
||||
string $repo,
|
||||
int $page = 1,
|
||||
int $limit = 10
|
||||
): ?array
|
||||
{
|
||||
return null; // github does not support wiki over API
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a wiki page from the repository.
|
||||
*
|
||||
* @param string $owner Repository owner (user or organization).
|
||||
* @param string $repo Repository name (without `.wiki`).
|
||||
* @param string $pageName Name of the page to delete (excluding `.md`).
|
||||
*
|
||||
* @return string 'success' on deletion, or error message if the page was not found.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function delete(
|
||||
string $owner,
|
||||
string $repo,
|
||||
string $pageName
|
||||
): string
|
||||
{
|
||||
return 'error'; // github does not support wiki over API
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an existing wiki page.
|
||||
*
|
||||
* @param string $owner Repository owner (user or organization).
|
||||
* @param string $repo Repository name (without `.wiki`).
|
||||
* @param string $pageName Name of the page to edit (excluding `.md`).
|
||||
* @param string $title New title of the page (used to rename if applicable).
|
||||
* @param string $content Updated Markdown content.
|
||||
* @param string|null $message Optional commit message.
|
||||
*
|
||||
* @return object|null API response object or null if the page doesn't exist.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function edit(
|
||||
string $owner,
|
||||
string $repo,
|
||||
string $pageName,
|
||||
string $title,
|
||||
string $content,
|
||||
string $message = null
|
||||
): ?object
|
||||
{
|
||||
return null; // github does not support wiki over API
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the commit history (revisions) for a specific wiki page.
|
||||
*
|
||||
* @param string $owner Repository owner (user or organization).
|
||||
* @param string $repo Repository name (without `.wiki`).
|
||||
* @param string $pageName Name of the page to retrieve revisions for (excluding `.md`).
|
||||
* @param int $page Pagination index (1-based).
|
||||
*
|
||||
* @return object|null API response object with commit history or null on failure.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function revisions(
|
||||
string $owner,
|
||||
string $repo,
|
||||
string $pageName,
|
||||
int $page = 1
|
||||
): ?object
|
||||
{
|
||||
return null; // github does not support wiki over API
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Github\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
use VDM\Joomla\Github\Utilities\Http;
|
||||
use VDM\Joomla\Github\Utilities\Uri;
|
||||
use VDM\Joomla\Github\Utilities\Response;
|
||||
|
||||
|
||||
/**
|
||||
* The Github Utilities Service
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
class Utilities implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Http::class, 'Github.Utilities.Http')
|
||||
->share('Github.Utilities.Http', [$this, 'getHttp'], true);
|
||||
|
||||
$container->alias(Uri::class, 'Github.Utilities.Uri')
|
||||
->share('Github.Utilities.Uri', [$this, 'getUri'], true);
|
||||
|
||||
$container->alias(Response::class, 'Github.Utilities.Response')
|
||||
->share('Github.Utilities.Response', [$this, 'getResponse'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Http class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Http
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function getHttp(Container $container): Http
|
||||
{
|
||||
return new Http(
|
||||
Helper::getParams('com_componentbuilder')->get('github_access_token') ?? null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Uri class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Uri
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function getUri(Container $container): Uri
|
||||
{
|
||||
return new Uri();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Response class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Response
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function getResponse(Container $container): Response
|
||||
{
|
||||
return new Response();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
163
libraries/vendor_jcb/VDM.Joomla.Github/src/Utilities/Http.php
Normal file
163
libraries/vendor_jcb/VDM.Joomla.Github/src/Utilities/Http.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Github\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Http\Http as JoomlaHttp;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Github Http
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
final class Http extends JoomlaHttp
|
||||
{
|
||||
/**
|
||||
* The token
|
||||
*
|
||||
* @var string|null
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected ?string $_token_; // to avoid collisions (but allow swapping)
|
||||
|
||||
/**
|
||||
* The GitHub API version header
|
||||
*
|
||||
* @var string
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected string $apiVersion;
|
||||
|
||||
/**
|
||||
* The GitHub default headers
|
||||
*
|
||||
* @var string
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected array $defaultHeaders;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string|null $token The Gitea API token.
|
||||
* @param string $version GitHub API Version (e.g. 2022-11-28)
|
||||
*
|
||||
* @since 5.1.1
|
||||
* @throws \InvalidArgumentException
|
||||
**/
|
||||
public function __construct(?string $token = null, string $version = '2022-11-28')
|
||||
{
|
||||
$this->apiVersion = $version;
|
||||
|
||||
$this->defaultHeaders = [
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/vnd.github+json',
|
||||
'X-GitHub-Api-Version' => $this->apiVersion
|
||||
];
|
||||
|
||||
// setup config
|
||||
$config = [
|
||||
'userAgent' => 'JoomlaGitHub/3.0',
|
||||
'headers' => $this->defaultHeaders
|
||||
];
|
||||
|
||||
// add the token if given
|
||||
if (is_string($token) && !empty($token))
|
||||
{
|
||||
$config['headers']['Authorization'] = 'Bearer ' . $token;
|
||||
$this->_token_ = $token;
|
||||
}
|
||||
|
||||
$options = new Registry($config);
|
||||
|
||||
// run parent constructor
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the Token.
|
||||
*
|
||||
* @param string $token The Gitea API token.
|
||||
*
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function setToken(string $token): void
|
||||
{
|
||||
// get the current headers
|
||||
$headers = (array) $this->getOption('headers', $this->defaultHeaders);
|
||||
|
||||
if (empty($token))
|
||||
{
|
||||
unset($headers['Authorization']);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the token
|
||||
$headers['Authorization'] = 'Bearer ' . $token;
|
||||
$this->_token_ = $token;
|
||||
}
|
||||
|
||||
$this->setOption('headers', $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Token.
|
||||
*
|
||||
* @return string|null
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function getToken(): ?string
|
||||
{
|
||||
return $this->_token_ ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Accept header to 'application/vnd.github+json'
|
||||
*
|
||||
* @return static
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function json(): self
|
||||
{
|
||||
$this->setAcceptHeader('application/vnd.github+json');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Accept header to 'application/vnd.github.raw+json'
|
||||
*
|
||||
* @return static
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function raw(): self
|
||||
{
|
||||
$this->setAcceptHeader('application/vnd.github.raw+json');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Accept header
|
||||
*
|
||||
* @return void
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function setAcceptHeader(string $value): void
|
||||
{
|
||||
$headers = (array) $this->getOption('headers', $this->defaultHeaders);
|
||||
$headers['Accept'] = $value;
|
||||
$this->setOption('headers', $headers);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Github\Utilities;
|
||||
|
||||
|
||||
use Joomla\Http\Response as JoomlaResponse;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* The Github Response
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
final class Response
|
||||
{
|
||||
/**
|
||||
* Process the response and decode it.
|
||||
*
|
||||
* @param JoomlaResponse $response The response.
|
||||
* @param integer $expectedCode The expected "good" code.
|
||||
* @param mixed $default The default if body not have length
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 5.1.1
|
||||
* @throws \DomainException
|
||||
**/
|
||||
public function get(JoomlaResponse $response, int $expectedCode = 200, $default = null)
|
||||
{
|
||||
// Validate the response code.
|
||||
if ($response->code != $expectedCode)
|
||||
{
|
||||
// Decode the error response and throw an exception.
|
||||
$message = $this->error($response);
|
||||
|
||||
throw new \DomainException("Invalid response received from GitHub API. {$message}", $response->code);
|
||||
}
|
||||
|
||||
return $this->body($response, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the response and decode it. (when we have multiple success codes)
|
||||
*
|
||||
* @param JoomlaResponse $response The response.
|
||||
* @param array [$expectedCode => $default] The expected "good" code. and The default if body not have length
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 5.1.1
|
||||
* @throws \DomainException
|
||||
**/
|
||||
public function get_(JoomlaResponse $response, array $validate = [200 => null])
|
||||
{
|
||||
// Validate the response code.
|
||||
if (!array_key_exists($response->code, $validate))
|
||||
{
|
||||
// Decode the error response and throw an exception.
|
||||
$message = $this->error($response);
|
||||
|
||||
throw new \DomainException("Invalid response received from GitHub API. {$message}", $response->code);
|
||||
}
|
||||
|
||||
return $this->body($response, $validate[$response->code]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the body from the response
|
||||
*
|
||||
* @param JoomlaResponse $response The response.
|
||||
* @param mixed $default The default if body not have length
|
||||
*
|
||||
* @return mixed
|
||||
* @since 5.1.1
|
||||
**/
|
||||
protected function body(JoomlaResponse $response, $default = null)
|
||||
{
|
||||
$body = method_exists($response, 'getBody')
|
||||
? (string) $response->getBody()
|
||||
: ($response->body ?? null);
|
||||
|
||||
// check that we have a body
|
||||
if ($body !== null && StringHelper::check($body))
|
||||
{
|
||||
if (JsonHelper::check($body))
|
||||
{
|
||||
$body = json_decode((string) $body);
|
||||
|
||||
if (isset($body->content) && isset($body->encoding) && $body->encoding === 'base64')
|
||||
{
|
||||
$body->decoded_content = base64_decode((string) $body->content);
|
||||
}
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract an error message from a response object.
|
||||
*
|
||||
* @param JoomlaResponse $response The response object.
|
||||
*
|
||||
* @return string The extracted error message, or an empty string.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function error(JoomlaResponse $response): string
|
||||
{
|
||||
// Try to get the raw response body
|
||||
$body = method_exists($response, 'getBody') ? (string) $response->getBody() : '';
|
||||
|
||||
// Try to decode as JSON object
|
||||
$errorData = JsonHelper::check($body) ? json_decode($body) : null;
|
||||
|
||||
if (is_object($errorData))
|
||||
{
|
||||
// GitHub's error structure may have a message and/or an errors array
|
||||
if (!empty($errorData->message)) {
|
||||
$errorMsg = $errorData->message;
|
||||
|
||||
if (!empty($errorData->errors) && is_array($errorData->errors)) {
|
||||
$details = [];
|
||||
|
||||
foreach ($errorData->errors as $err) {
|
||||
if (is_object($err)) {
|
||||
$details[] = trim(
|
||||
($err->resource ?? '') . ' ' .
|
||||
($err->field ?? '') . ' ' .
|
||||
($err->code ?? '')
|
||||
);
|
||||
} else {
|
||||
$details[] = (string) $err;
|
||||
}
|
||||
}
|
||||
|
||||
$errorMsg .= ' (' . implode('; ', array_filter($details)) . ')';
|
||||
}
|
||||
|
||||
return $errorMsg;
|
||||
}
|
||||
|
||||
return json_encode($errorData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
// Fallback to reason phrase or body
|
||||
if (!empty($body))
|
||||
{
|
||||
return $body;
|
||||
}
|
||||
|
||||
return method_exists($response, 'getReasonPhrase')
|
||||
? $response->getReasonPhrase()
|
||||
: 'No error information found in GitHub API response.';
|
||||
}
|
||||
}
|
||||
|
169
libraries/vendor_jcb/VDM.Joomla.Github/src/Utilities/Uri.php
Normal file
169
libraries/vendor_jcb/VDM.Joomla.Github/src/Utilities/Uri.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Github\Utilities;
|
||||
|
||||
|
||||
use Joomla\Uri\Uri as JoomlaUri;
|
||||
|
||||
|
||||
/**
|
||||
* The Github Uri
|
||||
*
|
||||
* @since 5.1.1
|
||||
*/
|
||||
final class Uri
|
||||
{
|
||||
/**
|
||||
* The api endpoint
|
||||
*
|
||||
* @var string
|
||||
* @since 5.1.1
|
||||
*/
|
||||
private string $endpoint;
|
||||
|
||||
/**
|
||||
* The api version
|
||||
*
|
||||
* @var string
|
||||
* @since 5.1.1
|
||||
*/
|
||||
private string $version;
|
||||
|
||||
/**
|
||||
* The api URL
|
||||
*
|
||||
* @var string
|
||||
* @since 5.1.1
|
||||
*/
|
||||
private string $url;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $url URL to the github system
|
||||
* example: https://api.github.com
|
||||
* @param string $endpoint Endpoint to the gitea system
|
||||
* @param string $version Version to the gitea system
|
||||
*
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function __construct(
|
||||
string $url = 'https://api.github.com',
|
||||
string $endpoint = '',
|
||||
string $version = 'v3')
|
||||
{
|
||||
// set the API details
|
||||
$this->setUrl($url);
|
||||
//$this->setEndpoint($endpoint);
|
||||
//$this->setVersion($version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to build and return a full request URL for the request. This method will
|
||||
* add appropriate pagination details if necessary and also prepend the API url
|
||||
* to have a complete URL for the request.
|
||||
*
|
||||
* @param string $path URL to inflect
|
||||
*
|
||||
* @return JoomlaUri
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function get(string $path): JoomlaUri
|
||||
{
|
||||
// GitHub API does not use version in URL (normally passed in Accept headers)
|
||||
// But we maintain compatibility with existing interface
|
||||
$uri = new JoomlaUri($this->api() . ltrim($path, '/'));
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full API URL
|
||||
*
|
||||
* @return string
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function api(): string
|
||||
{
|
||||
// Ensure trailing slash on base URL
|
||||
return rtrim($this->url, '/') . '/';
|
||||
/**
|
||||
// GitHub typically does not use endpoint/version in URL
|
||||
// But to preserve interface, we include them conditionally
|
||||
$segments = [];
|
||||
|
||||
if (!empty($this->endpoint))
|
||||
{
|
||||
$segments[] = trim($this->endpoint, '/');
|
||||
}
|
||||
|
||||
if (!empty($this->version))
|
||||
{
|
||||
$segments[] = trim($this->version, '/');
|
||||
}
|
||||
|
||||
return $base . (empty($segments) ? '' : implode('/', $segments) . '/');
|
||||
**/
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URL of the API
|
||||
*
|
||||
* @param string $url URL to your github system
|
||||
* example: https://api.github.com
|
||||
*
|
||||
* @return void
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function setUrl(string $url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL of the API
|
||||
*
|
||||
* @return string|null
|
||||
* @since 5.1.1
|
||||
**/
|
||||
public function getUrl(): ?string
|
||||
{
|
||||
return $this->url ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the endpoint of the API
|
||||
*
|
||||
* @param string $endpoint endpoint to your github API
|
||||
*
|
||||
* @return void
|
||||
* @since 5.1.1
|
||||
private function setEndpoint(string $endpoint)
|
||||
{
|
||||
$this->endpoint = $endpoint;
|
||||
}
|
||||
**/
|
||||
|
||||
/**
|
||||
* Set the version of the API
|
||||
*
|
||||
* @param string $version version to your github API
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
private function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
**/
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
Reference in New Issue
Block a user