[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/controller/ -> DiffusionPushEventViewController.php (source)

   1  <?php
   2  
   3  final class DiffusionPushEventViewController
   4    extends DiffusionPushLogController {
   5  
   6    private $id;
   7  
   8    public function shouldAllowPublic() {
   9      return true;
  10    }
  11  
  12    public function willProcessRequest(array $data) {
  13      $this->id = idx($data, 'id');
  14    }
  15  
  16    public function processRequest() {
  17      $request = $this->getRequest();
  18      $viewer = $request->getUser();
  19  
  20      $event = id(new PhabricatorRepositoryPushEventQuery())
  21        ->setViewer($viewer)
  22        ->withIDs(array($this->id))
  23        ->needLogs(true)
  24        ->executeOne();
  25      if (!$event) {
  26        return new Aphront404Response();
  27      }
  28  
  29      $repository = $event->getRepository();
  30      $title = pht('Push %d', $event->getID());
  31  
  32      $crumbs = $this->buildApplicationCrumbs();
  33      $crumbs->addTextCrumb(
  34        $repository->getName(),
  35        $this->getApplicationURI($repository->getCallsign().'/'));
  36      $crumbs->addTextCrumb(
  37        pht('Push Logs'),
  38        $this->getApplicationURI(
  39          'pushlog/?repositories='.$repository->getMonogram()));
  40      $crumbs->addTextCrumb($title);
  41  
  42      $event_properties = $this->buildPropertyList($event);
  43  
  44      $detail_box = id(new PHUIObjectBoxView())
  45        ->setHeaderText($title)
  46        ->addPropertyList($event_properties);
  47  
  48      $commits = $this->loadCommits($event);
  49      $commits_table = $this->renderCommitsTable($event, $commits);
  50  
  51      $commits_box = id(new PHUIObjectBoxView())
  52        ->setHeaderText(pht('Pushed Commits'))
  53        ->appendChild($commits_table);
  54  
  55      $logs = $event->getLogs();
  56  
  57      $updates_table = id(new DiffusionPushLogListView())
  58        ->setUser($viewer)
  59        ->setLogs($logs)
  60        ->setHandles($this->loadViewerHandles(mpull($logs, 'getPusherPHID')));
  61  
  62      $update_box = id(new PHUIObjectBoxView())
  63        ->setHeaderText(pht('All Pushed Updates'))
  64        ->appendChild($updates_table);
  65  
  66      return $this->buildApplicationPage(
  67        array(
  68          $crumbs,
  69          $detail_box,
  70          $commits_box,
  71          $update_box,
  72        ),
  73        array(
  74          'title' => $title,
  75        ));
  76    }
  77  
  78    private function buildPropertyList(PhabricatorRepositoryPushEvent $event) {
  79      $viewer = $this->getRequest()->getUser();
  80  
  81      $this->loadHandles(array($event->getPusherPHID()));
  82  
  83      $view = new PHUIPropertyListView();
  84  
  85      $view->addProperty(
  86        pht('Pushed At'),
  87        phabricator_datetime($event->getEpoch(), $viewer));
  88  
  89      $view->addProperty(
  90        pht('Pushed By'),
  91        $this->getHandle($event->getPusherPHID())->renderLink());
  92  
  93      $view->addProperty(
  94        pht('Pushed Via'),
  95        $event->getRemoteProtocol());
  96  
  97      return $view;
  98    }
  99  
 100    private function loadCommits(PhabricatorRepositoryPushEvent $event) {
 101      $viewer = $this->getRequest()->getUser();
 102  
 103      $identifiers = array();
 104      foreach ($event->getLogs() as $log) {
 105        if ($log->getRefType() == PhabricatorRepositoryPushLog::REFTYPE_COMMIT) {
 106          $identifiers[] = $log->getRefNew();
 107        }
 108      }
 109  
 110      if (!$identifiers) {
 111        return array();
 112      }
 113  
 114      // NOTE: Commits may not have been parsed/discovered yet. We need to return
 115      // the identifiers no matter what. If possible, we'll also return the
 116      // corresponding commits.
 117  
 118      $commits = id(new DiffusionCommitQuery())
 119        ->setViewer($viewer)
 120        ->withRepository($event->getRepository())
 121        ->withIdentifiers($identifiers)
 122        ->execute();
 123  
 124      $commits = mpull($commits, null, 'getCommitIdentifier');
 125  
 126      $results = array();
 127      foreach ($identifiers as $identifier) {
 128        $results[$identifier] = idx($commits, $identifier);
 129      }
 130  
 131      return $results;
 132    }
 133  
 134    private function renderCommitsTable(
 135      PhabricatorRepositoryPushEvent $event,
 136      array $commits) {
 137  
 138      $viewer = $this->getRequest()->getUser();
 139      $repository = $event->getRepository();
 140  
 141      $rows = array();
 142      foreach ($commits as $identifier => $commit) {
 143        if ($commit) {
 144          $partial_import = PhabricatorRepositoryCommit::IMPORTED_MESSAGE |
 145                            PhabricatorRepositoryCommit::IMPORTED_CHANGE;
 146          if ($commit->isPartiallyImported($partial_import)) {
 147            $summary = AphrontTableView::renderSingleDisplayLine(
 148              $commit->getSummary());
 149          } else {
 150            $summary = phutil_tag('em', array(), pht('Importing...'));
 151          }
 152        } else {
 153          $summary = phutil_tag('em', array(), pht('Discovering...'));
 154        }
 155  
 156        $commit_name = $repository->formatCommitName($identifier);
 157        if ($commit) {
 158          $commit_name = phutil_tag(
 159            'a',
 160            array(
 161              'href' => '/'.$commit_name,
 162            ),
 163            $commit_name);
 164        }
 165  
 166        $rows[] = array(
 167          $commit_name,
 168          $summary,
 169        );
 170      }
 171  
 172      $table = id(new AphrontTableView($rows))
 173        ->setNoDataString(pht("This push didn't push any new commits."))
 174        ->setHeaders(
 175          array(
 176            pht('Commit'),
 177            pht('Summary'),
 178          ))
 179        ->setColumnClasses(
 180          array(
 181            'n',
 182            'wide',
 183          ));
 184  
 185      return $table;
 186    }
 187  
 188  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1