Minor IRCBot fixes/upgrades
Summary: Keep him from getting killed every 24 hours by the overseer, add basic commit support. Test Plan: Ran irc bot, fed him a commit, fed him "http://blah/D1". Reviewed By: aran Reviewers: aran, jungejason, tuomaspelkonen, codeblock, mroch CC: aran, epriestley Differential Revision: 377
This commit is contained in:
@@ -40,3 +40,5 @@ phutil_load_library('arcanist/src');
|
|||||||
foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) {
|
foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) {
|
||||||
phutil_load_library($library);
|
phutil_load_library($library);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PhutilErrorHandler::initialize();
|
||||||
|
|||||||
@@ -66,10 +66,12 @@ class ConduitAPI_differential_find_Method extends ConduitAPIMethod {
|
|||||||
if (!$diff) {
|
if (!$diff) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$id = $revision->getID();
|
||||||
$results[] = array(
|
$results[] = array(
|
||||||
'id' => $revision->getID(),
|
'id' => $id,
|
||||||
'phid' => $revision->getPHID(),
|
'phid' => $revision->getPHID(),
|
||||||
'name' => $revision->getTitle(),
|
'name' => $revision->getTitle(),
|
||||||
|
'uri' => PhabricatorEnv::getProductionURI('/D'.$id),
|
||||||
'dateCreated' => $revision->getDateCreated(),
|
'dateCreated' => $revision->getDateCreated(),
|
||||||
'authorPHID' => $revision->getAuthorPHID(),
|
'authorPHID' => $revision->getAuthorPHID(),
|
||||||
'statusName' => DifferentialRevisionStatus::getNameForRevisionStatus(
|
'statusName' => DifferentialRevisionStatus::getNameForRevisionStatus(
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
phutil_require_module('phabricator', 'applications/conduit/method/base');
|
phutil_require_module('phabricator', 'applications/conduit/method/base');
|
||||||
phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus');
|
phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus');
|
||||||
phutil_require_module('phabricator', 'applications/differential/data/revisionlist');
|
phutil_require_module('phabricator', 'applications/differential/data/revisionlist');
|
||||||
|
phutil_require_module('phabricator', 'infrastructure/env');
|
||||||
|
|
||||||
phutil_require_module('phutil', 'utils');
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,12 @@ class ConduitAPI_diffusion_getcommits_Method extends ConduitAPIMethod {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Upgrade git short references into full commit identifiers.
|
// Upgrade git short references into full commit identifiers.
|
||||||
$commits[$name]['commitIdentifier'] = $cobj->getCommitIdentifier();
|
$identifier = $cobj->getCommitIdentifier();
|
||||||
|
$commits[$name]['commitIdentifier'] = $identifier;
|
||||||
|
|
||||||
|
$callsign = $commits[$name]['callsign'];
|
||||||
|
$uri = "/r{$callsign}{$identifier}";
|
||||||
|
$commits[$name]['uri'] = PhabricatorEnv::getProductionURI($uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$commits) {
|
if (!$commits) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'applications/repository/constants/reposito
|
|||||||
phutil_require_module('phabricator', 'applications/repository/storage/commit');
|
phutil_require_module('phabricator', 'applications/repository/storage/commit');
|
||||||
phutil_require_module('phabricator', 'applications/repository/storage/commitdata');
|
phutil_require_module('phabricator', 'applications/repository/storage/commitdata');
|
||||||
phutil_require_module('phabricator', 'applications/repository/storage/repository');
|
phutil_require_module('phabricator', 'applications/repository/storage/repository');
|
||||||
|
phutil_require_module('phabricator', 'infrastructure/env');
|
||||||
phutil_require_module('phabricator', 'storage/qsprintf');
|
phutil_require_module('phabricator', 'storage/qsprintf');
|
||||||
phutil_require_module('phabricator', 'storage/queryfx');
|
phutil_require_module('phabricator', 'storage/queryfx');
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ final class PhabricatorIRCBot extends PhabricatorDaemon {
|
|||||||
|
|
||||||
private function runSelectLoop() {
|
private function runSelectLoop() {
|
||||||
do {
|
do {
|
||||||
|
$this->stillWorking();
|
||||||
|
|
||||||
$read = array($this->socket);
|
$read = array($this->socket);
|
||||||
if (strlen($this->writeBuffer)) {
|
if (strlen($this->writeBuffer)) {
|
||||||
$write = array($this->socket);
|
$write = array($this->socket);
|
||||||
|
|||||||
@@ -35,24 +35,76 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler {
|
|||||||
$message = $message->getMessageText();
|
$message = $message->getMessageText();
|
||||||
$matches = null;
|
$matches = null;
|
||||||
$phids = array();
|
$phids = array();
|
||||||
if (preg_match_all('/(?:^|\b)D(\d+)(?:\b|$)/', $message, $matches)) {
|
|
||||||
if ($matches[1]) {
|
|
||||||
$revisions = $this->getConduit()->callMethodSynchronous(
|
|
||||||
'differential.find',
|
|
||||||
array(
|
|
||||||
'query' => 'revision-ids',
|
|
||||||
'guids' => $matches[1],
|
|
||||||
));
|
|
||||||
|
|
||||||
// TODO: This is utter hacks until phid.find or similar lands.
|
$pattern =
|
||||||
foreach ($revisions as $revision) {
|
'@'.
|
||||||
$phids[$revision['phid']] =
|
'(?<!/)(?:^|\b)'. // Negative lookbehind prevent matching "/D123".
|
||||||
'D'.$revision['id'].' '.$revision['name'].' - '.
|
'(D|T)(\d+)'.
|
||||||
PhabricatorEnv::getProductionURI('/D'.$revision['id']);
|
'(?:\b|$)'.
|
||||||
|
'@';
|
||||||
|
|
||||||
|
$revision_ids = array();
|
||||||
|
$task_ids = array();
|
||||||
|
$commit_names = array();
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($phids as $phid => $description) {
|
|
||||||
|
$pattern =
|
||||||
|
'@'.
|
||||||
|
'(?<!/)(?:^|\b)'.
|
||||||
|
'(r[A-Z]+[0-9a-z]{1,40})'.
|
||||||
|
'(?:\b|$)'.
|
||||||
|
'@';
|
||||||
|
if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
|
||||||
|
foreach ($matches as $match) {
|
||||||
|
$commit_names[] = $match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = array();
|
||||||
|
|
||||||
|
if ($revision_ids) {
|
||||||
|
$revisions = $this->getConduit()->callMethodSynchronous(
|
||||||
|
'differential.find',
|
||||||
|
array(
|
||||||
|
'query' => 'revision-ids',
|
||||||
|
'guids' => $revision_ids,
|
||||||
|
));
|
||||||
|
foreach ($revisions as $revision) {
|
||||||
|
$output[] =
|
||||||
|
'D'.$revision['id'].' '.$revision['name'].' - '.
|
||||||
|
$revision['uri'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Support tasks in Conduit.
|
||||||
|
|
||||||
|
if ($commit_names) {
|
||||||
|
$commits = $this->getConduit()->callMethodSynchronous(
|
||||||
|
'diffusion.getcommits',
|
||||||
|
array(
|
||||||
|
'commits' => $commit_names,
|
||||||
|
));
|
||||||
|
foreach ($commits as $commit) {
|
||||||
|
if (isset($commit['error'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$output[] = $commit['uri'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($output as $description) {
|
||||||
$this->write('PRIVMSG', "{$channel} :{$description}");
|
$this->write('PRIVMSG', "{$channel} :{$description}");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
|
|
||||||
phutil_require_module('phabricator', 'infrastructure/daemon/irc/handler/base');
|
phutil_require_module('phabricator', 'infrastructure/daemon/irc/handler/base');
|
||||||
phutil_require_module('phabricator', 'infrastructure/env');
|
|
||||||
|
|
||||||
|
|
||||||
phutil_require_source('PhabricatorIRCObjectNameHandler.php');
|
phutil_require_source('PhabricatorIRCObjectNameHandler.php');
|
||||||
|
|||||||
Reference in New Issue
Block a user