private static function renderName($name)
 {
     $email = new PhutilEmailAddress($name);
     if ($email->getDisplayName() || $email->getDomainName()) {
         return phutil_render_tag('span', array('title' => $email->getAddress()), phutil_escape_html($email->getDisplayName()));
     }
     return phutil_escape_html($name);
 }
Пример #2
0
 public static final function renderName($name)
 {
     $email = new PhutilEmailAddress($name);
     if ($email->getDisplayName() && $email->getDomainName()) {
         Javelin::initBehavior('phabricator-tooltips', array());
         require_celerity_resource('aphront-tooltip-css');
         return javelin_tag('span', array('sigil' => 'has-tooltip', 'meta' => array('tip' => $email->getAddress(), 'align' => 'E', 'size' => 'auto')), $email->getDisplayName());
     }
     return hsprintf('%s', $name);
 }
 public function testEmailParsing()
 {
     $email = new PhutilEmailAddress('Abraham Lincoln <*****@*****.**>');
     $this->assertEqual('Abraham Lincoln', $email->getDisplayName());
     $this->assertEqual('alincoln', $email->getLocalPart());
     $this->assertEqual('logcabin.com', $email->getDomainName());
     $this->assertEqual('*****@*****.**', $email->getAddress());
     $email = new PhutilEmailAddress('*****@*****.**');
     $this->assertEqual(null, $email->getDisplayName());
     $this->assertEqual('alincoln', $email->getLocalPart());
     $this->assertEqual('logcabin.com', $email->getDomainName());
     $this->assertEqual('*****@*****.**', $email->getAddress());
     $email = new PhutilEmailAddress('"Abraham" <*****@*****.**>');
     $this->assertEqual('Abraham', $email->getDisplayName());
     $this->assertEqual('alincoln', $email->getLocalPart());
     $this->assertEqual('logcabin.com', $email->getDomainName());
     $this->assertEqual('*****@*****.**', $email->getAddress());
     $email = new PhutilEmailAddress('    alincoln@logcabin.com     ');
     $this->assertEqual(null, $email->getDisplayName());
     $this->assertEqual('alincoln', $email->getLocalPart());
     $this->assertEqual('logcabin.com', $email->getDomainName());
     $this->assertEqual('*****@*****.**', $email->getAddress());
     $email = new PhutilEmailAddress('alincoln');
     $this->assertEqual(null, $email->getDisplayName());
     $this->assertEqual('alincoln', $email->getLocalPart());
     $this->assertEqual(null, $email->getDomainName());
     $this->assertEqual('alincoln', $email->getAddress());
     $email = new PhutilEmailAddress('alincoln <alincoln at logcabin dot com>');
     $this->assertEqual('alincoln', $email->getDisplayName());
     $this->assertEqual('alincoln at logcabin dot com', $email->getLocalPart());
     $this->assertEqual(null, $email->getDomainName());
     $this->assertEqual('alincoln at logcabin dot com', $email->getAddress());
 }
 /**
  * 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->findUserByRealName($display_name);
         if ($phid) {
             return $phid;
         }
     }
     return null;
 }
Пример #5
0
 public function getFullAuthor()
 {
     $author_name = $this->getAuthorName();
     if ($author_name === null) {
         return null;
     }
     $author_email = $this->getAuthorEmail();
     if ($author_email === null) {
         return null;
     }
     $full_author = sprintf('%s <%s>', $author_name, $author_email);
     // Because git is very picky about the author being in a valid format,
     // verify that we can parse it.
     $address = new PhutilEmailAddress($full_author);
     if (!$address->getDisplayName() || !$address->getAddress()) {
         return null;
     }
     return $full_author;
 }
 public function renderAuthorShortName($handles)
 {
     $author_phid = $this->getAuthorPHID();
     if ($author_phid && isset($handles[$author_phid])) {
         return $handles[$author_phid]->getName();
     }
     $data = $this->getCommitData();
     $name = $data->getAuthorName();
     $parsed = new PhutilEmailAddress($name);
     return nonempty($parsed->getDisplayName(), $parsed->getAddress());
 }
 public function run()
 {
     $source = $this->getSource();
     switch ($source) {
         case self::SOURCE_LOCAL:
             $repository_api = $this->getRepositoryAPI();
             $parser = new ArcanistDiffParser();
             $parser->setRepositoryAPI($repository_api);
             if ($repository_api instanceof ArcanistGitAPI) {
                 $this->parseBaseCommitArgument($this->getArgument('paths'));
                 $diff = $repository_api->getFullGitDiff($repository_api->getBaseCommit(), $repository_api->getHeadCommit());
                 $changes = $parser->parseDiff($diff);
                 $authors = $this->getConduit()->callMethodSynchronous('user.query', array('phids' => array($this->getUserPHID())));
                 $author_dict = reset($authors);
                 list($email) = $repository_api->execxLocal('config user.email');
                 $author = sprintf('%s <%s>', $author_dict['realName'], $email);
             } else {
                 if ($repository_api instanceof ArcanistMercurialAPI) {
                     $this->parseBaseCommitArgument($this->getArgument('paths'));
                     $diff = $repository_api->getFullMercurialDiff();
                     $changes = $parser->parseDiff($diff);
                     $authors = $this->getConduit()->callMethodSynchronous('user.query', array('phids' => array($this->getUserPHID())));
                     list($author) = $repository_api->execxLocal('showconfig ui.username');
                 } else {
                     // TODO: paths support
                     $paths = $repository_api->getWorkingCopyStatus();
                     $changes = $parser->parseSubversionDiff($repository_api, $paths);
                     $author = $this->getUserName();
                 }
             }
             $bundle = ArcanistBundle::newFromChanges($changes);
             $bundle->setProjectID($this->getWorkingCopy()->getProjectID());
             $bundle->setBaseRevision($repository_api->getSourceControlBaseRevision());
             // NOTE: we can't get a revision ID for SOURCE_LOCAL
             $parser = new PhutilEmailAddress($author);
             $bundle->setAuthorName($parser->getDisplayName());
             $bundle->setAuthorEmail($parser->getAddress());
             break;
         case self::SOURCE_REVISION:
             $bundle = $this->loadRevisionBundleFromConduit($this->getConduit(), $this->getSourceID());
             break;
         case self::SOURCE_DIFF:
             $bundle = $this->loadDiffBundleFromConduit($this->getConduit(), $this->getSourceID());
             break;
     }
     $try_encoding = nonempty($this->getArgument('encoding'), null);
     if (!$try_encoding) {
         try {
             $project_info = $this->getConduit()->callMethodSynchronous('arcanist.projectinfo', array('name' => $bundle->getProjectID()));
             $try_encoding = $project_info['encoding'];
         } catch (ConduitClientException $e) {
             $try_encoding = null;
         }
     }
     if ($try_encoding) {
         $bundle->setEncoding($try_encoding);
     }
     $format = $this->getFormat();
     switch ($format) {
         case self::FORMAT_GIT:
             echo $bundle->toGitPatch();
             break;
         case self::FORMAT_UNIFIED:
             echo $bundle->toUnifiedDiff();
             break;
         case self::FORMAT_BUNDLE:
             $path = $this->getArgument('arcbundle');
             echo "Writing bundle to '{$path}'...\n";
             $bundle->writeToDisk($path);
             echo "done.\n";
             break;
     }
     return 0;
 }
 private function splitUserIdentifier($user)
 {
     $email = new PhutilEmailAddress($user);
     if ($email->getDisplayName() || $email->getDomainName()) {
         $user_name = $email->getDisplayName();
         $user_email = $email->getAddress();
     } else {
         $user_name = $email->getAddress();
         $user_email = null;
     }
     return array($user_name, $user_email);
 }
Пример #9
0
 /**
  * Parse the Mercurial author field.
  *
  * Not everyone enters their email address as a part of the username
  * field. Try to make it work when it's obvious.
  *
  * @param string $full_author
  * @return array
  */
 protected function parseFullAuthor($full_author)
 {
     if (strpos($full_author, '@') === false) {
         $author = $full_author;
         $author_email = null;
     } else {
         $email = new PhutilEmailAddress($full_author);
         $author = $email->getDisplayName();
         $author_email = $email->getAddress();
     }
     return array($author, $author_email);
 }
 public function getAuthor()
 {
     $full_author = $this->getMercurialConfig('ui.username');
     $email = new PhutilEmailAddress($full_author);
     $author = $email->getDisplayName();
     return $author;
 }