Page MenuHomePhabricator

D8836.id21805.diff
No OneTemporary

D8836.id21805.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -623,6 +623,7 @@
'DoorkeeperBridge' => 'applications/doorkeeper/bridge/DoorkeeperBridge.php',
'DoorkeeperBridgeAsana' => 'applications/doorkeeper/bridge/DoorkeeperBridgeAsana.php',
'DoorkeeperBridgeJIRA' => 'applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php',
+ 'DoorkeeperBridgeJIRATestCase' => 'applications/doorkeeper/bridge/__tests__/DoorkeeperBridgeJIRATestCase.php',
'DoorkeeperDAO' => 'applications/doorkeeper/storage/DoorkeeperDAO.php',
'DoorkeeperExternalObject' => 'applications/doorkeeper/storage/DoorkeeperExternalObject.php',
'DoorkeeperExternalObjectQuery' => 'applications/doorkeeper/query/DoorkeeperExternalObjectQuery.php',
@@ -3276,6 +3277,7 @@
'DoorkeeperBridge' => 'Phobject',
'DoorkeeperBridgeAsana' => 'DoorkeeperBridge',
'DoorkeeperBridgeJIRA' => 'DoorkeeperBridge',
+ 'DoorkeeperBridgeJIRATestCase' => 'PhabricatorTestCase',
'DoorkeeperDAO' => 'PhabricatorLiskDAO',
'DoorkeeperExternalObject' =>
array(
diff --git a/src/applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php b/src/applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php
--- a/src/applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php
+++ b/src/applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php
@@ -110,10 +110,34 @@
// Convert the "self" URI, which points at the REST endpoint, into a
// browse URI.
$self = idx($result, 'self');
- $uri = new PhutilURI($self);
- $uri->setPath('browse/'.$obj->getObjectID());
+ $object_id = $obj->getObjectID();
- $obj->setObjectURI((string)$uri);
+ $uri = self::getJIRAIssueBrowseURIFromJIRARestURI($self, $object_id);
+ if ($uri !== null) {
+ $obj->setObjectURI($uri);
+ }
+ }
+
+ public static function getJIRAIssueBrowseURIFromJIRARestURI(
+ $uri,
+ $object_id) {
+
+ $uri = new PhutilURI($uri);
+
+ // The JIRA install might not be at the domain root, so we may need to
+ // keep an initial part of the path, like "/jira/". Find the API specific
+ // part of the URI, strip it off, then replace it with the web version.
+ $path = $uri->getPath();
+ $pos = strrpos($path, 'rest/api/2/issue/');
+ if ($pos === false) {
+ return null;
+ }
+
+ $path = substr($path, 0, $pos);
+ $path = $path.'browse/'.$object_id;
+ $uri->setPath($path);
+
+ return (string)$uri;
}
}
diff --git a/src/applications/doorkeeper/bridge/__tests__/DoorkeeperBridgeJIRATestCase.php b/src/applications/doorkeeper/bridge/__tests__/DoorkeeperBridgeJIRATestCase.php
new file mode 100644
--- /dev/null
+++ b/src/applications/doorkeeper/bridge/__tests__/DoorkeeperBridgeJIRATestCase.php
@@ -0,0 +1,37 @@
+<?php
+
+final class DoorkeeperBridgeJIRATestCase extends PhabricatorTestCase {
+
+ public function testJIRABridgeRestAPIURIConversion() {
+ $map = array(
+ array(
+ // Installed at domain root.
+ 'http://jira.example.com/rest/api/2/issue/1',
+ 'TP-1',
+ 'http://jira.example.com/browse/TP-1'
+ ),
+ array(
+ // Installed on path.
+ 'http://jira.example.com/jira/rest/api/2/issue/1',
+ 'TP-1',
+ 'http://jira.example.com/jira/browse/TP-1'
+ ),
+ array(
+ // A URI we don't understand.
+ 'http://jira.example.com/wake/cli/3/task/1',
+ 'TP-1',
+ null,
+ ),
+ );
+
+ foreach ($map as $inputs) {
+ list($rest_uri, $object_id, $expect) = $inputs;
+ $this->assertEqual(
+ $expect,
+ DoorkeeperBridgeJIRA::getJIRAIssueBrowseURIFromJIRARestURI(
+ $rest_uri,
+ $object_id));
+ }
+ }
+
+}
diff --git a/src/applications/doorkeeper/remarkup/DoorkeeperRemarkupRuleJIRA.php b/src/applications/doorkeeper/remarkup/DoorkeeperRemarkupRuleJIRA.php
--- a/src/applications/doorkeeper/remarkup/DoorkeeperRemarkupRuleJIRA.php
+++ b/src/applications/doorkeeper/remarkup/DoorkeeperRemarkupRuleJIRA.php
@@ -5,13 +5,12 @@
public function apply($text) {
return preg_replace_callback(
- '@(https?://[^/]+)/browse/([A-Z]+-[1-9]\d*)@',
+ '@(https?://\S+?)/browse/([A-Z]+-[1-9]\d*)@',
array($this, 'markupJIRALink'),
$text);
}
public function markupJIRALink($matches) {
-
$match_domain = $matches[1];
$match_issue = $matches[2];
@@ -21,6 +20,7 @@
return $matches[0];
}
+
$jira_base = $provider->getJIRABaseURI();
if ($match_domain != rtrim($jira_base, '/')) {
return $matches[0];

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 20, 5:10 PM (6 h, 24 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6719904
Default Alt Text
D8836.id21805.diff (4 KB)

Event Timeline