@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Create option for differential custom fields to display warning on accept

Summary:
This adds support to differential fields to display warnings before a revision
gets accepted. Since lint and unit are differential fields, the code for their
warnings was moved into their respective field specification classes, so there
is only one code path for warnings (lint, unit, or custom).

Test Plan:
Select 'Accept' on a revision with lint/unit warnings and see messages appear
like they used to. Change it back to 'Comment' and they go away. Repeat with
a revision without lint/unit warnings and see no warnings appear. Checked
darkconsole to see no errors due to this.

Reviewers: jungejason, epriestley, vrana

Reviewed By: epriestley

CC: aran, Koolvin

Differential Revision: https://secure.phabricator.com/D2363

+118 -78
+21 -21
src/__celerity_resource_map__.php
··· 857 857 ), 858 858 'javelin-behavior-differential-accept-with-errors' => 859 859 array( 860 - 'uri' => '/res/41c4685b/rsrc/js/application/differential/behavior-accept-with-errors.js', 860 + 'uri' => '/res/ba5144c5/rsrc/js/application/differential/behavior-accept-with-errors.js', 861 861 'type' => 'js', 862 862 'requires' => 863 863 array( ··· 2525 2525 'uri' => '/res/pkg/27683aba/differential.pkg.css', 2526 2526 'type' => 'css', 2527 2527 ), 2528 - 70509835 => 2528 + '5e9ae855' => 2529 2529 array( 2530 2530 'name' => 'differential.pkg.js', 2531 2531 'symbols' => ··· 2549 2549 16 => 'javelin-behavior-differential-dropdown-menus', 2550 2550 17 => 'javelin-behavior-buoyant', 2551 2551 ), 2552 - 'uri' => '/res/pkg/70509835/differential.pkg.js', 2552 + 'uri' => '/res/pkg/5e9ae855/differential.pkg.js', 2553 2553 'type' => 'js', 2554 2554 ), 2555 2555 'c8ce2d88' => ··· 2657 2657 'aphront-typeahead-control-css' => '9c4e265b', 2658 2658 'differential-changeset-view-css' => '27683aba', 2659 2659 'differential-core-view-css' => '27683aba', 2660 - 'differential-inline-comment-editor' => '70509835', 2660 + 'differential-inline-comment-editor' => '5e9ae855', 2661 2661 'differential-local-commits-view-css' => '27683aba', 2662 2662 'differential-results-table-css' => '27683aba', 2663 2663 'differential-revision-add-comment-css' => '27683aba', ··· 2670 2670 'inline-comment-summary-css' => '27683aba', 2671 2671 'javelin-behavior' => '8a5de8a3', 2672 2672 'javelin-behavior-aphront-basic-tokenizer' => '97f65640', 2673 - 'javelin-behavior-aphront-drag-and-drop' => '70509835', 2674 - 'javelin-behavior-aphront-drag-and-drop-textarea' => '70509835', 2673 + 'javelin-behavior-aphront-drag-and-drop' => '5e9ae855', 2674 + 'javelin-behavior-aphront-drag-and-drop-textarea' => '5e9ae855', 2675 2675 'javelin-behavior-aphront-form-disable-on-submit' => '0c96375e', 2676 2676 'javelin-behavior-audit-preview' => '5e68be89', 2677 - 'javelin-behavior-buoyant' => '70509835', 2678 - 'javelin-behavior-differential-accept-with-errors' => '70509835', 2679 - 'javelin-behavior-differential-add-reviewers-and-ccs' => '70509835', 2680 - 'javelin-behavior-differential-comment-jump' => '70509835', 2681 - 'javelin-behavior-differential-diff-radios' => '70509835', 2682 - 'javelin-behavior-differential-dropdown-menus' => '70509835', 2683 - 'javelin-behavior-differential-edit-inline-comments' => '70509835', 2684 - 'javelin-behavior-differential-feedback-preview' => '70509835', 2685 - 'javelin-behavior-differential-keyboard-navigation' => '70509835', 2686 - 'javelin-behavior-differential-populate' => '70509835', 2687 - 'javelin-behavior-differential-show-more' => '70509835', 2677 + 'javelin-behavior-buoyant' => '5e9ae855', 2678 + 'javelin-behavior-differential-accept-with-errors' => '5e9ae855', 2679 + 'javelin-behavior-differential-add-reviewers-and-ccs' => '5e9ae855', 2680 + 'javelin-behavior-differential-comment-jump' => '5e9ae855', 2681 + 'javelin-behavior-differential-diff-radios' => '5e9ae855', 2682 + 'javelin-behavior-differential-dropdown-menus' => '5e9ae855', 2683 + 'javelin-behavior-differential-edit-inline-comments' => '5e9ae855', 2684 + 'javelin-behavior-differential-feedback-preview' => '5e9ae855', 2685 + 'javelin-behavior-differential-keyboard-navigation' => '5e9ae855', 2686 + 'javelin-behavior-differential-populate' => '5e9ae855', 2687 + 'javelin-behavior-differential-show-more' => '5e9ae855', 2688 2688 'javelin-behavior-diffusion-commit-graph' => '5e68be89', 2689 2689 'javelin-behavior-diffusion-pull-lastmodified' => '5e68be89', 2690 2690 'javelin-behavior-maniphest-batch-selector' => '7707de41', ··· 2694 2694 'javelin-behavior-maniphest-transaction-preview' => '7707de41', 2695 2695 'javelin-behavior-phabricator-autofocus' => '0c96375e', 2696 2696 'javelin-behavior-phabricator-keyboard-shortcuts' => '0c96375e', 2697 - 'javelin-behavior-phabricator-object-selector' => '70509835', 2697 + 'javelin-behavior-phabricator-object-selector' => '5e9ae855', 2698 2698 'javelin-behavior-phabricator-oncopy' => '0c96375e', 2699 2699 'javelin-behavior-phabricator-tooltips' => '0c96375e', 2700 2700 'javelin-behavior-phabricator-watch-anchor' => '0c96375e', 2701 2701 'javelin-behavior-refresh-csrf' => '0c96375e', 2702 - 'javelin-behavior-repository-crossreference' => '70509835', 2702 + 'javelin-behavior-repository-crossreference' => '5e9ae855', 2703 2703 'javelin-behavior-workflow' => '0c96375e', 2704 2704 'javelin-dom' => '8a5de8a3', 2705 2705 'javelin-event' => '8a5de8a3', ··· 2725 2725 'phabricator-core-buttons-css' => '9c4e265b', 2726 2726 'phabricator-core-css' => '9c4e265b', 2727 2727 'phabricator-directory-css' => '9c4e265b', 2728 - 'phabricator-drag-and-drop-file-upload' => '70509835', 2728 + 'phabricator-drag-and-drop-file-upload' => '5e9ae855', 2729 2729 'phabricator-dropdown-menu' => '0c96375e', 2730 2730 'phabricator-flag-css' => '9c4e265b', 2731 2731 'phabricator-jump-nav' => '9c4e265b', ··· 2737 2737 'phabricator-prefab' => '0c96375e', 2738 2738 'phabricator-project-tag-css' => '7839ae2d', 2739 2739 'phabricator-remarkup-css' => '9c4e265b', 2740 - 'phabricator-shaped-request' => '70509835', 2740 + 'phabricator-shaped-request' => '5e9ae855', 2741 2741 'phabricator-standard-page-view' => '9c4e265b', 2742 2742 'phabricator-tooltip' => '0c96375e', 2743 2743 'phabricator-transaction-view-css' => '9c4e265b',
+1
src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php
··· 312 312 313 313 $comment_form = new DifferentialAddCommentView(); 314 314 $comment_form->setRevision($revision); 315 + $comment_form->setAuxFields($aux_fields); 315 316 $comment_form->setActions($this->getRevisionCommentActions($revision)); 316 317 $comment_form->setActionURI('/differential/comment/save/'); 317 318 $comment_form->setUser($user);
+12
src/applications/differential/field/specification/base/DifferentialFieldSpecification.php
··· 265 265 } 266 266 267 267 268 + /** 269 + * Return a markup block representing a warning to display with the comment 270 + * box when preparing to accept a diff. A return value of null indicates no 271 + * warning box should be displayed for this field. 272 + * 273 + * @return string|null Display markup for warning box, or null for no warning 274 + */ 275 + public function renderWarningBoxForRevisionAccept() { 276 + return null; 277 + } 278 + 279 + 268 280 /* -( Extending the Revision List Interface )------------------------------ */ 269 281 270 282
+28
src/applications/differential/field/specification/lint/DifferentialLintFieldSpecification.php
··· 197 197 return "Show Full Lint Results (".implode(', ', $show).")"; 198 198 } 199 199 200 + public function renderWarningBoxForRevisionAccept() { 201 + $diff = $this->getDiff(); 202 + $lint_warning = null; 203 + if ($diff->getLintStatus() >= DifferentialLintStatus::LINT_WARN) { 204 + $titles = 205 + array( 206 + DifferentialLintStatus::LINT_WARN => 'Lint Warning', 207 + DifferentialLintStatus::LINT_FAIL => 'Lint Failure', 208 + DifferentialLintStatus::LINT_SKIP => 'Lint Skipped' 209 + ); 210 + if ($diff->getLintStatus() == DifferentialLintStatus::LINT_SKIP) { 211 + $content = 212 + "<p>This diff was created without running lint. Make sure you are ". 213 + "OK with that before you accept this diff.</p>"; 214 + } else { 215 + $content = 216 + "<p>This diff has Lint Problems. Make sure you are OK with them ". 217 + "before you accept this diff.</p>"; 218 + } 219 + $lint_warning = id(new AphrontErrorView()) 220 + ->setSeverity(AphrontErrorView::SEVERITY_ERROR) 221 + ->setWidth(AphrontErrorView::WIDTH_WIDE) 222 + ->appendChild($content) 223 + ->setTitle(idx($titles, $diff->getLintStatus(), 'Warning')); 224 + } 225 + return $lint_warning; 226 + } 227 + 200 228 }
+2
src/applications/differential/field/specification/lint/__init__.php
··· 8 8 9 9 phutil_require_module('arcanist', 'lint/severity'); 10 10 11 + phutil_require_module('phabricator', 'applications/differential/constants/lintstatus'); 11 12 phutil_require_module('phabricator', 'applications/differential/field/specification/base'); 12 13 phutil_require_module('phabricator', 'applications/differential/view/resultstableview'); 13 14 phutil_require_module('phabricator', 'applications/differential/view/revisionupdatehistory'); 15 + phutil_require_module('phabricator', 'view/form/error'); 14 16 15 17 phutil_require_module('phutil', 'markup'); 16 18 phutil_require_module('phutil', 'utils');
+34
src/applications/differential/field/specification/unit/DifferentialUnitFieldSpecification.php
··· 182 182 return "Show Full Unit Results (".implode(', ', $show).")"; 183 183 } 184 184 185 + public function renderWarningBoxForRevisionAccept() { 186 + $diff = $this->getDiff(); 187 + $unit_warning = null; 188 + if ($diff->getUnitStatus() >= DifferentialUnitStatus::UNIT_WARN) { 189 + $titles = 190 + array( 191 + DifferentialUnitStatus::UNIT_WARN => 'Unit Tests Warning', 192 + DifferentialUnitStatus::UNIT_FAIL => 'Unit Tests Failure', 193 + DifferentialUnitStatus::UNIT_SKIP => 'Unit Tests Skipped', 194 + DifferentialUnitStatus::UNIT_POSTPONED => 'Unit Tests Postponed' 195 + ); 196 + if ($diff->getUnitStatus() == DifferentialUnitStatus::UNIT_POSTPONED) { 197 + $content = 198 + "<p>This diff has postponed unit tests. The results should be ". 199 + "coming in soon. You should probably wait for them before accepting ". 200 + "this diff.</p>"; 201 + } else if ($diff->getUnitStatus() == DifferentialUnitStatus::UNIT_SKIP) { 202 + $content = 203 + "<p>Unit tests were skipped when this diff was created. Make sure ". 204 + "you are OK with that before you accept this diff.</p>"; 205 + } else { 206 + $content = 207 + "<p>This diff has Unit Test Problems. Make sure you are OK with ". 208 + "them before you accept this diff.</p>"; 209 + } 210 + $unit_warning = id(new AphrontErrorView()) 211 + ->setSeverity(AphrontErrorView::SEVERITY_ERROR) 212 + ->setWidth(AphrontErrorView::WIDTH_WIDE) 213 + ->appendChild($content) 214 + ->setTitle(idx($titles, $diff->getUnitStatus(), 'Warning')); 215 + } 216 + return $unit_warning; 217 + } 218 + 185 219 }
+2
src/applications/differential/field/specification/unit/__init__.php
··· 8 8 9 9 phutil_require_module('arcanist', 'unit/result'); 10 10 11 + phutil_require_module('phabricator', 'applications/differential/constants/unitstatus'); 11 12 phutil_require_module('phabricator', 'applications/differential/field/specification/base'); 12 13 phutil_require_module('phabricator', 'applications/differential/view/resultstableview'); 13 14 phutil_require_module('phabricator', 'applications/differential/view/revisionupdatehistory'); 14 15 phutil_require_module('phabricator', 'applications/markup/engine'); 16 + phutil_require_module('phabricator', 'view/form/error'); 15 17 16 18 phutil_require_module('phutil', 'markup'); 17 19 phutil_require_module('phutil', 'utils');
+17 -53
src/applications/differential/view/addcomment/DifferentialAddCommentView.php
··· 23 23 private $actionURI; 24 24 private $user; 25 25 private $draft; 26 + private $auxFields; 26 27 27 28 public function setRevision($revision) { 28 29 $this->revision = $revision; 30 + return $this; 31 + } 32 + 33 + public function setAuxFields(array $aux_fields) { 34 + assert_instances_of($aux_fields, 'DifferentialFieldSpecification'); 35 + $this->auxFields = $aux_fields; 29 36 return $this; 30 37 } 31 38 ··· 144 151 )); 145 152 146 153 $diff = $revision->loadActiveDiff(); 154 + $warnings = mpull($this->auxFields, 'renderWarningBoxForRevisionAccept'); 147 155 $lint_warning = null; 148 156 $unit_warning = null; 149 - if ($diff->getLintStatus() >= DifferentialLintStatus::LINT_WARN) { 150 - $titles = 151 - array( 152 - DifferentialLintStatus::LINT_WARN => 'Lint Warning', 153 - DifferentialLintStatus::LINT_FAIL => 'Lint Failure', 154 - DifferentialLintStatus::LINT_SKIP => 'Lint Skipped' 155 - ); 156 - if ($diff->getLintStatus() == DifferentialLintStatus::LINT_SKIP) { 157 - $content = 158 - "<p>This diff was created without running lint. Make sure you are ". 159 - "OK with that before you accept this diff.</p>"; 160 - } else { 161 - $content = 162 - "<p>This diff has Lint Problems. Make sure you are OK with them ". 163 - "before you accept this diff.</p>"; 164 - } 165 - $lint_warning = $this->generateWarningView( 166 - $diff->getLintStatus(), 167 - $titles, 168 - 'lint-warning', 169 - $content); 170 - } 171 - 172 - if ($diff->getUnitStatus() >= DifferentialUnitStatus::UNIT_WARN) { 173 - $titles = 174 - array( 175 - DifferentialUnitStatus::UNIT_WARN => 'Unit Tests Warning', 176 - DifferentialUnitStatus::UNIT_FAIL => 'Unit Tests Failure', 177 - DifferentialUnitStatus::UNIT_SKIP => 'Unit Tests Skipped', 178 - DifferentialUnitStatus::UNIT_POSTPONED => 'Unit Tests Postponed' 179 - ); 180 - if ($diff->getUnitStatus() == DifferentialUnitStatus::UNIT_POSTPONED) { 181 - $content = 182 - "<p>This diff has postponed unit tests. The results should be ". 183 - "coming in soon. You should probably wait for them before accepting ". 184 - "this diff.</p>"; 185 - } else if ($diff->getUnitStatus() == DifferentialUnitStatus::UNIT_SKIP) { 186 - $content = 187 - "<p>Unit tests were skipped when this diff was created. Make sure ". 188 - "you are OK with that before you accept this diff.</p>"; 189 - } else { 190 - $content = 191 - "<p>This diff has Unit Test Problems. Make sure you are OK with ". 192 - "them before you accept this diff.</p>"; 193 - } 194 - $unit_warning = $this->generateWarningView( 195 - $diff->getUnitStatus(), 196 - $titles, 197 - 'unit-warning', 198 - $content); 199 - } 200 157 201 158 Javelin::initBehavior( 202 159 'differential-accept-with-errors', 203 160 array( 204 161 'select' => 'comment-action', 205 - 'lint_warning' => $lint_warning ? 'lint-warning' : null, 206 - 'unit_warning' => $unit_warning ? 'unit-warning' : null, 162 + 'warnings' => 'warnings', 207 163 )); 208 164 209 165 $rev_id = $revision->getID(); ··· 226 182 227 183 $panel_view = new AphrontPanelView(); 228 184 $panel_view->appendChild($form); 185 + $warning_container = '<div id="warnings">'; 186 + foreach ($warnings as $warning) { 187 + if ($warning) { 188 + $warning_container .= $warning->render(); 189 + } 190 + } 191 + $warning_container .= '</div>'; 192 + $panel_view->appendChild($warning_container); 229 193 if ($lint_warning) { 230 194 $panel_view->appendChild($lint_warning); 231 195 }
-2
src/applications/differential/view/addcomment/__init__.php
··· 6 6 7 7 8 8 9 - phutil_require_module('phabricator', 'applications/differential/constants/lintstatus'); 10 - phutil_require_module('phabricator', 'applications/differential/constants/unitstatus'); 11 9 phutil_require_module('phabricator', 'infrastructure/celerity/api'); 12 10 phutil_require_module('phabricator', 'infrastructure/env'); 13 11 phutil_require_module('phabricator', 'infrastructure/javelin/api');
+1 -2
webroot/rsrc/js/application/differential/behavior-accept-with-errors.js
··· 23 23 } 24 24 } 25 25 26 - toggleWarning(config.unit_warning); 27 - toggleWarning(config.lint_warning); 26 + toggleWarning(config.warnings); 28 27 });