[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DiffusionRepositoryEditBranchesController 4 extends DiffusionRepositoryEditController { 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 if (!$repository) { 22 return new Aphront404Response(); 23 } 24 25 $is_git = false; 26 $is_hg = false; 27 28 switch ($repository->getVersionControlSystem()) { 29 case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 30 $is_git = true; 31 break; 32 case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: 33 $is_hg = true; 34 break; 35 case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 36 throw new Exception( 37 pht('Subversion does not support branches!')); 38 default: 39 throw new Exception( 40 pht('Repository has unknown version control system!')); 41 } 42 43 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 44 45 $v_default = $repository->getHumanReadableDetail('default-branch'); 46 $v_track = $repository->getDetail( 47 'branch-filter', 48 array()); 49 $v_track = array_keys($v_track); 50 $v_autoclose = $repository->getDetail( 51 'close-commits-filter', 52 array()); 53 $v_autoclose = array_keys($v_autoclose); 54 55 $e_track = null; 56 $e_autoclose = null; 57 58 $validation_exception = null; 59 if ($request->isFormPost()) { 60 $v_default = $request->getStr('default'); 61 62 $v_track = $this->processBranches($request->getStr('track')); 63 if (!$is_hg) { 64 $v_autoclose = $this->processBranches($request->getStr('autoclose')); 65 } 66 67 $xactions = array(); 68 $template = id(new PhabricatorRepositoryTransaction()); 69 70 $type_default = PhabricatorRepositoryTransaction::TYPE_DEFAULT_BRANCH; 71 $type_track = PhabricatorRepositoryTransaction::TYPE_TRACK_ONLY; 72 $type_autoclose = PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE_ONLY; 73 74 $xactions[] = id(clone $template) 75 ->setTransactionType($type_default) 76 ->setNewValue($v_default); 77 78 $xactions[] = id(clone $template) 79 ->setTransactionType($type_track) 80 ->setNewValue($v_track); 81 82 if (!$is_hg) { 83 $xactions[] = id(clone $template) 84 ->setTransactionType($type_autoclose) 85 ->setNewValue($v_autoclose); 86 } 87 88 $editor = id(new PhabricatorRepositoryEditor()) 89 ->setContinueOnNoEffect(true) 90 ->setContentSourceFromRequest($request) 91 ->setActor($viewer); 92 93 try { 94 $editor->applyTransactions($repository, $xactions); 95 return id(new AphrontRedirectResponse())->setURI($edit_uri); 96 } catch (PhabricatorApplicationTransactionValidationException $ex) { 97 $validation_exception = $ex; 98 99 $e_track = $validation_exception->getShortMessage($type_track); 100 $e_autoclose = $validation_exception->getShortMessage($type_autoclose); 101 } 102 } 103 104 $content = array(); 105 106 $crumbs = $this->buildApplicationCrumbs(); 107 $crumbs->addTextCrumb(pht('Edit Branches')); 108 109 $title = pht('Edit Branches (%s)', $repository->getName()); 110 111 $policies = id(new PhabricatorPolicyQuery()) 112 ->setViewer($viewer) 113 ->setObject($repository) 114 ->execute(); 115 116 $rows = array(); 117 $rows[] = array( 118 array( 119 'master', 120 ), 121 pht('Select only master.'), 122 ); 123 $rows[] = array( 124 array( 125 'master', 126 'develop', 127 'release', 128 ), 129 pht('Select master, develop, and release.'), 130 ); 131 $rows[] = array( 132 array( 133 'master', 134 'regexp(/^release-/)', 135 ), 136 pht('Select master, and all branches which start with "release-".'), 137 ); 138 $rows[] = array( 139 array( 140 'regexp(/^(?!temp-)/)', 141 ), 142 pht('Select all branches which do not start with "temp-".'), 143 ); 144 145 foreach ($rows as $k => $row) { 146 $rows[$k][0] = phutil_tag( 147 'pre', 148 array(), 149 implode("\n", $row[0])); 150 } 151 152 $example_table = id(new AphrontTableView($rows)) 153 ->setHeaders( 154 array( 155 pht('Example'), 156 pht('Effect'), 157 )) 158 ->setColumnClasses( 159 array( 160 '', 161 'wide', 162 )); 163 164 $v_track = implode("\n", $v_track); 165 $v_autoclose = implode("\n", $v_autoclose); 166 167 $form = id(new AphrontFormView()) 168 ->setUser($viewer) 169 ->appendRemarkupInstructions( 170 pht( 171 'You can choose a **Default Branch** for viewing this repository.')) 172 ->appendChild( 173 id(new AphrontFormTextControl()) 174 ->setName('default') 175 ->setLabel(pht('Default Branch')) 176 ->setValue($v_default)) 177 ->appendRemarkupInstructions( 178 pht( 179 'If you want to import only some branches into Diffusion, you can '. 180 'list them in **Track Only**. Other branches will be ignored. If '. 181 'you do not specify any branches, all branches are tracked.')); 182 183 if (!$is_hg) { 184 $form->appendRemarkupInstructions( 185 pht( 186 'If you have **Autoclose** enabled for this repository, Phabricator '. 187 'can close tasks and revisions when corresponding commits are '. 188 'pushed to the repository. If you want to autoclose objects only '. 189 'when commits appear on specific branches, you can list those '. 190 'branches in **Autoclose Only**. By default, all tracked branches '. 191 'will autoclose objects.')); 192 } 193 194 $form 195 ->appendRemarkupInstructions( 196 pht( 197 'When specifying branches, you should enter one branch name per '. 198 'line. You can use regular expressions to match branches by '. 199 'wrapping an expression in `regexp(...)`. For example:')) 200 ->appendChild( 201 id(new AphrontFormMarkupControl()) 202 ->setValue($example_table)) 203 ->appendChild( 204 id(new AphrontFormTextAreaControl()) 205 ->setName('track') 206 ->setLabel(pht('Track Only')) 207 ->setError($e_track) 208 ->setValue($v_track)); 209 210 if (!$is_hg) { 211 $form->appendChild( 212 id(new AphrontFormTextAreaControl()) 213 ->setName('autoclose') 214 ->setLabel(pht('Autoclose Only')) 215 ->setError($e_autoclose) 216 ->setValue($v_autoclose)); 217 } 218 219 $form->appendChild( 220 id(new AphrontFormSubmitControl()) 221 ->setValue(pht('Save Branches')) 222 ->addCancelButton($edit_uri)); 223 224 $form_box = id(new PHUIObjectBoxView()) 225 ->setValidationException($validation_exception) 226 ->setHeaderText($title) 227 ->setForm($form); 228 229 return $this->buildApplicationPage( 230 array( 231 $crumbs, 232 $form_box, 233 ), 234 array( 235 'title' => $title, 236 )); 237 } 238 239 private function processBranches($string) { 240 $lines = phutil_split_lines($string, $retain_endings = false); 241 foreach ($lines as $key => $line) { 242 $lines[$key] = trim($line); 243 if (!strlen($lines[$key])) { 244 unset($lines[$key]); 245 } 246 } 247 248 return array_values($lines); 249 } 250 251 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |