Moves the Pro features into the Public version of JCB.

This commit is contained in:
2022-07-09 17:16:21 +02:00
parent 9e4a6e0c53
commit 4e30fcb967
110 changed files with 11383 additions and 3669 deletions

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1,165 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @github Joomla Component Builder <https://github.com/vdm-io/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\Gitea;
use Joomla\CMS\Http\Http as BaseHttp;
use Joomla\CMS\Http\HttpFactory;
use Joomla\CMS\Http\Response;
use Joomla\Registry\Registry;
use Joomla\Uri\Uri;
use VDM\Joomla\Utilities\JsonHelper;
abstract class AbstractGiteaObject
{
/**
* Options for the Gitea object.
*
* @var Registry
* @since 1.0
*/
protected $options;
/**
* The HTTP client object to use in sending HTTP requests.
*
* @var BaseHttp
* @since 1.0
*/
protected $client;
/**
* The package the object resides in
*
* @var string
* @since 1.0
*/
protected $package = '';
/**
* Constructor.
*
* @param Registry $options Gitea options object.
* @param BaseHttp $client The HTTP client object.
*
* @since 1.0
*/
public function __construct(Registry $options = null, BaseHttp $client = null)
{
$this->options = $options ?: new Registry;
$this->client = $client ?: (new HttpFactory)->getHttp($this->options);
$this->package = \get_class($this);
$this->package = substr($this->package, strrpos($this->package, '\\') + 1);
}
/**
* 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
* @param integer $page Page to request
* @param integer $limit Number of results to return per page
*
* @return Uri
*
* @since 1.0
*/
protected function fetchUrl($path, $page = 0, $limit = 0)
{
// Get a new Uri object focusing the api url and given path.
$uri = new Uri($this->options->get('api.url') . $path);
if ($this->options->get('access.token', false))
{
// Use oAuth authentication
$headers = $this->client->getOption('headers', array());
if (!isset($headers['Authorization']))
{
$headers['Authorization'] = 'token ' . $this->options->get('access.token');
$this->client->setOption('headers', $headers);
}
}
else
{
// Use basic authentication
if ($this->options->get('api.username', false))
{
$uri->setUser($this->options->get('api.username'));
}
if ($this->options->get('api.password', false))
{
$uri->setPass($this->options->get('api.password'));
}
}
// If we have a defined page number add it to the JUri object.
if ($page > 0)
{
$uri->setVar('page', (int) $page);
}
// If we have a defined items per page add it to the JUri object.
if ($limit > 0)
{
$uri->setVar('limit', (int) $limit);
}
return $uri;
}
/**
* Process the response and decode it.
*
* @param Response $response The response.
* @param integer $expectedCode The expected "good" code.
*
* @return mixed
*
* @since 1.0
* @throws RuntimeException
*/
protected function processResponse(Response $response, $expectedCode = 200)
{
// Validate the response code.
if ($response->code != $expectedCode)
{
// Decode the error response and throw an exception.
$error = json_decode($response->body);
$message = isset($error->message) ? $error->message : 'Invalid response received from Gitea.';
throw new \DomainException($message, $response->code);
}
if (JsonHelper::check($response->body))
{
$body = json_decode($response->body);
if (isset($body->content_base64))
{
$body->content = base64_decode($body->content_base64);
}
}
else
{
$body = $response->body;
}
return $body;
}
}

View File

@ -0,0 +1,71 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @github Joomla Component Builder <https://github.com/vdm-io/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\Gitea;
use Joomla\CMS\Http\Http as BaseHttp;
use Joomla\Registry\Registry;
use VDM\Gitea\AbstractGiteaObject;
abstract class AbstractPackage extends AbstractGiteaObject
{
/**
* Constructor.
*
* @param Registry $options Gitea options object.
* @param Http $client The HTTP client object.
*
* @since 1.0
*/
public function __construct(Registry $options = null, BaseHttp $client = null)
{
parent::__construct($options, $client);
$this->package = \get_class($this);
$this->package = substr($this->package, strrpos($this->package, '\\') + 1);
}
/**
* Magic method to lazily create API objects
*
* @param string $name Name of property to retrieve
*
* @since 1.0
* @throws \InvalidArgumentException
*
* @return AbstractPackage Gitea API package object.
*/
public function __get($name)
{
$class = '\\VDM\\Gitea\\Package\\' . $this->package . '\\' . ucfirst($name);
if (class_exists($class) == false)
{
throw new \InvalidArgumentException(
sprintf(
'Argument %1$s produced an invalid class name: %2$s in package %3$s',
$name, $class, $this->package
)
);
}
if (isset($this->$name) == false)
{
$this->$name = new $class($this->options, $this->client);
}
return $this->$name;
}
}

View File

@ -0,0 +1,124 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @github Joomla Component Builder <https://github.com/vdm-io/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\Gitea;
use Joomla\CMS\Http\Http as BaseHttp;
use Joomla\CMS\Http\HttpFactory;
use Joomla\Registry\Registry;
class Gitea
{
/**
* Options for the Gitea object.
*
* @var array
* @since 1.0
*/
protected $options;
/**
* The HTTP client object to use in sending HTTP requests.
*
* @var BaseHttp
* @since 1.0
*/
protected $client;
/**
* Constructor.
*
* @param Registry $options Gitea options object.
* @param Http $client The HTTP client object.
*
* @since 1.0
*/
public function __construct(Registry $options = null, BaseHttp $client = null)
{
$this->options = $options ?: new Registry;
// Setup the default user agent if not already set.
if (!$this->getOption('userAgent'))
{
$this->setOption('userAgent', 'JGitea/1.0');
}
// Setup the default API url if not already set.
if (!$this->getOption('api.url'))
{
$this->setOption('api.url', 'https://git.vdm.dev/api/v1');
}
$this->client = $client ?: (new HttpFactory)->getHttp($this->options);
}
/**
* Magic method to lazily create API objects
*
* @param string $name Name of property to retrieve
*
* @return AbstractGiteaObject Gitea API object (issues, pulls, etc).
*
* @since 1.0
* @throws \InvalidArgumentException If $name is not a valid sub class.
*/
public function __get($name)
{
$class = '\\VDM\\Gitea\\Package\\' . ucfirst($name);
if (class_exists($class))
{
if (isset($this->$name) == false)
{
$this->$name = new $class($this->options, $this->client);
}
return $this->$name;
}
throw new \InvalidArgumentException(sprintf('Argument %s produced an invalid class name: %s', $name, $class));
}
/**
* Get an option from the Gitea instance.
*
* @param string $key The name of the option to get.
*
* @return mixed The option value.
*
* @since 1.0
*/
public function getOption($key)
{
return isset($this->options[$key]) ? $this->options[$key] : null;
}
/**
* Set an option for the Gitea instance.
*
* @param string $key The name of the option to set.
* @param mixed $value The option value to set.
*
* @return Gitea This object for method chaining.
*
* @since 1.0
*/
public function setOption($key, $value)
{
$this->options[$key] = $value;
return $this;
}
}

View File

@ -0,0 +1,267 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @github Joomla Component Builder <https://github.com/vdm-io/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\Gitea\Package;
use Joomla\CMS\Http\Http;
use Joomla\Registry\Registry;
use VDM\Gitea\AbstractPackage;
class Repo extends AbstractPackage
{
/**
* List your repositories.
*
* List repositories for the authenticated user.
*
* @return object
*
* @since 1.0
*/
public function getListOwn()
{
// Build the request path.
$uri = $this->fetchUrl('/user/repos');
// Send the request.
return $this->processResponse($this->client->get($uri));
}
/**
* List user repositories.
*
* List public repositories for the specified user.
*
* @param string $user The user name.
*
* @return object
*
* @since 1.0
*/
public function getListUser($user)
{
// Build the request path.
$uri = $this->fetchUrl('/users/' . $user . '/repos');
// Send the request.
return $this->processResponse($this->client->get($uri));
}
/**
* List organization repositories.
*
* List repositories for the specified org.
*
* @param string $org The name of the organization.
*
* @return object
*
* @since 1.0
*/
public function getListOrg($org)
{
// Build the request path.
$uri = $this->fetchUrl('/orgs/' . $org . '/repos');
// Send the request.
return $this->processResponse($this->client->get($uri));
}
/**
* Create.
*
* Create a new repository for the authenticated user or an organization. OAuth users must supply repo scope.
*
* @param string $name The repository name.
* @param string $org The organization name (if needed).
* @param string $description The repository description.
* @param string $readme Readme of the repository to create.
* @param boolean $private Set true to create a private repository, false to create a public one.
* @param string $defaultBranch DefaultBranch of the repository (used when initializes and in template).
* @param string $license License to use.
* @param boolean $autoInit Whether the repository should auto init.
* @param boolean $template Whether the repository is template.
* @param string $gitignores Gitignores to use.
* options: [ Joomla, JetBrains ] and much more...
* @param string $issueLabels Label-Set to use.
* @param string $trustModel TrustModel of the repository.
* options: [ default, collaborator, committer, collaboratorcommitter ]
*
* @return object
*
* @since 1.0
*/
public function create($name, $org = '', $description = '', $readme = 'Default', $private = false, $defaultBranch = 'master',
$license = 'GPL-2.0-or-later', $autoInit = true, $template = false, $trustModel = 'default', $gitignores = '', $issueLabels = ''
)
{
$path = ($org)
// Create a repository for an organization
? '/orgs/' . $org . '/repos'
// Create a repository for a user
: '/user/repos';
$data = [
'name' => $name,
'description' => $description,
'readme' => $readme,
'private' => $private,
'auto_init' => $autoInit,
'default_branch' => $defaultBranch,
'issue_labels' => $issueLabels,
'license' => $license,
'template' => $template,
'gitignores' => $gitignores,
'trust_model' => $trustModel
];
// Send the request.
return $this->processResponse(
$this->client->post($this->fetchUrl($path), json_encode($data)),
201
);
}
/**
* Get.
*
* @param string $owner Repository owner.
* @param string $repo Repository name.
*
* @return object
*
* @since 1.0
*/
public function get($owner, $repo)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo;
// Send the request.
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
/**
* List contributors.
*
* @param string $owner Repository owner.
* @param string $repo Repository name.
*
* @return object
*
* @since 1.0
*/
public function getListContributors($owner, $repo)
{
// Build the request path.
$uri = $this->fetchUrl('/repos/' . $owner . '/' . $repo . '/contributors');
// Send the request.
return $this->processResponse($this->client->get($uri));
}
/**
* List languages.
*
* List languages for the specified repository. The value on the right of a language is the number of bytes of code
* written in that language.
*
* @param string $owner Repository owner.
* @param string $repo Repository name.
*
* @return object
*
* @since 1.0
*/
public function getListLanguages($owner, $repo)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/languages';
// Send the request.
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
/**
* List Teams
*
* @param string $owner Repository owner.
* @param string $repo Repository name.
*
* @return object
*
* @since 1.0
*/
public function getListTeams($owner, $repo)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/teams';
// Send the request.
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
/**
* List Tags.
*
* @param string $owner Repository owner.
* @param string $repo Repository name.
* @param integer $page Page to request
* @param integer $limit Number of results to return per page
*
* @return object
*
* @since 1.0
*/
public function getListTags($owner, $repo, $page = 0, $limit = 0)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/tags';
// Send the request.
return $this->processResponse(
$this->client->get($this->fetchUrl($path, $page, $limit))
);
}
/**
* Delete a Repository.
*
* Deleting a repository requires admin access. If OAuth is used, the delete_repo scope is required.
*
* @param string $owner Repository owner.
* @param string $repo Repository name.
*
* @return object
*
* @since 1.0
*/
public function delete($owner, $repo)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo;
// Send the request.
return $this->processResponse(
$this->client->delete($this->fetchUrl($path))
);
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @github Joomla Component Builder <https://github.com/vdm-io/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\Gitea\Package\Repo;
use Joomla\CMS\Http\Http;
use Joomla\Registry\Registry;
use VDM\Gitea\AbstractPackage;
/**
* Start looking here:
* https://git.vdm.dev/api/swagger#/repository/repoGetContents
*/
class File extends AbstractPackage
{
/**
* Gets the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir
*
* @param string $owner Repository owner.
* @param string $repo Repository name.
* @param string $filepath Repository file path.
*
* @return object
*
* @since 1.0
*/
public function get($owner, $repo, $filepath)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/contents/' . $filepath;
// Send the request.
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @github Joomla Component Builder <https://github.com/vdm-io/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\Gitea\Package\Repo;
use Joomla\CMS\Http\Http;
use Joomla\Registry\Registry;
use VDM\Gitea\AbstractPackage;
/**
* Start looking here:
* https://git.vdm.dev/api/swagger#/repository/repoCreateWikiPage
*/
class Wiki extends AbstractPackage
{
/**
* Get a repository wiki page
*
* @param string $owner The repository owner
* @param string $repo The repository name
* @param string $pageName The page name
*
* @return object
*
* @since 1.0
*/
public function get(string $owner, string $repo, string $pageName)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/wiki/page/' . $pageName;
// Send the request.
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
/**
* Get a repository wiki html page
*
* @param string $owner The repository owner
* @param string $repo The repository name
* @param string $pageName The page name
*
* @return object
*
* @since 1.0
*/
public function getHtml(string $owner, string $repo, string $pageName)
{
// get the gitea wiki page
$page = $this->get($owner, $repo, $pageName);
if (empty($page->content))
{
throw new \Exception('Wiki page could not be found.');
}
// Build the request path.
$path = '/markdown';
// Get headers
$headers = $this->client->getOption('headers', array());
$headers['accept'] = 'text/html';
$headers['Content-Type'] = 'application/json';
// build the post body
$data = [
'Context' => 'string',
'Mode' => 'string',
'Text' => $page->content,
'Wiki' => true
];
// Post the request.
return $this->processResponse(
$this->client->post($this->fetchUrl($path), json_encode($data), $headers)
);
}
}

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -75,6 +75,32 @@ abstract class ArrayHelper
}
return false;
}
/**
* Check if arrays intersect
*
* @input array The first array
* @input array The second array
*
* @returns bool true if intersect else false
*
* @since 3.1.1
*/
public static function intersect($a_array, $b_array)
{
// flip the second array
$b_array = array_flip($b_array);
// loop the first array
foreach ($a_array as $v)
{
if (isset($b_array[$v]))
{
return true;
}
}
return false;
}
}