mirror of
https://github.com/joomla-extensions/patchtester.git
synced 2025-01-22 22:58:27 +00:00
Creating component
This commit is contained in:
commit
077e57ccfa
7
administrator/components/com_patchtester/access.xml
Normal file
7
administrator/components/com_patchtester/access.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<access component="com_patchtester">
|
||||
<section name="component">
|
||||
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
|
||||
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
|
||||
</section>
|
||||
</access>
|
34
administrator/components/com_patchtester/config.xml
Normal file
34
administrator/components/com_patchtester/config.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<config>
|
||||
<fieldset name="component"
|
||||
label="COM_PATCHTESTER_COMPONENT_LABEL"
|
||||
description="COM_PATCHTESTER_COMPONENT_DESC"
|
||||
>
|
||||
|
||||
<field name="org" type="text"
|
||||
default="joomla"
|
||||
description="COM_PATCHTESTER_FIELD_ORG_DESC"
|
||||
label="COM_PATCHTESTER_FIELD_ORG_LABEL"
|
||||
/>
|
||||
|
||||
<field name="repo" type="text"
|
||||
default="joomla-cms"
|
||||
description="COM_PATCHTESTER_FIELD_REPO_DESC"
|
||||
label="COM_PATCHTESTER_FIELD_REPO_LABEL"
|
||||
/>
|
||||
|
||||
</fieldset>
|
||||
|
||||
<fieldset name="permissions"
|
||||
description="JCONFIG_PERMISSIONS_DESC"
|
||||
label="JCONFIG_PERMISSIONS_LABEL"
|
||||
>
|
||||
|
||||
<field name="rules" type="rules"
|
||||
component="com_patchtester"
|
||||
filter="rules"
|
||||
validate="rules"
|
||||
label="JCONFIG_PERMISSIONS_LABEL"
|
||||
section="component" />
|
||||
</fieldset>
|
||||
</config>
|
35
administrator/components/com_patchtester/controller.php
Normal file
35
administrator/components/com_patchtester/controller.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* @package PatchTester
|
||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* PatchTester Controller
|
||||
*
|
||||
* @package PatchTester
|
||||
*/
|
||||
class PatchTesterController extends JController
|
||||
{
|
||||
protected $default_view = 'Pulls';
|
||||
|
||||
/**
|
||||
* Method to display a view.
|
||||
*
|
||||
* @param boolean $cachable If true, the view output will be cached
|
||||
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
|
||||
*
|
||||
* @return JController This object to support chaining.
|
||||
* @since 1.5
|
||||
*/
|
||||
public function display($cachable = false, $urlparams = false)
|
||||
{
|
||||
parent::display();
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @package PatchTester
|
||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
jimport('joomla.application.component.controllerform');
|
||||
|
||||
/**
|
||||
* Pull controller class
|
||||
*
|
||||
* @package PatchTester
|
||||
*/
|
||||
class PatchtesterControllerPull extends JController
|
||||
{
|
||||
public function apply()
|
||||
{
|
||||
$model = $this->getModel('pull');
|
||||
if ($model->apply(JRequest::getVar('pull_id'))) {
|
||||
$msg = 'Patch successfully applied';
|
||||
} else {
|
||||
$msg = 'Patch did not apply';
|
||||
}
|
||||
$this->setRedirect(JRoute::_('index.php?option=com_patchtester&view=pulls', false), $msg);
|
||||
}
|
||||
|
||||
public function revert()
|
||||
{
|
||||
$model = $this->getModel('pull');
|
||||
if ($model->revert(JRequest::getVar('pull_id'))) {
|
||||
$msg = 'Patch successfully reverted';
|
||||
} else {
|
||||
$msg = 'Patch did not revert';
|
||||
}
|
||||
$this->setRedirect(JRoute::_('index.php?option=com_patchtester&view=pulls', false), $msg);
|
||||
}
|
||||
|
||||
}
|
0
administrator/components/com_patchtester/index.html
Normal file
0
administrator/components/com_patchtester/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
COM_PATCHTESTER_NOT_APPLIED="Not Applied"
|
||||
COM_PATCHTESTER_APPLIED="Applied"
|
||||
COM_PATCHTESTER_REVERT_PATCH="Revert Patch"
|
||||
COM_PATCHTESTER_APPLY_PATCH="Apply Patch"
|
||||
COM_PATCHTESTER_TEST_THIS_PATCH="Test This Patch"
|
||||
COM_PATCHTESTER_REPO_IS_GONE="The patch could not be applied because the repository is missing"
|
||||
COM_PATCHTESTER_CONFLICT="The patch could not be applied because it conflicts with a previously applied patch"
|
||||
COM_PATCHTESTER_COMPONENT_LABEL="Patch Tester"
|
||||
COM_PATCHTESTER_COMPONENT_DESC="Patch Tester Configuration Values"
|
||||
COM_PATCHTESTER_FIELD_ORG_DESC="Github Username"
|
||||
COM_PATCHTESTER_FIELD_ORG_LABEL="Name of account on Github of which to monitor pull requests"
|
||||
COM_PATCHTESTER_FIELD_REPO_DESC="Github Repository"
|
||||
COM_PATCHTESTER_FIELD_REPO_LABEL="Name of repository on Github of which to monitor pull requests"
|
@ -0,0 +1,3 @@
|
||||
COM_PATCHTESTER="Patch Tester"
|
||||
COM_PATCHTESTER_XML_DESCRIPTION="Component for pull request management testing"
|
||||
|
133
administrator/components/com_patchtester/models/pull.php
Normal file
133
administrator/components/com_patchtester/models/pull.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* @package PatchTester
|
||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Methods supporting pull requests.
|
||||
*
|
||||
* @package PatchTester
|
||||
*/
|
||||
class PatchtesterModelPull extends JModel
|
||||
{
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
// Initialise variables.
|
||||
$app = JFactory::getApplication('administrator');
|
||||
|
||||
// Load the parameters.
|
||||
$params = JComponentHelper::getParams('com_patchtester');
|
||||
$this->setState('params', $params);
|
||||
$this->setState('github_user', $params->get('org'));
|
||||
$this->setState('github_repo', $params->get('repo'));
|
||||
|
||||
parent::populateState();
|
||||
}
|
||||
|
||||
|
||||
public function apply($id)
|
||||
{
|
||||
jimport('joomla.client.github');
|
||||
jimport('joomla.client.http');
|
||||
|
||||
$table = JTable::getInstance('tests', 'PatchTesterTable');
|
||||
$github = new JGithub();
|
||||
$pull = $github->pulls->get($this->getState('github_user'), $this->getState('github_repo'), $id);
|
||||
$patchUrl = $pull->patch_url;
|
||||
|
||||
$http = new JHttp;
|
||||
|
||||
$patch = $http->get($patchUrl)->body;
|
||||
$patch = explode("\n", $patch);
|
||||
|
||||
$files = array();
|
||||
|
||||
foreach ($patch AS $line)
|
||||
{
|
||||
if (is_null($pull->head->repo)) {
|
||||
$this->setError(JText::_('COM_PATCHTESTER_REPO_IS_GONE'));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strpos($line, '--- a/') === 0) {
|
||||
$file = substr($line, 6);
|
||||
|
||||
// if the backup file already exists, we can't apply the patch
|
||||
if (file_exists(JPATH_COMPONENT . '/backups/' . md5($file) . '.txt')) {
|
||||
$this->setError(JText::_('COM_PATCHTESTER_CONFLICT'));
|
||||
return false;
|
||||
}
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($files AS $file)
|
||||
{
|
||||
// we only create a backup if the file already exists
|
||||
if (file_exists(JPATH_ROOT . '/' . $file)) {
|
||||
JFile::copy(JPath::clean(JPATH_ROOT . '/' . $file), JPATH_COMPONENT . '/backups/' . md5($file) . '.txt');
|
||||
}
|
||||
|
||||
$url = 'https://raw.github.com/' . $pull->head->user->login . '/' . $pull->head->repo->name . '/' .
|
||||
$pull->head->ref . $file;
|
||||
$newFile = $http->get($url);
|
||||
JFile::write(JPath::clean(JPATH_ROOT . '/' . $file), $newFile->body);
|
||||
|
||||
}
|
||||
$table->pull_id = $pull->number;
|
||||
$table->data = json_encode($files);
|
||||
$table->patched_by = JFactory::getUser()->id;
|
||||
$table->applied = 1;
|
||||
$version = new JVersion;
|
||||
$table->applied_version = $version->getShortVersion();
|
||||
$result = $table->store();
|
||||
|
||||
if ($result) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function revert($id)
|
||||
{
|
||||
$table = JTable::getInstance('tests', 'PatchTesterTable');
|
||||
|
||||
$table->load($id);
|
||||
|
||||
// we don't want to restore files from an older version
|
||||
$version = new JVersion;
|
||||
if ($table->applied_version != $version->getShortVersion()) {
|
||||
$table->applied = 0;
|
||||
$table->applied_version = '';
|
||||
$table->store();
|
||||
return true;
|
||||
}
|
||||
|
||||
$files = json_decode($table->data);
|
||||
|
||||
foreach ($files AS $file) {
|
||||
JFile::copy(JPATH_COMPONENT . '/backups/' . md5($file) . '.txt', JPATH_ROOT . '/' . $file);
|
||||
JFile::delete(JPATH_COMPONENT . '/backups/' . md5($file) . '.txt');
|
||||
}
|
||||
|
||||
$table->applied_version = '';
|
||||
$table->applied = 0;
|
||||
$table->store();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
110
administrator/components/com_patchtester/models/pulls.php
Normal file
110
administrator/components/com_patchtester/models/pulls.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* @package PatchTester
|
||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
jimport('joomla.application.component.modellist');
|
||||
|
||||
/**
|
||||
* Methods supporting a list of pull request.
|
||||
*
|
||||
* @package PatchTester
|
||||
*/
|
||||
class PatchtesterModelPulls extends JModelList
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array An optional associative array of configuration settings.
|
||||
* @see JController
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if (empty($config['filter_fields'])) {
|
||||
$config['filter_fields'] = array(
|
||||
'id', 'id',
|
||||
'title', 'title',
|
||||
'updated_at', 'updated_at',
|
||||
'user', 'user'
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
// Initialise variables.
|
||||
$app = JFactory::getApplication('administrator');
|
||||
|
||||
// Load the parameters.
|
||||
$params = JComponentHelper::getParams('com_patchtester');
|
||||
|
||||
$this->setState('params', $params);
|
||||
$this->setState('github_user', $params->get('org'));
|
||||
$this->setState('github_repo', $params->get('repo'));
|
||||
// List state information.
|
||||
parent::populateState('title', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
* @return string A store id.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
public function getAppliedPatches()
|
||||
{
|
||||
$query = $this->_db->getQuery(true);
|
||||
$query->select('*');
|
||||
$query->from('#__tests');
|
||||
$query->where('applied = 1');
|
||||
|
||||
$this->_db->setQuery($query);
|
||||
$tests = $this->_db->loadObjectList('pull_id');
|
||||
return $tests;
|
||||
}
|
||||
|
||||
public function getItems()
|
||||
{
|
||||
jimport('joomla.client.github');
|
||||
|
||||
if ($this->getState('github_user') == '' || $this->getState('github_repo') == '') {
|
||||
return array();
|
||||
}
|
||||
|
||||
$github = new JGithub();
|
||||
$pulls = $github->pulls->getAll($this->getState('github_user'), $this->getState('github_repo'));
|
||||
usort($pulls, array($this, 'sortItems'));
|
||||
return $pulls;
|
||||
}
|
||||
|
||||
public function sortItems($a, $b)
|
||||
{
|
||||
return strcasecmp($a->title, $b->title);
|
||||
}
|
||||
}
|
22
administrator/components/com_patchtester/patchtester.php
Normal file
22
administrator/components/com_patchtester/patchtester.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* @package PatchTester
|
||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
|
||||
// no direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// Access check.
|
||||
if (!JFactory::getUser()->authorise('core.manage', 'com_patchtester')) {
|
||||
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
|
||||
}
|
||||
|
||||
// Include dependencies
|
||||
jimport('joomla.application.component.controller');
|
||||
|
||||
$controller = JController::getInstance('PatchTester');
|
||||
$controller->execute(JRequest::getCmd('task'));
|
||||
$controller->redirect();
|
46
administrator/components/com_patchtester/patchtester.xml
Normal file
46
administrator/components/com_patchtester/patchtester.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension type="component" version="1.7" method="upgrade">
|
||||
<name>com_patchtester</name>
|
||||
<author>Ian MacLennan</author>
|
||||
<creationDate>October 2011</creationDate>
|
||||
<copyright>(C) 2011 Ian MacLennan. All rights reserved.
|
||||
</copyright>
|
||||
<license>GNU General Public License version 2 or later; see
|
||||
LICENSE.txt</license>
|
||||
<authorEmail>ianlenmac@gmail.com</authorEmail>
|
||||
<authorUrl>http://github.com/ianmacl</authorUrl>
|
||||
<version>1.0alpha</version>
|
||||
<description>COM_PATCHTESTER_XML_DESCRIPTION</description>
|
||||
|
||||
<install> <!-- Runs on install -->
|
||||
<sql>
|
||||
<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
|
||||
</sql>
|
||||
</install>
|
||||
<uninstall> <!-- Runs on uninstall -->
|
||||
<sql>
|
||||
<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
|
||||
</sql>
|
||||
</uninstall>
|
||||
|
||||
<files folder="site">
|
||||
<filename>patchtester.php</filename>
|
||||
</files>
|
||||
<languages folder="site">
|
||||
<language tag="en-GB">language/en-GB.com_patchtester.ini</language>
|
||||
</languages>
|
||||
<administration>
|
||||
<menu img="class:patchtester">com_patchtester</menu>
|
||||
<files folder="admin">
|
||||
<filename>access.xml</filename>
|
||||
<filename>config.xml</filename>
|
||||
<filename>controller.php</filename>
|
||||
<filename>patchtester.php</filename>
|
||||
<folder>controllers</folder> <folder>models</folder>
|
||||
<folder>sql</folder>
|
||||
<folder>tables</folder>
|
||||
<folder>views</folder>
|
||||
<folder>language</folder>
|
||||
</files>
|
||||
</administration>
|
||||
</extension>
|
@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS `#__tests` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`pull_id` int(11) NOT NULL,
|
||||
`data` varchar(5000) NOT NULL,
|
||||
`patched_by` int(11) NOT NULL,
|
||||
`applied` int(11) NOT NULL,
|
||||
`applied_version` varchar(25) NOT NULL,
|
||||
`rating` int(11) NOT NULL,
|
||||
`comments` varchar(3000) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARSET=utf8;
|
@ -0,0 +1 @@
|
||||
DROP TABLE IF NOT EXISTS `#__tests`
|
27
administrator/components/com_patchtester/tables/tests.php
Normal file
27
administrator/components/com_patchtester/tables/tests.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @package PatchTester
|
||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Tests Table class
|
||||
*
|
||||
* @package PatchTester
|
||||
*/
|
||||
class PatchtesterTableTests extends JTable
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param JDatabase A database connector object
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
parent::__construct('#__tests', 'id', $db);
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* @package PatchTester
|
||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
// no direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
JHtml::_('behavior.tooltip');
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var submitpatch = function(task, id) {
|
||||
document.id('pull_id').set('value', id);
|
||||
return Joomla.submitbutton(task);
|
||||
}
|
||||
</script>
|
||||
|
||||
<form action="<?php echo JRoute::_('index.php?option=com_patchtester&view=pulls'); ?>" method="post" name="adminForm" id="adminForm">
|
||||
|
||||
<table class="adminlist">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="1%">
|
||||
<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
|
||||
</th>
|
||||
<th class="title">
|
||||
<?php echo JText::_('JGLOBAL_TITLE'); ?>
|
||||
</th>
|
||||
<th width="20%">
|
||||
<?php echo JText::_('JSTATUS'); ?>
|
||||
</th>
|
||||
<th width="20%">
|
||||
<?php echo JText::_('COM_PATCHTESTER_TEST_THIS_PATCH'); ?>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="10">
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
<?php foreach ($this->items as $i => $item) :
|
||||
if (isset($this->patches[$item->number])) {
|
||||
$patch = $this->patches[$item->number];
|
||||
} else {
|
||||
$patch = false;
|
||||
}
|
||||
?>
|
||||
<tr class="row<?php echo $i % 2; ?>">
|
||||
<td class="center">
|
||||
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?php echo JRoute::_('index.php?option=com_patchtester&view=pull&id='.(int)$item->id); ?>"><?php echo $item->title; ?></a>
|
||||
</td>
|
||||
<td class="center">
|
||||
<?php
|
||||
if ($patch && $patch->applied) {
|
||||
echo JText::_('COM_PATCHTESTER_APPLIED');
|
||||
} else {
|
||||
echo JText::_('COM_PATCHTESTER_NOT_APPLIED');
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td class="center">
|
||||
<?php
|
||||
if ($patch && $patch->applied) {
|
||||
echo '<a href="javascript:submitpatch(\'pull.revert\', '.(int)$patch->id.');">'.JText::_('COM_PATCHTESTER_REVERT_PATCH').'</a>';
|
||||
} else {
|
||||
echo '<a href="javascript:submitpatch(\'pull.apply\', '.(int)$item->number.');">'.JText::_('COM_PATCHTESTER_APPLY_PATCH').'</a>';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div>
|
||||
<input type="hidden" name="task" value="" />
|
||||
<input type="hidden" name="boxchecked" value="0" />
|
||||
<input type="hidden" name="pull_id" id="pull_id" value="" />
|
||||
<?php echo JHtml::_('form.token'); ?>
|
||||
</div>
|
||||
</form>
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @package PatchTester
|
||||
* @copyright Copyright (C) 2011 Ian MacLennan, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
jimport('joomla.application.component.view');
|
||||
|
||||
/**
|
||||
* View class for a list of pull requests.
|
||||
*
|
||||
* @package PatchTester
|
||||
*/
|
||||
class PatchtesterViewPulls extends JView
|
||||
{
|
||||
protected $items;
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* Display the view
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$this->state = $this->get('State');
|
||||
$this->items = $this->get('Items');
|
||||
$this->patches = $this->get('AppliedPatches');
|
||||
|
||||
// Check for errors.
|
||||
if (count($errors = $this->get('Errors'))) {
|
||||
JError::raiseError(500, implode("\n", $errors));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->addToolbar();
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the page title and toolbar.
|
||||
*/
|
||||
protected function addToolbar()
|
||||
{
|
||||
JToolBarHelper::title('Joomla! Patch Tester');
|
||||
JToolBarHelper::preferences('com_patchtester');
|
||||
}
|
||||
}
|
0
components/com_patchtester/index.html
Normal file
0
components/com_patchtester/index.html
Normal file
0
components/com_patchtester/patchtester.php
Normal file
0
components/com_patchtester/patchtester.php
Normal file
177
libraries/joomla/client/github.php
Executable file
177
libraries/joomla/client/github.php
Executable file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
jimport('joomla.environment.uri');
|
||||
jimport('joomla.client.http');
|
||||
JLoader::register('JHttpResponse', JPATH_PLATFORM.'/joomla/client/http.php');
|
||||
jimport('joomla.client.github.githubpulls');
|
||||
jimport('joomla.client.github.githubgists');
|
||||
jimport('joomla.client.github.githubissues');
|
||||
jimport('joomla.client.githubobject');
|
||||
|
||||
/**
|
||||
* HTTP client class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since 11.1
|
||||
*/
|
||||
class JGithub
|
||||
{
|
||||
const AUTHENTICATION_NONE = 0;
|
||||
const AUTHENTICATION_BASIC = 1;
|
||||
const AUTHENTICATION_OAUTH = 2;
|
||||
|
||||
/**
|
||||
* Authentication Method
|
||||
*
|
||||
* Possible values are 0 - no authentication, 1 - basic authentication, 2 - OAuth
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $authentication_method = 0;
|
||||
|
||||
protected $gists = null;
|
||||
|
||||
protected $issues = null;
|
||||
|
||||
protected $pulls = null;
|
||||
|
||||
protected $credentials = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $options Array of configuration options for the client.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if (isset($options['username']) && isset($options['password'])) {
|
||||
$this->credentials['username'] = $options['username'];
|
||||
$this->credentials['password'] = $options['password'];
|
||||
$this->authentication_method = JGithub::AUTHENTICATION_BASIC;
|
||||
} elseif (isset($options['token'])) {
|
||||
$this->credentials['token'] = $options['token'];
|
||||
$this->authentication_method = JGithub::AUTHENTICATION_OAUTH;
|
||||
} else {
|
||||
$this->authentication_method = JGithub::AUTHENTICATION_NONE;
|
||||
}
|
||||
|
||||
$this->http = curl_init();
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
if ($name == 'gists') {
|
||||
if ($this->gists == null) {
|
||||
$this->gists = new JGithubGists($this);
|
||||
}
|
||||
return $this->gists;
|
||||
}
|
||||
|
||||
if ($name == 'issues') {
|
||||
if ($this->issues == null) {
|
||||
$this->issues = new JGithubIssues($this);
|
||||
}
|
||||
return $this->issues;
|
||||
}
|
||||
|
||||
if ($name == 'pulls') {
|
||||
if ($this->pulls == null) {
|
||||
$this->pulls = new JGithubPulls($this);
|
||||
}
|
||||
return $this->pulls;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function sendRequest($url, $method = 'get', $data = array(), $options = array())
|
||||
{
|
||||
|
||||
$this->http = curl_init();
|
||||
|
||||
$curl_options = array(
|
||||
CURLOPT_URL => 'https://api.github.com'.$url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_FOLLOWLOCATION => false,
|
||||
CURLOPT_USERAGENT => 'JGithub',
|
||||
CURLOPT_CONNECTTIMEOUT => 120,
|
||||
CURLOPT_TIMEOUT => 120,
|
||||
CURLINFO_HEADER_OUT => true,
|
||||
CURLOPT_HTTPHEADER => array('Content-type: application/json')
|
||||
);
|
||||
|
||||
switch ($this->authentication_method)
|
||||
{
|
||||
case JGithub::AUTHENTICATION_BASIC:
|
||||
$curl_options[CURLOPT_USERPWD] = $this->credentials['username'].':'.$this->credentials['password'];
|
||||
break;
|
||||
|
||||
case JGithub::AUTHENTICATION_OAUTH:
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?access_token='.$this->credentials['token'];
|
||||
} else {
|
||||
$url .= '&access_token='.$this->credentials['token'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
switch ($method) {
|
||||
case 'post':
|
||||
$curl_options[CURLOPT_POST] = 1;
|
||||
$curl_options[CURLOPT_POSTFIELDS] = json_encode($data);
|
||||
break;
|
||||
|
||||
case 'put':
|
||||
$curl_options[CURLOPT_POST] = 1;
|
||||
$curl_options[CURLOPT_POSTFIELDS] = '';
|
||||
$curl_options[CURLOPT_CUSTOMREQUEST] = 'PUT';
|
||||
$curl_options[CURLOPT_HTTPGET] = false;
|
||||
break;
|
||||
|
||||
case 'patch':
|
||||
$curl_options[CURLOPT_POSTFIELDS] = json_encode($data);
|
||||
case 'delete':
|
||||
$curl_options[CURLOPT_CUSTOMREQUEST] = strtoupper($method);
|
||||
$curl_options[CURLOPT_POST] = false;
|
||||
$curl_options[CURLOPT_HTTPGET] = false;
|
||||
|
||||
break;
|
||||
|
||||
case 'get':
|
||||
$curl_options[CURLOPT_POSTFIELDS] = null;
|
||||
$curl_options[CURLOPT_POST] = false;
|
||||
$curl_options[CURLOPT_HTTPGET] = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
curl_setopt_array($this->http, $curl_options);
|
||||
|
||||
$response = new JHttpResponse;
|
||||
$response->body = json_decode(curl_exec($this->http));
|
||||
|
||||
$request_data = curl_getinfo($this->http);
|
||||
$response->headers = $request_data['request_header'];
|
||||
$response->code = $request_data['http_code'];
|
||||
|
||||
curl_close($this->http);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
182
libraries/joomla/client/github/githubgists.php
Normal file
182
libraries/joomla/client/github/githubgists.php
Normal file
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* HTTP client class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since 11.1
|
||||
*/
|
||||
class JGithubGists
|
||||
{
|
||||
/**
|
||||
* Github Connector
|
||||
*
|
||||
* @var JGithub
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $connector = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $options Array of configuration options for the client.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($connector, $options = array())
|
||||
{
|
||||
$this->connector = $connector;
|
||||
}
|
||||
|
||||
protected function paginate($url, $page = 0, $per_page = 0)
|
||||
{
|
||||
//TODO: Make a new base class and move paginate into it
|
||||
$query_string = array();
|
||||
|
||||
if ($page > 0) {
|
||||
$query_string[] = 'page='.(int)$page;
|
||||
}
|
||||
|
||||
if ($per_page > 0) {
|
||||
$query_string[] = 'per_page='.(int)$per_page;
|
||||
}
|
||||
|
||||
if (isset($query_string[0])) {
|
||||
$query = implode('&', $query_string);
|
||||
} else {
|
||||
$query = '';
|
||||
}
|
||||
|
||||
if (strlen($query) > 0) {
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?'.$query;
|
||||
} else {
|
||||
$url .= '&'.$query;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function getAll($page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/gists';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getByUser($user, $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/users/'.$user.'/gists';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getPublic($page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/gists/public';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getStarred($page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/gists/starred';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function get($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id)->body;
|
||||
}
|
||||
|
||||
public function create($files, $public = false, $description = null)
|
||||
{
|
||||
$gist = new stdClass;
|
||||
$gist->public = $public;
|
||||
$gist->files = $files;
|
||||
|
||||
if (!empty($description)) {
|
||||
$gist->description = $description;
|
||||
}
|
||||
|
||||
return $this->connector->sendRequest('/gists', 'post', $gist)->body;
|
||||
}
|
||||
|
||||
public function edit($gist_id, $files, $description = null)
|
||||
{
|
||||
$gist = new stdClass;
|
||||
$gist->files = $files;
|
||||
|
||||
if (!empty($description)) {
|
||||
$gist->description = $description;
|
||||
}
|
||||
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id, 'patch', $gist)->body;
|
||||
}
|
||||
|
||||
public function star($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star', 'put')->body;
|
||||
}
|
||||
|
||||
public function unstar($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star', 'delete')->body;
|
||||
}
|
||||
|
||||
public function isStarred($gist_id)
|
||||
{
|
||||
$response = $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star');
|
||||
|
||||
if ($response->code == '204') {
|
||||
return true;
|
||||
} else { // the code should be 404
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function fork($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/fork', 'put')->body;
|
||||
}
|
||||
|
||||
public function delete($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id, 'delete')->body;
|
||||
}
|
||||
|
||||
public function getComments($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/comments')->body;
|
||||
}
|
||||
|
||||
public function getComment($comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id)->body;
|
||||
}
|
||||
|
||||
public function createComment($gist_id, $comment)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/comments', 'post', array('body' => $comment))->body;
|
||||
}
|
||||
|
||||
public function editComment($comment_id, $comment)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id, 'patch', array('body' => $comment))->body;
|
||||
}
|
||||
|
||||
public function deleteComment($comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id, 'delete')->body;
|
||||
}
|
||||
}
|
190
libraries/joomla/client/github/githubissues.php
Normal file
190
libraries/joomla/client/github/githubissues.php
Normal file
@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* HTTP client class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since 11.1
|
||||
*/
|
||||
class JGithubIssues
|
||||
{
|
||||
/**
|
||||
* Github Connector
|
||||
*
|
||||
* @var JGithub
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $connector = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $options Array of configuration options for the client.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($connector, $options = array())
|
||||
{
|
||||
$this->connector = $connector;
|
||||
}
|
||||
|
||||
protected function paginate($url, $page = 0, $per_page = 0)
|
||||
{
|
||||
//TODO: Make a new base class and move paginate into it
|
||||
$query_string = array();
|
||||
|
||||
if ($page > 0) {
|
||||
$query_string[] = 'page='.(int)$page;
|
||||
}
|
||||
|
||||
if ($per_page > 0) {
|
||||
$query_string[] = 'per_page='.(int)$per_page;
|
||||
}
|
||||
|
||||
if (isset($query_string[0])) {
|
||||
$query = implode('&', $query_string);
|
||||
} else {
|
||||
$query = '';
|
||||
}
|
||||
|
||||
if (strlen($query) > 0) {
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?'.$query;
|
||||
} else {
|
||||
$url .= '&'.$query;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function getAll($parameters = array(), $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/issues';
|
||||
|
||||
$queryString = '';
|
||||
|
||||
foreach ($parameters AS $parameter) {
|
||||
$queryString .= '';
|
||||
}
|
||||
if (isset($options['filter'])) {
|
||||
}
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getByUser($user, $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/users/'.$user.'/gists';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getPublic($page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/gists/public';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getStarred($page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/gists/starred';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function get($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id)->body;
|
||||
}
|
||||
|
||||
public function create($files, $public = false, $description = null)
|
||||
{
|
||||
$gist = new stdClass;
|
||||
$gist->public = $public;
|
||||
$gist->files = $files;
|
||||
|
||||
if (!empty($description)) {
|
||||
$gist->description = $description;
|
||||
}
|
||||
|
||||
return $this->connector->sendRequest('/gists', 'post', $gist)->body;
|
||||
}
|
||||
|
||||
public function edit($gist_id, $files, $description = null)
|
||||
{
|
||||
$gist = new stdClass;
|
||||
$gist->files = $files;
|
||||
|
||||
if (!empty($description)) {
|
||||
$gist->description = $description;
|
||||
}
|
||||
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id, 'patch', $gist)->body;
|
||||
}
|
||||
|
||||
public function star($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star', 'put')->body;
|
||||
}
|
||||
|
||||
public function unstar($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star', 'delete')->body;
|
||||
}
|
||||
|
||||
public function isStarred($gist_id)
|
||||
{
|
||||
$response = $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star');
|
||||
|
||||
if ($response->code == '204') {
|
||||
return true;
|
||||
} else { // the code should be 404
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function fork($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/fork', 'put')->body;
|
||||
}
|
||||
|
||||
public function delete($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id, 'delete')->body;
|
||||
}
|
||||
|
||||
public function getComments($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/comments')->body;
|
||||
}
|
||||
|
||||
public function getComment($comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id)->body;
|
||||
}
|
||||
|
||||
public function createComment($gist_id, $comment)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/comments', 'post', array('body' => $comment))->body;
|
||||
}
|
||||
|
||||
public function editComment($comment_id, $comment)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id, 'patch', array('body' => $comment))->body;
|
||||
}
|
||||
|
||||
public function deleteComment($comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id, 'delete')->body;
|
||||
}
|
||||
}
|
144
libraries/joomla/client/github/githubpulls.php
Normal file
144
libraries/joomla/client/github/githubpulls.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
jimport('joomla.client.githubobject');
|
||||
|
||||
/**
|
||||
* Github Pull Request Class
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since 11.1
|
||||
*/
|
||||
class JGithubPulls extends JGithubObject
|
||||
{
|
||||
public function getAll($user, $repo, $state = 'open', $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/repos/'.$user.'/'.$repo.'/pulls'.($state == 'closed' ? '?state=closed' : '');
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function get($user, $repo, $pull_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id)->body;
|
||||
}
|
||||
|
||||
public function create($user, $repo, $title, $base, $head, $body = '')
|
||||
{
|
||||
$pull = new stdClass;
|
||||
$pull->title = $title;
|
||||
$pull->base = $base;
|
||||
$pull->head = $head;
|
||||
$pull->body = $body;
|
||||
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls', 'post', $pull)->body;
|
||||
}
|
||||
|
||||
public function createFromIssue($user, $repo, $issue, $base, $head)
|
||||
{
|
||||
$pull = new stdClass;
|
||||
$pull->issue = (int)$issue;
|
||||
$pull->base = $base;
|
||||
$pull->head = $head;
|
||||
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls', 'post', $pull)->body;
|
||||
}
|
||||
|
||||
public function edit($user, $repo, $id, $title = null, $body = null, $state = null)
|
||||
{
|
||||
$pull = new stdClass;
|
||||
|
||||
if (isset($title)) {
|
||||
$pull->title = $title;
|
||||
}
|
||||
|
||||
if (isset($body)) {
|
||||
$pull->body = $body;
|
||||
}
|
||||
|
||||
if (isset($state)) {
|
||||
$pull->state = $state;
|
||||
}
|
||||
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/'.(int)$id, 'patch', $pull)->body;
|
||||
}
|
||||
|
||||
public function getCommits($user, $repo, $pull_id, $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/commits';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getFiles($user, $repo, $pull_id, $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/files';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function isMerged($user, $repo, $pull_id)
|
||||
{
|
||||
$url = '/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/merge';
|
||||
$response = $this->connector->sendRequest($url);
|
||||
|
||||
if ($response->code == '204') {
|
||||
return true;
|
||||
} else { // the code should be 404
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function merge($user, $repo, $pull_id, $commit_message = '')
|
||||
{
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/merge', 'put', array('commit_message' => $commit_message))->body;
|
||||
}
|
||||
|
||||
public function getComments($user, $repo, $pull_id, $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/comments';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getComment($user, $repo, $comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/comments/'.(int)$comment_id)->body;
|
||||
}
|
||||
|
||||
public function createComment($user, $repo, $pull_id, $body, $commit_id, $path, $position)
|
||||
{
|
||||
$comment = new stdClass;
|
||||
$comment->body = $body;
|
||||
$comment->commit_id = $commit_id;
|
||||
$comment->path = $path;
|
||||
$comment->position = $position;
|
||||
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/comments', 'post', $comment)->body;
|
||||
}
|
||||
|
||||
public function createCommentReply($user, $repo, $pull_id, $body, $in_reply_to)
|
||||
{
|
||||
$comment = new stdClass;
|
||||
$comment->body = $body;
|
||||
$comment->in_reply_to = (int)$in_reply_to;
|
||||
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/comments', 'post', $comment)->body;
|
||||
}
|
||||
|
||||
public function editComment($user, $repo, $comment_id, $body)
|
||||
{
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/comments/'.(int)$comment_id, 'patch', array('body' => $body))->body;
|
||||
}
|
||||
|
||||
public function deleteComment($user, $repo, $comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/comments/'.(int)$comment_id, 'delete')->body;
|
||||
}
|
||||
|
||||
}
|
72
libraries/joomla/client/githubobject.php
Executable file
72
libraries/joomla/client/githubobject.php
Executable file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* HTTP client class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since 11.1
|
||||
*/
|
||||
class JGithubObject
|
||||
{
|
||||
/**
|
||||
* Github Connector
|
||||
*
|
||||
* @var JGithub
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $connector = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $options Array of configuration options for the client.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($connector, $options = array())
|
||||
{
|
||||
$this->connector = $connector;
|
||||
}
|
||||
|
||||
protected function paginate($url, $page = 0, $per_page = 0)
|
||||
{
|
||||
//TODO: Make a new base class and move paginate into it
|
||||
$query_string = array();
|
||||
|
||||
if ($page > 0) {
|
||||
$query_string[] = 'page='.(int)$page;
|
||||
}
|
||||
|
||||
if ($per_page > 0) {
|
||||
$query_string[] = 'per_page='.(int)$per_page;
|
||||
}
|
||||
|
||||
if (isset($query_string[0])) {
|
||||
$query = implode('&', $query_string);
|
||||
} else {
|
||||
$query = '';
|
||||
}
|
||||
|
||||
if (strlen($query) > 0) {
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?'.$query;
|
||||
} else {
|
||||
$url .= '&'.$query;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user