1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

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
This commit is contained in:
epriestley 2013-03-05 12:31:52 -08:00
parent d585c2d745
commit 7d771b4ff7
5 changed files with 68 additions and 59 deletions

View file

@ -28,7 +28,7 @@ final class ConduitAPI_phid_lookup_Method
$names = $request->getValue('names');
$phids = array();
foreach ($names as $name) {
$phid = PhabricatorPHID::fromObjectName($name);
$phid = PhabricatorPHID::fromObjectName($name, $request->getUser());
if ($phid) {
$phids[$name] = $phid;
}

View file

@ -24,7 +24,7 @@ final class PhabricatorPHID {
return "PHID-{$type_str}-{$uniq}";
}
public static function fromObjectName($name) {
public static function fromObjectName($name, PhabricatorUser $viewer) {
$object = null;
$match = null;
if (preg_match('/^PHID-[A-Z]+-.{20}$/', $name)) {
@ -56,10 +56,18 @@ final class PhabricatorPHID {
$object = id(new DifferentialRevision())->load($match[1]);
} else if (preg_match('/^t(\d+)$/i', $name, $match)) {
$object = id(new ManiphestTask())->load($match[1]);
} else if (preg_match('/^m(\d+)$/i', $name, $match)) {
$objects = id(new PholioMockQuery())
->setViewer($viewer)
->withIDs(array($match[1]))
->execute();
$object = head($objects);
}
if ($object) {
return $object->getPHID();
}
return null;
}
}

View file

@ -221,7 +221,7 @@ final class PhabricatorSearchController
$results = $pager->sliceResults($results);
if (!$request->getInt('page')) {
$jump = PhabricatorPHID::fromObjectName($query->getQuery());
$jump = PhabricatorPHID::fromObjectName($query->getQuery(), $user);
if ($jump) {
array_unshift($results, $jump);
}

View file

@ -93,7 +93,9 @@ final class PhabricatorSearchManagementIndexWorkflow
private function loadPHIDsByNames(array $names) {
$phids = array();
foreach ($names as $name) {
$phid = PhabricatorPHID::fromObjectName($name);
$phid = PhabricatorPHID::fromObjectName(
$name,
PhabricatorUser::getOmnipotentUser());
if (!$phid) {
throw new PhutilArgumentUsageException(
"'{$name}' is not the name of a known object.");

View file

@ -20,38 +20,62 @@ final class PhabricatorBotObjectNameHandler extends PhabricatorBotHandler {
$message = $original_message->getBody();
$matches = null;
$pattern =
'@'.
'(?<!/)(?:^|\b)'. // Negative lookbehind prevent matching "/D123".
'(D|T|P|V|F)(\d+)'.
'(?:\b|$)'.
'@';
$revision_ids = array();
$task_ids = array();
$paste_ids = array();
$commit_names = array();
$vote_ids = array();
$file_ids = array();
$object_names = array();
$output = array();
$pattern =
'@'.
'(?<!/)(?:^|\b)'.
'(R2D2)'.
'(?:\b|$)'.
'@';
if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
switch ($match[1]) {
case 'D':
$revision_ids[] = $match[2];
break;
case 'T':
$task_ids[] = $match[2];
break;
case 'P':
$paste_ids[] = $match[2];
break;
case 'V':
$vote_ids[] = $match[2];
break;
case 'F':
$file_ids[] = $match[2];
break;
case 'R2D2':
$output[$match[1]] = pht('beep hoop bop');
break;
}
}
}
$pattern =
'@'.
'(?<!/)(?:^|\b)'. // Negative lookbehind prevent matching "/D123".
'([A-Z])(\d+)'.
'(?:\b|$)'.
'@';
if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
switch ($match[1]) {
case 'P':
$paste_ids[] = $match[2];
break;
case 'V':
$vote_ids[] = $match[2];
break;
case 'F':
$file_ids[] = $match[2];
break;
default:
$name = $match[1].$match[2];
switch ($name) {
case 'T1000':
$output[$name] = pht(
'T1000: A mimetic poly-alloy assassin controlled by '.
'Skynet');
break;
default:
$object_names[] = $name;
break;
}
break;
}
}
}
@ -68,39 +92,14 @@ final class PhabricatorBotObjectNameHandler extends PhabricatorBotHandler {
}
}
$output = array();
if ($revision_ids) {
$revisions = $this->getConduit()->callMethodSynchronous(
'differential.query',
if ($object_names) {
$objects = $this->getConduit()->callMethodSynchronous(
'phid.lookup',
array(
'ids' => $revision_ids,
'names' => $object_names,
));
$revisions = array_select_keys(
ipull($revisions, null, 'id'),
$revision_ids);
foreach ($revisions as $revision) {
$output[$revision['phid']] =
'D'.$revision['id'].' '.$revision['title'].' - '.
$revision['uri'];
}
}
if ($task_ids) {
foreach ($task_ids as $task_id) {
if ($task_id == 1000) {
$output[1000] = 'T1000: A nanomorph mimetic poly-alloy'
.'(liquid metal) assassin controlled by Skynet: '
.'http://en.wikipedia.org/wiki/T-1000';
continue;
}
$task = $this->getConduit()->callMethodSynchronous(
'maniphest.info',
array(
'task_id' => $task_id,
));
$output[$task['phid']] = 'T'.$task['id'].': '.$task['title'].
' (Priority: '.$task['priority'].') - '.$task['uri'];
foreach ($objects as $object) {
$output[$object['phid']] = $object['fullName'].' - '.$object['uri'];
}
}