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

Fix JIRA issue URI selection for JIRA installs which are not on the domain root

Summary: Fixes T4859. See that for details.

Test Plan:
- Verified things still work on my local (domain root) install.
- Added some unit tests.
- Did not verify a non-root install since I don't have one handy, hopefully @salehe can help.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: salehe, epriestley

Maniphest Tasks: T4859

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

+68 -5
+2
src/__phutil_library_map__.php
··· 623 623 'DoorkeeperBridge' => 'applications/doorkeeper/bridge/DoorkeeperBridge.php', 624 624 'DoorkeeperBridgeAsana' => 'applications/doorkeeper/bridge/DoorkeeperBridgeAsana.php', 625 625 'DoorkeeperBridgeJIRA' => 'applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php', 626 + 'DoorkeeperBridgeJIRATestCase' => 'applications/doorkeeper/bridge/__tests__/DoorkeeperBridgeJIRATestCase.php', 626 627 'DoorkeeperDAO' => 'applications/doorkeeper/storage/DoorkeeperDAO.php', 627 628 'DoorkeeperExternalObject' => 'applications/doorkeeper/storage/DoorkeeperExternalObject.php', 628 629 'DoorkeeperExternalObjectQuery' => 'applications/doorkeeper/query/DoorkeeperExternalObjectQuery.php', ··· 3276 3277 'DoorkeeperBridge' => 'Phobject', 3277 3278 'DoorkeeperBridgeAsana' => 'DoorkeeperBridge', 3278 3279 'DoorkeeperBridgeJIRA' => 'DoorkeeperBridge', 3280 + 'DoorkeeperBridgeJIRATestCase' => 'PhabricatorTestCase', 3279 3281 'DoorkeeperDAO' => 'PhabricatorLiskDAO', 3280 3282 'DoorkeeperExternalObject' => 3281 3283 array(
+27 -3
src/applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php
··· 110 110 // Convert the "self" URI, which points at the REST endpoint, into a 111 111 // browse URI. 112 112 $self = idx($result, 'self'); 113 - $uri = new PhutilURI($self); 114 - $uri->setPath('browse/'.$obj->getObjectID()); 113 + $object_id = $obj->getObjectID(); 114 + 115 + $uri = self::getJIRAIssueBrowseURIFromJIRARestURI($self, $object_id); 116 + if ($uri !== null) { 117 + $obj->setObjectURI($uri); 118 + } 119 + } 120 + 121 + public static function getJIRAIssueBrowseURIFromJIRARestURI( 122 + $uri, 123 + $object_id) { 115 124 116 - $obj->setObjectURI((string)$uri); 125 + $uri = new PhutilURI($uri); 126 + 127 + // The JIRA install might not be at the domain root, so we may need to 128 + // keep an initial part of the path, like "/jira/". Find the API specific 129 + // part of the URI, strip it off, then replace it with the web version. 130 + $path = $uri->getPath(); 131 + $pos = strrpos($path, 'rest/api/2/issue/'); 132 + if ($pos === false) { 133 + return null; 134 + } 135 + 136 + $path = substr($path, 0, $pos); 137 + $path = $path.'browse/'.$object_id; 138 + $uri->setPath($path); 139 + 140 + return (string)$uri; 117 141 } 118 142 119 143 }
+37
src/applications/doorkeeper/bridge/__tests__/DoorkeeperBridgeJIRATestCase.php
··· 1 + <?php 2 + 3 + final class DoorkeeperBridgeJIRATestCase extends PhabricatorTestCase { 4 + 5 + public function testJIRABridgeRestAPIURIConversion() { 6 + $map = array( 7 + array( 8 + // Installed at domain root. 9 + 'http://jira.example.com/rest/api/2/issue/1', 10 + 'TP-1', 11 + 'http://jira.example.com/browse/TP-1' 12 + ), 13 + array( 14 + // Installed on path. 15 + 'http://jira.example.com/jira/rest/api/2/issue/1', 16 + 'TP-1', 17 + 'http://jira.example.com/jira/browse/TP-1' 18 + ), 19 + array( 20 + // A URI we don't understand. 21 + 'http://jira.example.com/wake/cli/3/task/1', 22 + 'TP-1', 23 + null, 24 + ), 25 + ); 26 + 27 + foreach ($map as $inputs) { 28 + list($rest_uri, $object_id, $expect) = $inputs; 29 + $this->assertEqual( 30 + $expect, 31 + DoorkeeperBridgeJIRA::getJIRAIssueBrowseURIFromJIRARestURI( 32 + $rest_uri, 33 + $object_id)); 34 + } 35 + } 36 + 37 + }
+2 -2
src/applications/doorkeeper/remarkup/DoorkeeperRemarkupRuleJIRA.php
··· 5 5 6 6 public function apply($text) { 7 7 return preg_replace_callback( 8 - '@(https?://[^/]+)/browse/([A-Z]+-[1-9]\d*)@', 8 + '@(https?://\S+?)/browse/([A-Z]+-[1-9]\d*)@', 9 9 array($this, 'markupJIRALink'), 10 10 $text); 11 11 } 12 12 13 13 public function markupJIRALink($matches) { 14 - 15 14 $match_domain = $matches[1]; 16 15 $match_issue = $matches[2]; 17 16 ··· 20 19 if (!$provider) { 21 20 return $matches[0]; 22 21 } 22 + 23 23 24 24 $jira_base = $provider->getJIRABaseURI(); 25 25 if ($match_domain != rtrim($jira_base, '/')) {