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
|
|
|
*
|
|
|
|
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2014 Open Source Matters, Inc. All rights reserved.
|
|
|
|
* @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
|
|
|
|
2014-05-03 02:02:38 +00:00
|
|
|
use Joomla\Registry\Registry;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Initializes the JGithub object
|
|
|
|
*
|
2014-05-03 23:48:08 +00:00
|
|
|
* @return \JGithub
|
2014-05-03 01:56:15 +00:00
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public static function initializeGithub()
|
|
|
|
{
|
2014-05-03 23:48:08 +00:00
|
|
|
$params = \JComponentHelper::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
|
|
|
|
|
|
|
// If an API token is set in the params, use it for authentication
|
|
|
|
if ($params->get('gh_token', ''))
|
|
|
|
{
|
|
|
|
$options->set('gh.token', $params->get('gh_token', ''));
|
|
|
|
}
|
|
|
|
// 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
|
|
|
|
{
|
2014-05-03 23:48:08 +00:00
|
|
|
\JFactory::getApplication()->enqueueMessage(\JText::_('COM_PATCHTESTER_NO_CREDENTIALS'), 'notice');
|
2014-05-03 01:56:15 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 23:48:08 +00:00
|
|
|
return new \JGithub($options);
|
2014-05-03 01:56:15 +00:00
|
|
|
}
|
|
|
|
}
|