diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 5de9f3181e..4e8b2266d7 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1009,7 +1009,6 @@ phutil_register_library_map(array( 'PhabricatorRepositoryCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php', 'PhabricatorRepositoryCommitData' => 'applications/repository/storage/PhabricatorRepositoryCommitData.php', 'PhabricatorRepositoryCommitHeraldWorker' => 'applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php', - 'PhabricatorRepositoryCommitMessageDetailParser' => 'applications/repository/parser/PhabricatorRepositoryCommitMessageDetailParser.php', 'PhabricatorRepositoryCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php', 'PhabricatorRepositoryCommitOwnersWorker' => 'applications/repository/worker/PhabricatorRepositoryCommitOwnersWorker.php', 'PhabricatorRepositoryCommitParserWorker' => 'applications/repository/worker/PhabricatorRepositoryCommitParserWorker.php', diff --git a/src/applications/repository/parser/PhabricatorRepositoryCommitMessageDetailParser.php b/src/applications/repository/parser/PhabricatorRepositoryCommitMessageDetailParser.php deleted file mode 100644 index f7d8701de1..0000000000 --- a/src/applications/repository/parser/PhabricatorRepositoryCommitMessageDetailParser.php +++ /dev/null @@ -1,101 +0,0 @@ -commit = $commit; - $this->commitData = $data; - } - - final public function getCommit() { - return $this->commit; - } - - final public function getCommitData() { - return $this->commitData; - } - - /** - * Try to link a commit name to a Phabricator account. Basically we throw it - * at the wall and see if something sticks. - */ - public function resolveUserPHID($user_name) { - if (!strlen($user_name)) { - return null; - } - - $phid = $this->findUserByUserName($user_name); - if ($phid) { - return $phid; - } - $phid = $this->findUserByEmailAddress($user_name); - if ($phid) { - return $phid; - } - $phid = $this->findUserByRealName($user_name); - if ($phid) { - return $phid; - } - - // No hits yet, try to parse it as an email address. - - $email = new PhutilEmailAddress($user_name); - - $phid = $this->findUserByEmailAddress($email->getAddress()); - if ($phid) { - return $phid; - } - - $display_name = $email->getDisplayName(); - if ($display_name) { - $phid = $this->findUserByUserName($display_name); - if ($phid) { - return $phid; - } - $phid = $this->findUserByRealName($display_name); - if ($phid) { - return $phid; - } - } - - return null; - } - - abstract public function parseCommitDetails(); - - private function findUserByUserName($user_name) { - $by_username = id(new PhabricatorUser())->loadOneWhere( - 'userName = %s', - $user_name); - if ($by_username) { - return $by_username->getPHID(); - } - return null; - } - - private function findUserByRealName($real_name) { - // Note, real names are not guaranteed unique, which is why we do it this - // way. - $by_realname = id(new PhabricatorUser())->loadAllWhere( - 'realName = %s', - $real_name); - if (count($by_realname) == 1) { - return reset($by_realname)->getPHID(); - } - return null; - } - - private function findUserByEmailAddress($email_address) { - $by_email = PhabricatorUser::loadOneWithEmailAddress($email_address); - if ($by_email) { - return $by_email->getPHID(); - } - return null; - } - -} diff --git a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php index 92f0ed3c8a..16a218d05b 100644 --- a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php +++ b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php @@ -20,10 +20,17 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker } $data->setCommitID($commit->getID()); $data->setAuthorName($author); + $data->setCommitDetail( + 'authorPHID', + $this->resolveUserPHID($author)); + $data->setCommitMessage($message); if ($committer) { $data->setCommitDetail('committer', $committer); + $data->setCommitDetail( + 'committerPHID', + $this->resolveUserPHID($committer)); } $repository = $this->repository; @@ -436,4 +443,76 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker return $event->getValue('result'); } + private function resolveUserPHID($user_name) { + if (!strlen($user_name)) { + return null; + } + + $phid = $this->findUserByUserName($user_name); + if ($phid) { + return $phid; + } + $phid = $this->findUserByEmailAddress($user_name); + if ($phid) { + return $phid; + } + $phid = $this->findUserByRealName($user_name); + if ($phid) { + return $phid; + } + + // No hits yet, try to parse it as an email address. + + $email = new PhutilEmailAddress($user_name); + + $phid = $this->findUserByEmailAddress($email->getAddress()); + if ($phid) { + return $phid; + } + + $display_name = $email->getDisplayName(); + if ($display_name) { + $phid = $this->findUserByUserName($display_name); + if ($phid) { + return $phid; + } + $phid = $this->findUserByRealName($display_name); + if ($phid) { + return $phid; + } + } + + return null; + } + + private function findUserByUserName($user_name) { + $by_username = id(new PhabricatorUser())->loadOneWhere( + 'userName = %s', + $user_name); + if ($by_username) { + return $by_username->getPHID(); + } + return null; + } + + private function findUserByRealName($real_name) { + // Note, real names are not guaranteed unique, which is why we do it this + // way. + $by_realname = id(new PhabricatorUser())->loadAllWhere( + 'realName = %s', + $real_name); + if (count($by_realname) == 1) { + return reset($by_realname)->getPHID(); + } + return null; + } + + private function findUserByEmailAddress($email_address) { + $by_email = PhabricatorUser::loadOneWithEmailAddress($email_address); + if ($by_email) { + return $by_email->getPHID(); + } + return null; + } + }