@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 173 lines 4.6 kB view raw
1<?php 2 3final class DiffusionPushEventViewController 4 extends DiffusionLogController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $this->getViewer(); 8 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(); 16 } 17 18 $repository = $event->getRepository(); 19 $title = pht('Push %d', $event->getID()); 20 21 $crumbs = $this->buildApplicationCrumbs(); 22 $crumbs->addTextCrumb( 23 $repository->getName(), 24 $repository->getURI()); 25 26 $crumbs->addTextCrumb( 27 pht('Push Logs'), 28 $this->getApplicationURI( 29 'pushlog/?repositories='.$repository->getMonogram())); 30 $crumbs->addTextCrumb($title); 31 32 $event_properties = $this->buildPropertyList($event); 33 34 $detail_box = id(new PHUIObjectBoxView()) 35 ->setHeaderText($title) 36 ->addPropertyList($event_properties); 37 38 $commits = $this->loadCommits($event); 39 $commits_table = $this->renderCommitsTable($event, $commits); 40 41 $commits_box = id(new PHUIObjectBoxView()) 42 ->setHeaderText(pht('Pushed Commits')) 43 ->setTable($commits_table); 44 45 $logs = $event->getLogs(); 46 47 $updates_table = id(new DiffusionPushLogListView()) 48 ->setUser($viewer) 49 ->setLogs($logs); 50 51 $update_box = id(new PHUIObjectBoxView()) 52 ->setHeaderText(pht('All Pushed Updates')) 53 ->setTable($updates_table); 54 55 return $this->newPage() 56 ->setTitle($title) 57 ->setCrumbs($crumbs) 58 ->appendChild( 59 array( 60 $detail_box, 61 $commits_box, 62 $update_box, 63 )); 64 } 65 66 private function buildPropertyList(PhabricatorRepositoryPushEvent $event) { 67 $viewer = $this->getRequest()->getUser(); 68 $view = new PHUIPropertyListView(); 69 70 $view->addProperty( 71 pht('Pushed At'), 72 phabricator_datetime($event->getEpoch(), $viewer)); 73 74 $view->addProperty( 75 pht('Pushed By'), 76 $viewer->renderHandle($event->getPusherPHID())); 77 78 $view->addProperty( 79 pht('Pushed Via'), 80 $event->getRemoteProtocol()); 81 82 return $view; 83 } 84 85 private function loadCommits(PhabricatorRepositoryPushEvent $event) { 86 $viewer = $this->getRequest()->getUser(); 87 88 $identifiers = array(); 89 foreach ($event->getLogs() as $log) { 90 if ($log->getRefType() == PhabricatorRepositoryPushLog::REFTYPE_COMMIT) { 91 $identifiers[] = $log->getRefNew(); 92 } 93 } 94 95 if (!$identifiers) { 96 return array(); 97 } 98 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. 102 103 $commits = id(new DiffusionCommitQuery()) 104 ->setViewer($viewer) 105 ->withRepository($event->getRepository()) 106 ->withIdentifiers($identifiers) 107 ->execute(); 108 109 $commits = mpull($commits, null, 'getCommitIdentifier'); 110 111 $results = array(); 112 foreach ($identifiers as $identifier) { 113 $results[$identifier] = idx($commits, $identifier); 114 } 115 116 return $results; 117 } 118 119 private function renderCommitsTable( 120 PhabricatorRepositoryPushEvent $event, 121 array $commits) { 122 123 $viewer = $this->getRequest()->getUser(); 124 $repository = $event->getRepository(); 125 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...')); 136 } 137 } else { 138 $summary = phutil_tag('em', array(), pht('Discovering...')); 139 } 140 141 $commit_name = $repository->formatCommitName($identifier); 142 if ($commit) { 143 $commit_name = phutil_tag( 144 'a', 145 array( 146 'href' => '/'.$commit_name, 147 ), 148 $commit_name); 149 } 150 151 $rows[] = array( 152 $commit_name, 153 $summary, 154 ); 155 } 156 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'), 163 )) 164 ->setColumnClasses( 165 array( 166 'n', 167 'wide', 168 )); 169 170 return $table; 171 } 172 173}