2014-05-03 01:56:15 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-05-03 23:48:08 +00:00
|
|
|
* Patch testing component for the Joomla! CMS
|
2014-05-03 01:56:15 +00:00
|
|
|
*
|
2018-09-01 14:32:23 +00:00
|
|
|
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
|
2014-05-03 01:56:15 +00:00
|
|
|
* @license GNU General Public License version 2 or later
|
|
|
|
*/
|
|
|
|
|
2014-05-03 23:48:08 +00:00
|
|
|
namespace PatchTester;
|
2014-05-03 01:56:15 +00:00
|
|
|
|
2017-08-17 23:22:01 +00:00
|
|
|
use Joomla\CMS\Component\ComponentHelper;
|
|
|
|
use Joomla\CMS\Factory;
|
2019-08-28 01:20:49 +00:00
|
|
|
use Joomla\CMS\Language\Text;
|
2014-05-03 02:02:38 +00:00
|
|
|
use Joomla\Registry\Registry;
|
2016-06-25 16:34:48 +00:00
|
|
|
use PatchTester\GitHub\GitHub;
|
2014-05-03 02:02:38 +00:00
|
|
|
|
2014-05-03 01:56:15 +00:00
|
|
|
/**
|
|
|
|
* Helper class for the patch tester component
|
|
|
|
*
|
2014-05-03 23:48:08 +00:00
|
|
|
* @since 2.0
|
2014-05-03 01:56:15 +00:00
|
|
|
*/
|
2014-05-03 23:48:08 +00:00
|
|
|
abstract class Helper
|
2014-05-03 01:56:15 +00:00
|
|
|
{
|
|
|
|
/**
|
2016-06-25 16:34:48 +00:00
|
|
|
* Initializes the GitHub object
|
2014-05-03 01:56:15 +00:00
|
|
|
*
|
2016-06-25 16:34:48 +00:00
|
|
|
* @return GitHub
|
2014-05-03 01:56:15 +00:00
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public static function initializeGithub()
|
|
|
|
{
|
2017-08-17 23:22:01 +00:00
|
|
|
$params = ComponentHelper::getParams('com_patchtester');
|
2014-05-03 01:56:15 +00:00
|
|
|
|
2014-05-03 02:02:38 +00:00
|
|
|
$options = new Registry;
|
2014-05-03 01:56:15 +00:00
|
|
|
|
2016-06-25 16:34:48 +00:00
|
|
|
// Set a user agent for the request
|
|
|
|
$options->set('userAgent', 'PatchTester/3.0');
|
|
|
|
|
|
|
|
// Set the default timeout to 120 seconds
|
|
|
|
$options->set('timeout', 120);
|
|
|
|
|
|
|
|
// Set the API URL
|
|
|
|
$options->set('api.url', 'https://api.github.com');
|
|
|
|
|
2014-05-03 01:56:15 +00:00
|
|
|
// If an API token is set in the params, use it for authentication
|
|
|
|
if ($params->get('gh_token', ''))
|
|
|
|
{
|
2020-07-05 09:17:38 +00:00
|
|
|
$options->set('headers', ['Authorization' => 'token ' . $params->get('gh_token', '')]);
|
2014-05-03 01:56:15 +00:00
|
|
|
}
|
|
|
|
// Set the username and password if set in the params
|
|
|
|
elseif ($params->get('gh_user', '') && $params->get('gh_password'))
|
|
|
|
{
|
|
|
|
$options->set('api.username', $params->get('gh_user', ''));
|
|
|
|
$options->set('api.password', $params->get('gh_password', ''));
|
|
|
|
}
|
|
|
|
// Display a message about the lowered API limit without credentials
|
|
|
|
else
|
|
|
|
{
|
2019-08-28 01:20:49 +00:00
|
|
|
Factory::getApplication()->enqueueMessage(Text::_('COM_PATCHTESTER_NO_CREDENTIALS'), 'notice');
|
2014-05-03 01:56:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-25 16:34:48 +00:00
|
|
|
return new GitHub($options);
|
2014-05-03 01:56:15 +00:00
|
|
|
}
|
2019-09-08 16:02:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the CI Settings
|
|
|
|
*
|
|
|
|
* @return Registry
|
|
|
|
*
|
|
|
|
* @since 3.0
|
|
|
|
*/
|
|
|
|
public static function initializeCISettings()
|
|
|
|
{
|
2019-09-11 12:57:35 +00:00
|
|
|
$params = ComponentHelper::getParams('com_patchtester');
|
|
|
|
|
2019-09-08 16:02:14 +00:00
|
|
|
$options = new Registry;
|
|
|
|
|
|
|
|
// Set CI server address for the request
|
2019-09-18 13:13:24 +00:00
|
|
|
$options->set('server.url', $params->get('ci_server', 'https://ci.joomla.org:444'));
|
2019-09-08 16:02:14 +00:00
|
|
|
|
|
|
|
// Set name of the zip archive
|
|
|
|
$options->set('zip.name', 'build.zip');
|
2019-09-11 09:41:01 +00:00
|
|
|
$options->set('zip.log.name', 'deleted_files.log');
|
2019-09-08 16:02:14 +00:00
|
|
|
|
|
|
|
// Set temp archive for extracting and downloading files
|
2019-09-10 11:53:40 +00:00
|
|
|
$options->set('folder.temp', Factory::getConfig()->get('tmp_path'));
|
2019-09-08 16:02:14 +00:00
|
|
|
$options->set('folder.backups', JPATH_COMPONENT . '/backups');
|
|
|
|
|
|
|
|
// Set full url for addressing the file
|
2019-09-18 13:13:24 +00:00
|
|
|
$options->set('zip.url', $options->get('server.url') . '/artifacts/joomla/joomla-cms/4.0-dev/%s/patchtester/' . $options->get('zip.name'));
|
2019-09-08 16:02:14 +00:00
|
|
|
|
|
|
|
return $options;
|
|
|
|
}
|
2014-05-03 01:56:15 +00:00
|
|
|
}
|