Skip to content

Commit 25f3086

Browse files
committed
Do not show apply button for pull requests that require additional steps, make this configurable
Signed-off-by: Roland Dalmulder <contact@rolandd.com>
1 parent 07c2890 commit 25f3086

File tree

4 files changed

+99
-43
lines changed

4 files changed

+99
-43
lines changed

administrator/components/com_patchtester/config.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<config>
3-
<help key="Components_Patch_Tester_Options"/>
3+
<inlinehelp button="show"/>
4+
<fieldset
5+
name="patchtester"
6+
label="COM_PATCHTESTER_FIELDSET_PATCHTESTER_LABEL"
7+
>
8+
<field
9+
name="advanced"
10+
type="radio"
11+
label="COM_PATCHTESTER_FIELD_ADVANCED_LABEL"
12+
description="COM_PATCHTESTER_FIELD_ADVANCED_DESC"
13+
layout="joomla.form.field.radio.switcher"
14+
default="0"
15+
>
16+
<option value="0">JNO</option>
17+
<option value="1">JYES</option>
18+
</field>
19+
</fieldset>
420
<fieldset
521
name="repositories"
622
label="COM_PATCHTESTER_FIELDSET_REPOSITORIES_LABEL"

administrator/components/com_patchtester/language/en-GB/com_patchtester.sys.ini

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
COM_PATCHTESTER="Joomla! Patch Tester"
77
COM_PATCHTESTER_COULD_NOT_INSTALL_OVERRIDES="Could not install the template overrides for the following templates: %s"
88
COM_PATCHTESTER_COULD_NOT_REMOVE_OVERRIDES="Could not remove the template overrides for the following templates: %s"
9-
COM_PATCHTESTER_XML_DESCRIPTION="Component for pull request management testing"
10-
COM_PATCHTESTER_UPDATE_TEXT="Patch Tester Update script. Patch Tester now updated to version %s."
9+
COM_PATCHTESTER_FIELDSET_PATCHTESTER_LABEL="Patch Tester"
10+
COM_PATCHTESTER_FIELD_ADVANCED_DESC="Show the Apply button for pull requests that require additional steps such as the use of composer or node package manager."
11+
COM_PATCHTESTER_FIELD_ADVANCED_LABEL="Advanced"
1112
COM_PATCHTESTER_INSTALL_INSTRUCTIONS="<p>Thank you for installing the Joomla! Patch Tester.</p><p>To use the Joomla! Patch Tester you first need to setup your GitHub credentials in the Joomla! Patch Tester Options. <a href=\"index.php?option=com_config&view=component&component=com_patchtester&returnurl=aW5kZXgucGhwP29wdGlvbj1jb21fcGF0Y2h0ZXN0ZXI=#authentication\" alt=\"Go to Options\">Go to the Joomla! Patch Tester Options</a> to setup your credentials. After clicking on Save & Close you will be taken to the Joomla! Patch Tester where you can start using the Patch Tester."
12-
COM_PATCHTESTER_UPDATE_INSTRUCTIONS="<p>Thank you for updating the Joomla! Patch Tester.</p><p><a href=\"index.php?option=com_patchtester\" alt=\"Go to Patch Tester\">Go to the Joomla! Patch Tester</a></p>"
1313
COM_PATCHTESTER_UNINSTALL_THANK_YOU="Thank you for using the Joomla! Patch Tester for testing patches for the latest version of Joomla!"
14+
COM_PATCHTESTER_UPDATE_INSTRUCTIONS="<p>Thank you for updating the Joomla! Patch Tester.</p><p><a href=\"index.php?option=com_patchtester\" alt=\"Go to Patch Tester\">Go to the Joomla! Patch Tester</a></p>"
15+
COM_PATCHTESTER_UPDATE_TEXT="Patch Tester Update script. Patch Tester now updated to version %s."
16+
COM_PATCHTESTER_XML_DESCRIPTION="Component for pull request management testing"

administrator/components/com_patchtester/src/View/Pulls/HtmlView.php

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Joomla\Component\Patchtester\Administrator\View\Pulls;
1111

1212
use Exception;
13+
use Joomla\CMS\Component\ComponentHelper;
1314
use Joomla\CMS\Form\Form;
1415
use Joomla\CMS\Language\Text;
1516
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
@@ -32,62 +33,75 @@
3233
*/
3334
class HtmlView extends BaseHtmlView
3435
{
36+
/**
37+
* Form object for search filters
38+
*
39+
* @var Form
40+
* @since 4.1.0
41+
*/
42+
public $filterForm;
43+
44+
/**
45+
* The active search filters
46+
*
47+
* @var array
48+
* @since 4.1.0
49+
*/
50+
public $activeFilters;
51+
3552
/**
3653
* Array containing environment errors
3754
*
3855
* @var array
3956
* @since 2.0
4057
*/
4158
protected $envErrors = [];
42-
/**
59+
60+
/**
4361
* Array of open pull requests
4462
*
4563
* @var array
4664
* @since 2.0
4765
*/
4866
protected $items;
49-
/**
67+
68+
/**
5069
* Pagination object
5170
*
5271
* @var Pagination
5372
* @since 2.0
5473
*/
5574
protected $pagination;
56-
/**
57-
* Form object for search filters
58-
*
59-
* @var Form
60-
* @since 4.1.0
61-
*/
62-
public $filterForm;
63-
/**
64-
* The active search filters
65-
*
66-
* @var array
67-
* @since 4.1.0
68-
*/
69-
public $activeFilters;
70-
/**
75+
76+
/**
7177
* The model state
7278
*
7379
* @var Registry
7480
* @since 2.0.0
7581
*/
7682
protected $state;
77-
/**
83+
84+
/**
7885
* The issue tracker project alias
7986
*
8087
* @var string|boolean
8188
* @since 2.0
8289
*/
8390
protected $trackerAlias;
84-
/**
91+
92+
/**
93+
* @var Registry
94+
* @since 4.4.0
95+
*/
96+
protected $settings;
97+
98+
/**
8599
* Method to render the view.
86100
*
87101
* @return void
88102
*
89-
* @since 2.0.0
90103
* @throws Exception
104+
* @since 2.0.0
91105
*/
92106
public function display($tpl = null): void
93107
{
@@ -106,10 +120,13 @@ public function display($tpl = null): void
106120
$this->pagination = $model->getPagination();
107121
$this->filterForm = $model->getFilterForm();
108122
$this->activeFilters = $model->getActiveFilters();
109-
$this->trackerAlias = TrackerHelper::getTrackerAlias($this->state->get('github_user'), $this->state->get('github_repo'));
123+
$this->settings = ComponentHelper::getParams('com_patchtester');
124+
$this->trackerAlias = TrackerHelper::getTrackerAlias(
125+
$this->state->get('github_user'),
126+
$this->state->get('github_repo')
127+
);
110128
}
111129

112-
// Change the layout if there are environment errors
113130
if (count($this->envErrors)) {
114131
$this->setLayout('errors');
115132
}
@@ -132,7 +149,18 @@ protected function addToolbar(): void
132149
ToolbarHelper::title(Text::_('COM_PATCHTESTER'), 'patchtester fas fa-save');
133150
if (!count($this->envErrors)) {
134151
$toolbar = Toolbar::getInstance('toolbar');
135-
$toolbar->appendButton('Popup', 'sync', 'COM_PATCHTESTER_TOOLBAR_FETCH_DATA', 'index.php?option=com_patchtester&view=fetch&task=fetch&tmpl=component', 500, 210, 0, 0, 'window.parent.location.reload()', Text::_('COM_PATCHTESTER_HEADING_FETCH_DATA'));
152+
$toolbar->appendButton(
153+
'Popup',
154+
'sync',
155+
'COM_PATCHTESTER_TOOLBAR_FETCH_DATA',
156+
'index.php?option=com_patchtester&view=fetch&task=fetch&tmpl=component',
157+
500,
158+
210,
159+
0,
160+
0,
161+
'window.parent.location.reload()',
162+
Text::_('COM_PATCHTESTER_HEADING_FETCH_DATA')
163+
);
136164
$toolbar->appendButton('Standard', 'expired', 'COM_PATCHTESTER_TOOLBAR_RESET', 'reset.reset', false);
137165
}
138166

administrator/components/com_patchtester/tmpl/pulls/default_items.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
*/
99

1010
use Joomla\CMS\Language\Text;
11-
use Joomla\Component\Patchtester\Administrator\View\Pulls\PullsHtmlView;
11+
use Joomla\Component\Patchtester\Administrator\View\Pulls\HtmlView;
1212

1313
// phpcs:disable PSR1.Files.SideEffects
1414
\defined('_JEXEC') or die;
1515
// phpcs:enable PSR1.Files.SideEffects
1616

17-
/** @var PullsHtmlView $this */
17+
/** @var HtmlView $this */
1818

1919
foreach ($this->items as $i => $item) :
2020
$status = '';
@@ -91,11 +91,9 @@
9191
case 'test instructions missing':
9292
case 'updates requested':
9393
$textColor = '000000';
94-
9594
break;
9695
default:
9796
$textColor = 'FFFFFF';
98-
9997
break;
10098
}
10199
?>
@@ -133,18 +131,29 @@
133131
endif; ?>
134132
</td>
135133
<td class="text-center">
136-
<?php if ($item->applied) :
137-
?>
138-
<button type="button" class="btn btn-sm btn-success submitPatch"
139-
data-task="revert" data-id="<?php echo (int) $item->applied; ?>"><?php echo Text::_('COM_PATCHTESTER_REVERT_PATCH'); ?></button>
140-
<?php
141-
else :
142-
?>
143-
<button type="button" class="btn btn-sm btn-primary submitPatch"
144-
data-task="apply" data-id="<?php echo (int) $item->pull_id; ?>"><?php echo Text::_('COM_PATCHTESTER_APPLY_PATCH'); ?></button>
145-
<?php
146-
endif; ?>
147-
</td>
134+
<?php $hideButton = function($labels) {
135+
foreach ($labels as $label) {
136+
if (in_array(strtolower($label->name), ['npm resource changed', 'composer dependency changed', 'rtc'])) {
137+
return true;
138+
}
139+
}
140+
141+
return false;
142+
};?>
143+
<?php if ($this->settings->get('advanced', 0) || !$hideButton($item->labels)) : ?>
144+
<?php if ($item->applied) :
145+
?>
146+
<button type="button" class="btn btn-sm btn-success submitPatch"
147+
data-task="revert" data-id="<?php echo (int) $item->applied; ?>"><?php echo Text::_('COM_PATCHTESTER_REVERT_PATCH'); ?></button>
148+
<?php
149+
else :
150+
?>
151+
<button type="button" class="btn btn-sm btn-primary submitPatch"
152+
data-task="apply" data-id="<?php echo (int) $item->pull_id; ?>"><?php echo Text::_('COM_PATCHTESTER_APPLY_PATCH'); ?></button>
153+
<?php
154+
endif; ?>
155+
<?php endif; ?>
156+
</td>
148157
</tr>
149158
<?php
150159
endforeach;

0 commit comments

Comments
 (0)