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

Allow Conduit API methods in Diffusion to accept any repository identifier

Summary:
Ref T4245. Broaden support to include "ABCD", "rABCD", "1234", "R1234", etc.

This doesn't change the old behavior, just accepts more stuff.

Test Plan:
- Browsed Diffusion.
- Made various calls via API console.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4245

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

+68 -46
+9 -3
src/applications/diffusion/conduit/DiffusionQueryConduitAPIMethod.php
··· 38 38 return $this->defineCustomErrorTypes() + 39 39 array( 40 40 'ERR-UNKNOWN-REPOSITORY' => 41 - pht('There is no repository with that callsign.'), 41 + pht('There is no matching repository.'), 42 42 'ERR-UNKNOWN-VCS-TYPE' => 43 43 pht('Unknown repository VCS type.'), 44 44 'ERR-UNSUPPORTED-VCS' => ··· 56 56 final protected function defineParamTypes() { 57 57 return $this->defineCustomParamTypes() + 58 58 array( 59 - 'callsign' => 'required string', 59 + 'callsign' => 'optional string (deprecated)', 60 + 'repository' => 'optional string', 60 61 'branch' => 'optional string', 61 62 ); 62 63 } ··· 95 96 * should occur after @{method:getResult}, like formatting a timestamp. 96 97 */ 97 98 final protected function execute(ConduitAPIRequest $request) { 99 + $identifier = $request->getValue('repository'); 100 + if ($identifier === null) { 101 + $identifier = $request->getValue('callsign'); 102 + } 103 + 98 104 $drequest = DiffusionRequest::newFromDictionary( 99 105 array( 100 106 'user' => $request->getUser(), 101 - 'callsign' => $request->getValue('callsign'), 107 + 'repository' => $identifier, 102 108 'branch' => $request->getValue('branch'), 103 109 'path' => $request->getValue('path'), 104 110 'commit' => $request->getValue('commit'),
+59 -43
src/applications/diffusion/request/DiffusionRequest.php
··· 9 9 */ 10 10 abstract class DiffusionRequest extends Phobject { 11 11 12 - protected $callsign; 13 12 protected $path; 14 13 protected $line; 15 14 protected $branch; ··· 47 46 * 48 47 * Parameters are: 49 48 * 50 - * - `callsign` Repository callsign. Provide this or `repository`. 51 - * - `user` Viewing user. Required if `callsign` is provided. 52 - * - `repository` Repository object. Provide this or `callsign`. 49 + * - `repository` Repository object or identifier. 50 + * - `user` Viewing user. Required if `repository` is an identifier. 53 51 * - `branch` Optional, branch name. 54 52 * - `path` Optional, file path. 55 53 * - `commit` Optional, commit identifier. ··· 60 58 * @task new 61 59 */ 62 60 final public static function newFromDictionary(array $data) { 63 - if (isset($data['repository']) && isset($data['callsign'])) { 64 - throw new Exception( 65 - pht( 66 - "Specify '%s' or '%s', but not both.", 67 - 'repository', 68 - 'callsign')); 69 - } else if (!isset($data['repository']) && !isset($data['callsign'])) { 61 + $repository_key = 'repository'; 62 + $identifier_key = 'callsign'; 63 + $viewer_key = 'user'; 64 + 65 + $repository = idx($data, $repository_key); 66 + $identifier = idx($data, $identifier_key); 67 + 68 + $have_repository = ($repository !== null); 69 + $have_identifier = ($identifier !== null); 70 + 71 + if ($have_repository && $have_identifier) { 70 72 throw new Exception( 71 73 pht( 72 - "One of '%s' and '%s' is required.", 73 - 'repository', 74 - 'callsign')); 75 - } else if (isset($data['callsign']) && empty($data['user'])) { 74 + 'Specify "%s" or "%s", but not both.', 75 + $repository_key, 76 + $identifier_key)); 77 + } 78 + 79 + if (!$have_repository && !$have_identifier) { 76 80 throw new Exception( 77 81 pht( 78 - "Parameter '%s' is required if '%s' is provided.", 79 - 'user', 80 - 'callsign')); 82 + 'One of "%s" and "%s" is required.', 83 + $repository_key, 84 + $identifier_key)); 81 85 } 82 86 83 - if (isset($data['repository'])) { 84 - $object = self::newFromRepository($data['repository']); 87 + if ($have_repository) { 88 + if (!($repository instanceof PhabricatorRepository)) { 89 + if (empty($data[$viewer_key])) { 90 + throw new Exception( 91 + pht( 92 + 'Parameter "%s" is required if "%s" is provided.', 93 + $viewer_key, 94 + $identifier_key)); 95 + } 96 + 97 + $identifier = $repository; 98 + $repository = null; 99 + } 100 + } 101 + 102 + if ($identifier !== null) { 103 + $object = self::newFromIdentifier($identifier, $data[$viewer_key]); 85 104 } else { 86 - $object = self::newFromCallsign($data['callsign'], $data['user']); 105 + $object = self::newFromRepository($repository); 87 106 } 88 107 89 108 $object->initializeFromDictionary($data); ··· 105 124 array $data, 106 125 AphrontRequest $request) { 107 126 108 - $callsign = phutil_unescape_uri_path_component(idx($data, 'callsign')); 109 - $object = self::newFromCallsign($callsign, $request->getUser()); 127 + $identifier = phutil_unescape_uri_path_component(idx($data, 'callsign')); 128 + $object = self::newFromIdentifier($identifier, $request->getUser()); 110 129 111 130 $use_branches = $object->supportsBranches(); 112 131 ··· 141 160 /** 142 161 * Internal. Use @{method:newFromDictionary}, not this method. 143 162 * 144 - * @param string Repository callsign. 163 + * @param string Repository identifier. 145 164 * @param PhabricatorUser Viewing user. 146 165 * @return DiffusionRequest New request object. 147 166 * @task new 148 167 */ 149 - final private static function newFromCallsign( 150 - $callsign, 168 + final private static function newFromIdentifier( 169 + $identifier, 151 170 PhabricatorUser $viewer) { 152 171 153 172 $repository = id(new PhabricatorRepositoryQuery()) 154 173 ->setViewer($viewer) 155 - ->withCallsigns(array($callsign)) 174 + ->withIdentifiers(array($identifier)) 156 175 ->executeOne(); 157 176 158 177 if (!$repository) { 159 - throw new Exception(pht("No such repository '%s'.", $callsign)); 178 + throw new Exception(pht("No such repository '%s'.", $identifier)); 160 179 } 161 180 162 181 return self::newFromRepository($repository); ··· 189 208 $object = new $class(); 190 209 191 210 $object->repository = $repository; 192 - $object->callsign = $repository->getCallsign(); 193 211 194 212 return $object; 195 213 } ··· 239 257 } 240 258 241 259 public function getCallsign() { 242 - return $this->callsign; 260 + return $this->getRepository()->getCallsign(); 243 261 } 244 262 245 263 public function setPath($path) { ··· 702 720 703 721 protected function raisePermissionException() { 704 722 $host = php_uname('n'); 705 - $callsign = $this->getRepository()->getCallsign(); 706 723 throw new DiffusionSetupException( 707 724 pht( 708 - "The clone of this repository ('%s') on the local machine ('%s') ". 709 - "could not be read. Ensure that the repository is in a ". 710 - "location where the web server has read permissions.", 711 - $callsign, 725 + 'The clone of this repository ("%s") on the local machine ("%s") '. 726 + 'could not be read. Ensure that the repository is in a '. 727 + 'location where the web server has read permissions.', 728 + $this->getRepository()->getDisplayName(), 712 729 $host)); 713 730 } 714 731 715 732 protected function raiseCloneException() { 716 733 $host = php_uname('n'); 717 - $callsign = $this->getRepository()->getCallsign(); 718 734 throw new DiffusionSetupException( 719 735 pht( 720 - "The working copy for this repository ('%s') hasn't been cloned yet ". 721 - "on this machine ('%s'). Make sure you've started the Phabricator ". 722 - "daemons. If this problem persists for longer than a clone should ". 723 - "take, check the daemon logs (in the Daemon Console) to see if there ". 724 - "were errors cloning the repository. Consult the 'Diffusion User ". 725 - "Guide' in the documentation for help setting up repositories.", 726 - $callsign, 736 + 'The working copy for this repository ("%s") has not been cloned yet '. 737 + 'on this machine ("%s"). Make sure you havestarted the Phabricator '. 738 + 'daemons. If this problem persists for longer than a clone should '. 739 + 'take, check the daemon logs (in the Daemon Console) to see if there '. 740 + 'were errors cloning the repository. Consult the "Diffusion User '. 741 + 'Guide" in the documentation for help setting up repositories.', 742 + $this->getRepository()->getDisplayName(), 727 743 $host)); 728 744 } 729 745