private function sendMail(PhabricatorMailTarget $target, PhabricatorRepository $repository, PhabricatorRepositoryPushEvent $event)
 {
     $task_data = $this->getTaskData();
     $viewer = $target->getViewer();
     $locale = PhabricatorEnv::beginScopedLocale($viewer->getTranslation());
     $logs = $event->getLogs();
     list($ref_lines, $ref_list) = $this->renderRefs($logs);
     list($commit_lines, $subject_line) = $this->renderCommits($repository, $logs, idx($task_data, 'info', array()));
     $ref_count = count($ref_lines);
     $commit_count = count($commit_lines);
     $handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($event->getPusherPHID()))->execute();
     $pusher_name = $handles[$event->getPusherPHID()]->getName();
     $repo_name = $repository->getMonogram();
     if ($commit_count) {
         $overview = pht('%s pushed %d commit(s) to %s.', $pusher_name, $commit_count, $repo_name);
     } else {
         $overview = pht('%s pushed to %s.', $pusher_name, $repo_name);
     }
     $details_uri = PhabricatorEnv::getProductionURI('/diffusion/pushlog/view/' . $event->getID() . '/');
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection($overview);
     $body->addLinkSection(pht('DETAILS'), $details_uri);
     if ($commit_lines) {
         $body->addTextSection(pht('COMMITS'), implode("\n", $commit_lines));
     }
     if ($ref_lines) {
         $body->addTextSection(pht('REFERENCES'), implode("\n", $ref_lines));
     }
     $prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix');
     $parts = array();
     if ($commit_count) {
         $parts[] = pht('%s commit(s)', $commit_count);
     }
     if ($ref_count) {
         $parts[] = implode(', ', $ref_list);
     }
     $parts = implode(', ', $parts);
     if ($subject_line) {
         $subject = pht('(%s) %s', $parts, $subject_line);
     } else {
         $subject = pht('(%s)', $parts);
     }
     $mail = id(new PhabricatorMetaMTAMail())->setRelatedPHID($event->getPHID())->setSubjectPrefix($prefix)->setVarySubjectPrefix(pht('[Push]'))->setSubject($subject)->setFrom($event->getPusherPHID())->setBody($body->render())->setThreadID($event->getPHID(), $is_new = true)->addHeader('Thread-Topic', $subject)->setIsBulk(true);
     $target->sendMail($mail);
 }
 private function loadCommits(PhabricatorRepositoryPushEvent $event)
 {
     $viewer = $this->getRequest()->getUser();
     $identifiers = array();
     foreach ($event->getLogs() as $log) {
         if ($log->getRefType() == PhabricatorRepositoryPushLog::REFTYPE_COMMIT) {
             $identifiers[] = $log->getRefNew();
         }
     }
     if (!$identifiers) {
         return array();
     }
     // NOTE: Commits may not have been parsed/discovered yet. We need to return
     // the identifiers no matter what. If possible, we'll also return the
     // corresponding commits.
     $commits = id(new DiffusionCommitQuery())->setViewer($viewer)->withRepository($event->getRepository())->withIdentifiers($identifiers)->execute();
     $commits = mpull($commits, null, 'getCommitIdentifier');
     $results = array();
     foreach ($identifiers as $identifier) {
         $results[$identifier] = idx($commits, $identifier);
     }
     return $results;
 }