Skip to content

Commit 7d771b4

Browse files
author
epriestley
committed
Support "M" in phid.lookup and ircbot
Summary: Fixes T2651. This could be futher generalized but it's a bit out of the way. Test Plan: See chatlog. Reviewers: chad Reviewed By: chad CC: aran Maniphest Tasks: T2651 Differential Revision: https://secure.phabricator.com/D5236
1 parent d585c2d commit 7d771b4

File tree

5 files changed

+67
-58
lines changed

5 files changed

+67
-58
lines changed

src/applications/phid/conduit/ConduitAPI_phid_lookup_Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function execute(ConduitAPIRequest $request) {
2828
$names = $request->getValue('names');
2929
$phids = array();
3030
foreach ($names as $name) {
31-
$phid = PhabricatorPHID::fromObjectName($name);
31+
$phid = PhabricatorPHID::fromObjectName($name, $request->getUser());
3232
if ($phid) {
3333
$phids[$name] = $phid;
3434
}

src/applications/phid/storage/PhabricatorPHID.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function generateNewPHID($type, $subtype = null) {
2424
return "PHID-{$type_str}-{$uniq}";
2525
}
2626

27-
public static function fromObjectName($name) {
27+
public static function fromObjectName($name, PhabricatorUser $viewer) {
2828
$object = null;
2929
$match = null;
3030
if (preg_match('/^PHID-[A-Z]+-.{20}$/', $name)) {
@@ -56,10 +56,18 @@ public static function fromObjectName($name) {
5656
$object = id(new DifferentialRevision())->load($match[1]);
5757
} else if (preg_match('/^t(\d+)$/i', $name, $match)) {
5858
$object = id(new ManiphestTask())->load($match[1]);
59+
} else if (preg_match('/^m(\d+)$/i', $name, $match)) {
60+
$objects = id(new PholioMockQuery())
61+
->setViewer($viewer)
62+
->withIDs(array($match[1]))
63+
->execute();
64+
$object = head($objects);
5965
}
66+
6067
if ($object) {
6168
return $object->getPHID();
6269
}
70+
6371
return null;
6472
}
6573
}

src/applications/search/controller/PhabricatorSearchController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function processRequest() {
221221
$results = $pager->sliceResults($results);
222222

223223
if (!$request->getInt('page')) {
224-
$jump = PhabricatorPHID::fromObjectName($query->getQuery());
224+
$jump = PhabricatorPHID::fromObjectName($query->getQuery(), $user);
225225
if ($jump) {
226226
array_unshift($results, $jump);
227227
}

src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public function execute(PhutilArgumentParser $args) {
9393
private function loadPHIDsByNames(array $names) {
9494
$phids = array();
9595
foreach ($names as $name) {
96-
$phid = PhabricatorPHID::fromObjectName($name);
96+
$phid = PhabricatorPHID::fromObjectName(
97+
$name,
98+
PhabricatorUser::getOmnipotentUser());
9799
if (!$phid) {
98100
throw new PhutilArgumentUsageException(
99101
"'{$name}' is not the name of a known object.");

src/infrastructure/daemon/bot/handler/PhabricatorBotObjectNameHandler.php

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,62 @@ public function receiveMessage(PhabricatorBotMessage $original_message) {
2020
$message = $original_message->getBody();
2121
$matches = null;
2222

23+
$paste_ids = array();
24+
$commit_names = array();
25+
$vote_ids = array();
26+
$file_ids = array();
27+
$object_names = array();
28+
$output = array();
29+
2330
$pattern =
2431
'@'.
25-
'(?<!/)(?:^|\b)'. // Negative lookbehind prevent matching "/D123".
26-
'(D|T|P|V|F)(\d+)'.
32+
'(?<!/)(?:^|\b)'.
33+
'(R2D2)'.
2734
'(?:\b|$)'.
2835
'@';
2936

30-
$revision_ids = array();
31-
$task_ids = array();
32-
$paste_ids = array();
33-
$commit_names = array();
34-
$vote_ids = array();
35-
$file_ids = array();
37+
if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
38+
foreach ($matches as $match) {
39+
switch ($match[1]) {
40+
case 'R2D2':
41+
$output[$match[1]] = pht('beep hoop bop');
42+
break;
43+
}
44+
}
45+
}
46+
47+
$pattern =
48+
'@'.
49+
'(?<!/)(?:^|\b)'. // Negative lookbehind prevent matching "/D123".
50+
'([A-Z])(\d+)'.
51+
'(?:\b|$)'.
52+
'@';
3653

3754
if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
3855
foreach ($matches as $match) {
3956
switch ($match[1]) {
40-
case 'D':
41-
$revision_ids[] = $match[2];
42-
break;
43-
case 'T':
44-
$task_ids[] = $match[2];
45-
break;
46-
case 'P':
47-
$paste_ids[] = $match[2];
48-
break;
49-
case 'V':
50-
$vote_ids[] = $match[2];
51-
break;
52-
case 'F':
53-
$file_ids[] = $match[2];
54-
break;
57+
case 'P':
58+
$paste_ids[] = $match[2];
59+
break;
60+
case 'V':
61+
$vote_ids[] = $match[2];
62+
break;
63+
case 'F':
64+
$file_ids[] = $match[2];
65+
break;
66+
default:
67+
$name = $match[1].$match[2];
68+
switch ($name) {
69+
case 'T1000':
70+
$output[$name] = pht(
71+
'T1000: A mimetic poly-alloy assassin controlled by '.
72+
'Skynet');
73+
break;
74+
default:
75+
$object_names[] = $name;
76+
break;
77+
}
78+
break;
5579
}
5680
}
5781
}
@@ -68,39 +92,14 @@ public function receiveMessage(PhabricatorBotMessage $original_message) {
6892
}
6993
}
7094

71-
$output = array();
72-
73-
if ($revision_ids) {
74-
$revisions = $this->getConduit()->callMethodSynchronous(
75-
'differential.query',
95+
if ($object_names) {
96+
$objects = $this->getConduit()->callMethodSynchronous(
97+
'phid.lookup',
7698
array(
77-
'ids' => $revision_ids,
99+
'names' => $object_names,
78100
));
79-
$revisions = array_select_keys(
80-
ipull($revisions, null, 'id'),
81-
$revision_ids);
82-
foreach ($revisions as $revision) {
83-
$output[$revision['phid']] =
84-
'D'.$revision['id'].' '.$revision['title'].' - '.
85-
$revision['uri'];
86-
}
87-
}
88-
89-
if ($task_ids) {
90-
foreach ($task_ids as $task_id) {
91-
if ($task_id == 1000) {
92-
$output[1000] = 'T1000: A nanomorph mimetic poly-alloy'
93-
.'(liquid metal) assassin controlled by Skynet: '
94-
.'http://en.wikipedia.org/wiki/T-1000';
95-
continue;
96-
}
97-
$task = $this->getConduit()->callMethodSynchronous(
98-
'maniphest.info',
99-
array(
100-
'task_id' => $task_id,
101-
));
102-
$output[$task['phid']] = 'T'.$task['id'].': '.$task['title'].
103-
' (Priority: '.$task['priority'].') - '.$task['uri'];
101+
foreach ($objects as $object) {
102+
$output[$object['phid']] = $object['fullName'].' - '.$object['uri'];
104103
}
105104
}
106105

0 commit comments

Comments
 (0)