@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.

Add support for branch-related configuration to new Repository edit workflow

Summary: Ref T2231. Modernizes editing "Default Branch", "Track Only", and "Autoclose Only".

Test Plan: See screenshots.

Reviewers: btrahan, chad

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2231

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

+329
+2
src/__phutil_library_map__.php
··· 506 506 'DiffusionRepositoryCreateController' => 'applications/diffusion/controller/DiffusionRepositoryCreateController.php', 507 507 'DiffusionRepositoryEditActivateController' => 'applications/diffusion/controller/DiffusionRepositoryEditActivateController.php', 508 508 'DiffusionRepositoryEditBasicController' => 'applications/diffusion/controller/DiffusionRepositoryEditBasicController.php', 509 + 'DiffusionRepositoryEditBranchesController' => 'applications/diffusion/controller/DiffusionRepositoryEditBranchesController.php', 509 510 'DiffusionRepositoryEditController' => 'applications/diffusion/controller/DiffusionRepositoryEditController.php', 510 511 'DiffusionRepositoryEditEncodingController' => 'applications/diffusion/controller/DiffusionRepositoryEditEncodingController.php', 511 512 'DiffusionRepositoryEditPolicyController' => 'applications/diffusion/controller/DiffusionRepositoryEditPolicyController.php', ··· 2677 2678 'DiffusionRepositoryCreateController' => 'DiffusionController', 2678 2679 'DiffusionRepositoryEditActivateController' => 'DiffusionController', 2679 2680 'DiffusionRepositoryEditBasicController' => 'DiffusionController', 2681 + 'DiffusionRepositoryEditBranchesController' => 'DiffusionController', 2680 2682 'DiffusionRepositoryEditController' => 'DiffusionController', 2681 2683 'DiffusionRepositoryEditEncodingController' => 'DiffusionController', 2682 2684 'DiffusionRepositoryEditPolicyController' => 'DiffusionController',
+1
src/applications/diffusion/application/PhabricatorApplicationDiffusion.php
··· 69 69 'encoding/' => 'DiffusionRepositoryEditEncodingController', 70 70 'activate/' => 'DiffusionRepositoryEditActivateController', 71 71 'policy/' => 'DiffusionRepositoryEditPolicyController', 72 + 'branches/' => 'DiffusionRepositoryEditBranchesController', 72 73 ), 73 74 ), 74 75 'inline/' => array(
+147
src/applications/diffusion/controller/DiffusionRepositoryEditBranchesController.php
··· 1 + <?php 2 + 3 + final class DiffusionRepositoryEditBranchesController 4 + extends DiffusionController { 5 + 6 + public function processRequest() { 7 + $request = $this->getRequest(); 8 + $viewer = $request->getUser(); 9 + $drequest = $this->diffusionRequest; 10 + $repository = $drequest->getRepository(); 11 + 12 + $repository = id(new PhabricatorRepositoryQuery()) 13 + ->setViewer($viewer) 14 + ->requireCapabilities( 15 + array( 16 + PhabricatorPolicyCapability::CAN_VIEW, 17 + PhabricatorPolicyCapability::CAN_EDIT, 18 + )) 19 + ->withIDs(array($repository->getID())) 20 + ->executeOne(); 21 + 22 + if (!$repository) { 23 + return new Aphront404Response(); 24 + } 25 + 26 + switch ($repository->getVersionControlSystem()) { 27 + case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 28 + case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: 29 + break; 30 + case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 31 + throw new Exception( 32 + pht('Subversion does not support branches!')); 33 + default: 34 + throw new Exception( 35 + pht('Repository has unknown version control system!')); 36 + } 37 + 38 + $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 39 + 40 + $v_default = $repository->getHumanReadableDetail('default-branch'); 41 + $v_track = $repository->getHumanReadableDetail('branch-filter'); 42 + $v_autoclose = $repository->getHumanReadableDetail('close-commits-filter'); 43 + 44 + if ($request->isFormPost()) { 45 + $v_default = $request->getStr('default'); 46 + $v_track = $request->getStrList('track'); 47 + $v_autoclose = $request->getStrList('autoclose'); 48 + 49 + $xactions = array(); 50 + $template = id(new PhabricatorRepositoryTransaction()); 51 + 52 + $type_default = PhabricatorRepositoryTransaction::TYPE_DEFAULT_BRANCH; 53 + $type_track = PhabricatorRepositoryTransaction::TYPE_TRACK_ONLY; 54 + $type_autoclose = PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE_ONLY; 55 + 56 + $xactions[] = id(clone $template) 57 + ->setTransactionType($type_default) 58 + ->setNewValue($v_default); 59 + 60 + $xactions[] = id(clone $template) 61 + ->setTransactionType($type_track) 62 + ->setNewValue($v_track); 63 + 64 + $xactions[] = id(clone $template) 65 + ->setTransactionType($type_autoclose) 66 + ->setNewValue($v_autoclose); 67 + 68 + id(new PhabricatorRepositoryEditor()) 69 + ->setContinueOnNoEffect(true) 70 + ->setContentSourceFromRequest($request) 71 + ->setActor($viewer) 72 + ->applyTransactions($repository, $xactions); 73 + 74 + return id(new AphrontRedirectResponse())->setURI($edit_uri); 75 + } 76 + 77 + $content = array(); 78 + 79 + $crumbs = $this->buildCrumbs(); 80 + $crumbs->addCrumb( 81 + id(new PhabricatorCrumbView()) 82 + ->setName(pht('Edit Branches'))); 83 + 84 + $title = pht('Edit Branches (%s)', $repository->getName()); 85 + 86 + $policies = id(new PhabricatorPolicyQuery()) 87 + ->setViewer($viewer) 88 + ->setObject($repository) 89 + ->execute(); 90 + 91 + $form = id(new AphrontFormView()) 92 + ->setUser($viewer) 93 + ->appendRemarkupInstructions( 94 + pht( 95 + 'You can choose a **Default Branch** for viewing this repository.'. 96 + "\n\n". 97 + 'If you want to import only some branches into Diffusion, you can '. 98 + 'list them in **Track Only**. Other branches will be ignored. If '. 99 + 'you do not specify any branches, all branches are tracked.'. 100 + "\n\n". 101 + 'If you have **Autoclose** enabled, Phabricator can close tasks and '. 102 + 'revisions when corresponding commits are pushed to the repository. '. 103 + 'If you want to autoclose objects only when commits appear on '. 104 + 'specific branches, you can list those branches in **Autoclose '. 105 + 'Only**. By default, all branches autoclose objects.')) 106 + ->appendChild( 107 + id(new AphrontFormTextControl()) 108 + ->setName('default') 109 + ->setLabel(pht('Default Branch')) 110 + ->setValue($v_default) 111 + ->setCaption( 112 + pht('Example: %s', phutil_tag('tt', array(), 'develop')))) 113 + ->appendChild( 114 + id(new AphrontFormTextControl()) 115 + ->setName('track') 116 + ->setLabel(pht('Track Only')) 117 + ->setValue($v_track) 118 + ->setCaption( 119 + pht('Example: %s', phutil_tag('tt', array(), 'master, develop')))) 120 + ->appendChild( 121 + id(new AphrontFormTextControl()) 122 + ->setName('autoclose') 123 + ->setLabel(pht('Autoclose Only')) 124 + ->setValue($v_autoclose) 125 + ->setCaption( 126 + pht('Example: %s', phutil_tag('tt', array(), 'master, release')))) 127 + ->appendChild( 128 + id(new AphrontFormSubmitControl()) 129 + ->setValue(pht('Save Branches')) 130 + ->addCancelButton($edit_uri)); 131 + 132 + $form_box = id(new PHUIObjectBoxView()) 133 + ->setHeaderText($title) 134 + ->setForm($form); 135 + 136 + return $this->buildApplicationPage( 137 + array( 138 + $crumbs, 139 + $form_box, 140 + ), 141 + array( 142 + 'title' => $title, 143 + 'device' => true, 144 + )); 145 + } 146 + 147 + }
+82
src/applications/diffusion/controller/DiffusionRepositoryEditController.php
··· 8 8 $drequest = $this->diffusionRequest; 9 9 $repository = $drequest->getRepository(); 10 10 11 + $is_svn = false; 12 + $is_git = false; 13 + $is_hg = false; 14 + switch ($repository->getVersionControlSystem()) { 15 + case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 16 + $is_git = true; 17 + break; 18 + case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 19 + $is_svn = true; 20 + break; 21 + case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: 22 + $is_hg = true; 23 + break; 24 + } 25 + 26 + $has_branches = ($is_git || $is_hg); 27 + 11 28 $crumbs = $this->buildCrumbs(); 12 29 $crumbs->addCrumb( 13 30 id(new PhabricatorCrumbView()) ··· 37 54 $encoding_properties = 38 55 $this->buildEncodingProperties($repository, $encoding_actions); 39 56 57 + $branches_properties = null; 58 + if ($has_branches) { 59 + $branches_properties = $this->buildBranchesProperties( 60 + $repository, 61 + $this->buildBranchesActions($repository)); 62 + } 63 + 40 64 $xactions = id(new PhabricatorRepositoryTransactionQuery()) 41 65 ->setViewer($user) 42 66 ->withObjectPHIDs(array($repository->getPHID())) ··· 64 88 ->addPropertyList($basic_properties) 65 89 ->addPropertyList($policy_properties) 66 90 ->addPropertyList($encoding_properties); 91 + 92 + if ($branches_properties) { 93 + $obj_box->addPropertyList($branches_properties); 94 + } 67 95 68 96 return $this->buildApplicationPage( 69 97 array( ··· 248 276 249 277 return $view; 250 278 } 279 + 280 + private function buildBranchesActions(PhabricatorRepository $repository) { 281 + $viewer = $this->getRequest()->getUser(); 282 + 283 + $view = id(new PhabricatorActionListView()) 284 + ->setObjectURI($this->getRequest()->getRequestURI()) 285 + ->setUser($viewer); 286 + 287 + $can_edit = PhabricatorPolicyFilter::hasCapability( 288 + $viewer, 289 + $repository, 290 + PhabricatorPolicyCapability::CAN_EDIT); 291 + 292 + $edit = id(new PhabricatorActionView()) 293 + ->setIcon('edit') 294 + ->setName(pht('Edit Branches')) 295 + ->setHref( 296 + $this->getRepositoryControllerURI($repository, 'edit/branches/')) 297 + ->setWorkflow(!$can_edit) 298 + ->setDisabled(!$can_edit); 299 + $view->addAction($edit); 300 + 301 + return $view; 302 + } 303 + 304 + private function buildBranchesProperties( 305 + PhabricatorRepository $repository, 306 + PhabricatorActionListView $actions) { 307 + 308 + $viewer = $this->getRequest()->getUser(); 309 + 310 + $view = id(new PHUIPropertyListView()) 311 + ->setUser($viewer) 312 + ->setActionList($actions) 313 + ->addSectionHeader(pht('Branches')); 314 + 315 + $default_branch = nonempty( 316 + $repository->getHumanReadableDetail('default-branch'), 317 + phutil_tag('em', array(), $repository->getDefaultBranch())); 318 + $view->addProperty(pht('Default Branch'), $default_branch); 319 + 320 + $track_only = nonempty( 321 + $repository->getHumanReadableDetail('branch-filter'), 322 + phutil_tag('em', array(), pht('Track All Branches'))); 323 + $view->addProperty(pht('Track Only'), $track_only); 324 + 325 + $autoclose_only = nonempty( 326 + $repository->getHumanReadableDetail('close-commits-filter'), 327 + phutil_tag('em', array(), pht('Autoclose On All Branches'))); 328 + $view->addProperty(pht('Autoclose Only'), $autoclose_only); 329 + 330 + return $view; 331 + } 332 + 251 333 252 334 }
+25
src/applications/repository/editor/PhabricatorRepositoryEditor.php
··· 10 10 $types[] = PhabricatorRepositoryTransaction::TYPE_NAME; 11 11 $types[] = PhabricatorRepositoryTransaction::TYPE_DESCRIPTION; 12 12 $types[] = PhabricatorRepositoryTransaction::TYPE_ENCODING; 13 + $types[] = PhabricatorRepositoryTransaction::TYPE_DEFAULT_BRANCH; 14 + $types[] = PhabricatorRepositoryTransaction::TYPE_TRACK_ONLY; 15 + $types[] = PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE_ONLY; 13 16 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 14 17 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 15 18 ··· 29 32 return $object->getDetail('description'); 30 33 case PhabricatorRepositoryTransaction::TYPE_ENCODING: 31 34 return $object->getDetail('encoding'); 35 + case PhabricatorRepositoryTransaction::TYPE_DEFAULT_BRANCH: 36 + return $object->getDetail('default-branch'); 37 + case PhabricatorRepositoryTransaction::TYPE_TRACK_ONLY: 38 + return array_keys($object->getDetail('branch-filter', array())); 39 + case PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE_ONLY: 40 + return array_keys($object->getDetail('close-commits-filter', array())); 32 41 } 33 42 } 34 43 ··· 41 50 case PhabricatorRepositoryTransaction::TYPE_NAME: 42 51 case PhabricatorRepositoryTransaction::TYPE_DESCRIPTION: 43 52 case PhabricatorRepositoryTransaction::TYPE_ENCODING: 53 + case PhabricatorRepositoryTransaction::TYPE_DEFAULT_BRANCH: 54 + case PhabricatorRepositoryTransaction::TYPE_TRACK_ONLY: 55 + case PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE_ONLY: 44 56 return $xaction->getNewValue(); 45 57 } 46 58 } ··· 58 70 break; 59 71 case PhabricatorRepositoryTransaction::TYPE_DESCRIPTION: 60 72 $object->setDetail('description', $xaction->getNewValue()); 73 + break; 74 + case PhabricatorRepositoryTransaction::TYPE_DEFAULT_BRANCH: 75 + $object->setDetail('default-branch', $xaction->getNewValue()); 76 + break; 77 + case PhabricatorRepositoryTransaction::TYPE_TRACK_ONLY: 78 + $object->setDetail( 79 + 'branch-filter', 80 + array_fill_keys($xaction->getNewValue(), true)); 81 + break; 82 + case PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE_ONLY: 83 + $object->setDetail( 84 + 'close-commits-filter', 85 + array_fill_keys($xaction->getNewValue(), true)); 61 86 break; 62 87 case PhabricatorRepositoryTransaction::TYPE_ENCODING: 63 88 // Make sure the encoding is valid by converting to UTF-8. This tests
+14
src/applications/repository/storage/PhabricatorRepository.php
··· 71 71 return idx($this->details, $key, $default); 72 72 } 73 73 74 + public function getHumanReadableDetail($key, $default = null) { 75 + $value = $this->getDetail($key, $default); 76 + 77 + switch ($key) { 78 + case 'branch-filter': 79 + case 'close-commits-filter': 80 + $value = array_keys($value); 81 + $value = implode(', ', $value); 82 + break; 83 + } 84 + 85 + return $value; 86 + } 87 + 74 88 public function setDetail($key, $value) { 75 89 $this->details[$key] = $value; 76 90 return $this;
+58
src/applications/repository/storage/PhabricatorRepositoryTransaction.php
··· 7 7 const TYPE_NAME = 'repo:name'; 8 8 const TYPE_DESCRIPTION = 'repo:description'; 9 9 const TYPE_ENCODING = 'repo:encoding'; 10 + const TYPE_DEFAULT_BRANCH = 'repo:default-branch'; 11 + const TYPE_TRACK_ONLY = 'repo:track-only'; 12 + const TYPE_AUTOCLOSE_ONLY = 'repo:autoclose-only'; 10 13 11 14 public function getApplicationName() { 12 15 return 'repository'; ··· 65 68 $old, 66 69 $new); 67 70 } 71 + case self::TYPE_DEFAULT_BRANCH: 72 + if (!strlen($new)) { 73 + return pht( 74 + '%s removed "%s" as the default branch.', 75 + $this->renderHandleLink($author_phid), 76 + $old); 77 + } else if (!strlen($old)) { 78 + return pht( 79 + '%s set the default branch to "%s".', 80 + $this->renderHandleLink($author_phid), 81 + $new); 82 + } else { 83 + return pht( 84 + '%s changed the default branch from "%s" to "%s".', 85 + $this->renderHandleLink($author_phid), 86 + $old, 87 + $new); 88 + } 89 + break; 90 + case self::TYPE_TRACK_ONLY: 91 + if (!$new) { 92 + return pht( 93 + '%s set this repository to track all branches.', 94 + $this->renderHandleLink($author_phid)); 95 + } else if (!$old) { 96 + return pht( 97 + '%s set this repository to track branches: %s.', 98 + $this->renderHandleLink($author_phid), 99 + implode(', ', $new)); 100 + } else { 101 + return pht( 102 + '%s changed track branches from "%s" to "%s".', 103 + $this->renderHandleLink($author_phid), 104 + implode(', ', $old), 105 + implode(', ', $new)); 106 + } 107 + break; 108 + case self::TYPE_AUTOCLOSE_ONLY: 109 + if (!$new) { 110 + return pht( 111 + '%s set this repository to autoclose on all branches.', 112 + $this->renderHandleLink($author_phid)); 113 + } else if (!$old) { 114 + return pht( 115 + '%s set this repository to autoclose on branches: %s.', 116 + $this->renderHandleLink($author_phid), 117 + implode(', ', $new)); 118 + } else { 119 + return pht( 120 + '%s changed autoclose branches from "%s" to "%s".', 121 + $this->renderHandleLink($author_phid), 122 + implode(', ', $old), 123 + implode(', ', $new)); 124 + } 125 + break; 68 126 } 69 127 70 128 return parent::getTitle();