mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
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:
parent
0cdf4c2518
commit
d3fed84b9c
8 changed files with 81 additions and 17 deletions
|
@ -40,3 +40,5 @@ phutil_load_library('arcanist/src');
|
|||
foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) {
|
||||
phutil_load_library($library);
|
||||
}
|
||||
|
||||
PhutilErrorHandler::initialize();
|
||||
|
|
|
@ -66,10 +66,12 @@ class ConduitAPI_differential_find_Method extends ConduitAPIMethod {
|
|||
if (!$diff) {
|
||||
continue;
|
||||
}
|
||||
$id = $revision->getID();
|
||||
$results[] = array(
|
||||
'id' => $revision->getID(),
|
||||
'id' => $id,
|
||||
'phid' => $revision->getPHID(),
|
||||
'name' => $revision->getTitle(),
|
||||
'uri' => PhabricatorEnv::getProductionURI('/D'.$id),
|
||||
'dateCreated' => $revision->getDateCreated(),
|
||||
'authorPHID' => $revision->getAuthorPHID(),
|
||||
'statusName' => DifferentialRevisionStatus::getNameForRevisionStatus(
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
phutil_require_module('phabricator', 'applications/conduit/method/base');
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus');
|
||||
phutil_require_module('phabricator', 'applications/differential/data/revisionlist');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
|
|
@ -126,7 +126,12 @@ class ConduitAPI_diffusion_getcommits_Method extends ConduitAPIMethod {
|
|||
);
|
||||
|
||||
// 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) {
|
||||
|
|
|
@ -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/commitdata');
|
||||
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/queryfx');
|
||||
|
||||
|
|
|
@ -113,6 +113,8 @@ final class PhabricatorIRCBot extends PhabricatorDaemon {
|
|||
|
||||
private function runSelectLoop() {
|
||||
do {
|
||||
$this->stillWorking();
|
||||
|
||||
$read = array($this->socket);
|
||||
if (strlen($this->writeBuffer)) {
|
||||
$write = array($this->socket);
|
||||
|
|
|
@ -35,24 +35,76 @@ class PhabricatorIRCObjectNameHandler extends PhabricatorIRCHandler {
|
|||
$message = $message->getMessageText();
|
||||
$matches = null;
|
||||
$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.
|
||||
foreach ($revisions as $revision) {
|
||||
$phids[$revision['phid']] =
|
||||
'D'.$revision['id'].' '.$revision['name'].' - '.
|
||||
PhabricatorEnv::getProductionURI('/D'.$revision['id']);
|
||||
$pattern =
|
||||
'@'.
|
||||
'(?<!/)(?:^|\b)'. // Negative lookbehind prevent matching "/D123".
|
||||
'(D|T)(\d+)'.
|
||||
'(?:\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}");
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
|
||||
phutil_require_module('phabricator', 'infrastructure/daemon/irc/handler/base');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorIRCObjectNameHandler.php');
|
||||
|
|
Loading…
Reference in a new issue