Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / diffusion / controller / DiffusionPushEventViewController.php
blob21718c256d75544722bed9851550537262b75b11
1 <?php
3 final class DiffusionPushEventViewController
4 extends DiffusionLogController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
9 $event = id(new PhabricatorRepositoryPushEventQuery())
10 ->setViewer($viewer)
11 ->withIDs(array($request->getURIData('id')))
12 ->needLogs(true)
13 ->executeOne();
14 if (!$event) {
15 return new Aphront404Response();
18 $repository = $event->getRepository();
19 $title = pht('Push %d', $event->getID());
21 $crumbs = $this->buildApplicationCrumbs();
22 $crumbs->addTextCrumb(
23 $repository->getName(),
24 $repository->getURI());
26 $crumbs->addTextCrumb(
27 pht('Push Logs'),
28 $this->getApplicationURI(
29 'pushlog/?repositories='.$repository->getMonogram()));
30 $crumbs->addTextCrumb($title);
32 $event_properties = $this->buildPropertyList($event);
34 $detail_box = id(new PHUIObjectBoxView())
35 ->setHeaderText($title)
36 ->addPropertyList($event_properties);
38 $commits = $this->loadCommits($event);
39 $commits_table = $this->renderCommitsTable($event, $commits);
41 $commits_box = id(new PHUIObjectBoxView())
42 ->setHeaderText(pht('Pushed Commits'))
43 ->setTable($commits_table);
45 $logs = $event->getLogs();
47 $updates_table = id(new DiffusionPushLogListView())
48 ->setUser($viewer)
49 ->setLogs($logs);
51 $update_box = id(new PHUIObjectBoxView())
52 ->setHeaderText(pht('All Pushed Updates'))
53 ->setTable($updates_table);
55 return $this->newPage()
56 ->setTitle($title)
57 ->setCrumbs($crumbs)
58 ->appendChild(
59 array(
60 $detail_box,
61 $commits_box,
62 $update_box,
63 ));
66 private function buildPropertyList(PhabricatorRepositoryPushEvent $event) {
67 $viewer = $this->getRequest()->getUser();
68 $view = new PHUIPropertyListView();
70 $view->addProperty(
71 pht('Pushed At'),
72 phabricator_datetime($event->getEpoch(), $viewer));
74 $view->addProperty(
75 pht('Pushed By'),
76 $viewer->renderHandle($event->getPusherPHID()));
78 $view->addProperty(
79 pht('Pushed Via'),
80 $event->getRemoteProtocol());
82 return $view;
85 private function loadCommits(PhabricatorRepositoryPushEvent $event) {
86 $viewer = $this->getRequest()->getUser();
88 $identifiers = array();
89 foreach ($event->getLogs() as $log) {
90 if ($log->getRefType() == PhabricatorRepositoryPushLog::REFTYPE_COMMIT) {
91 $identifiers[] = $log->getRefNew();
95 if (!$identifiers) {
96 return array();
99 // NOTE: Commits may not have been parsed/discovered yet. We need to return
100 // the identifiers no matter what. If possible, we'll also return the
101 // corresponding commits.
103 $commits = id(new DiffusionCommitQuery())
104 ->setViewer($viewer)
105 ->withRepository($event->getRepository())
106 ->withIdentifiers($identifiers)
107 ->execute();
109 $commits = mpull($commits, null, 'getCommitIdentifier');
111 $results = array();
112 foreach ($identifiers as $identifier) {
113 $results[$identifier] = idx($commits, $identifier);
116 return $results;
119 private function renderCommitsTable(
120 PhabricatorRepositoryPushEvent $event,
121 array $commits) {
123 $viewer = $this->getRequest()->getUser();
124 $repository = $event->getRepository();
126 $rows = array();
127 foreach ($commits as $identifier => $commit) {
128 if ($commit) {
129 $partial_import = PhabricatorRepositoryCommit::IMPORTED_MESSAGE |
130 PhabricatorRepositoryCommit::IMPORTED_CHANGE;
131 if ($commit->isPartiallyImported($partial_import)) {
132 $summary = AphrontTableView::renderSingleDisplayLine(
133 $commit->getSummary());
134 } else {
135 $summary = phutil_tag('em', array(), pht('Importing...'));
137 } else {
138 $summary = phutil_tag('em', array(), pht('Discovering...'));
141 $commit_name = $repository->formatCommitName($identifier);
142 if ($commit) {
143 $commit_name = phutil_tag(
144 'a',
145 array(
146 'href' => '/'.$commit_name,
148 $commit_name);
151 $rows[] = array(
152 $commit_name,
153 $summary,
157 $table = id(new AphrontTableView($rows))
158 ->setNoDataString(pht("This push didn't push any new commits."))
159 ->setHeaders(
160 array(
161 pht('Commit'),
162 pht('Summary'),
164 ->setColumnClasses(
165 array(
166 'n',
167 'wide',
170 return $table;