[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DiffusionDoorkeeperCommitFeedStoryPublisher 4 extends DoorkeeperFeedStoryPublisher { 5 6 private $auditRequests; 7 private $activePHIDs; 8 private $passivePHIDs; 9 10 private function getAuditRequests() { 11 return $this->auditRequests; 12 } 13 14 public function canPublishStory(PhabricatorFeedStory $story, $object) { 15 return 16 ($story instanceof PhabricatorApplicationTransactionFeedStory) && 17 ($object instanceof PhabricatorRepositoryCommit); 18 } 19 20 public function isStoryAboutObjectCreation($object) { 21 // TODO: Although creation stories exist, they currently don't have a 22 // primary object PHID set, so they'll never make it here because they 23 // won't pass `canPublishStory()`. 24 return false; 25 } 26 27 public function isStoryAboutObjectClosure($object) { 28 // TODO: This isn't quite accurate, but pretty close: check if this story 29 // is a close (which clearly is about object closure) or is an "Accept" and 30 // the commit is fully audited (which is almost certainly a closure). 31 // After ApplicationTransactions, we could annotate feed stories more 32 // explicitly. 33 34 $fully_audited = PhabricatorAuditCommitStatusConstants::FULLY_AUDITED; 35 36 $story = $this->getFeedStory(); 37 $xaction = $story->getPrimaryTransaction(); 38 switch ($xaction->getTransactionType()) { 39 case PhabricatorAuditActionConstants::ACTION: 40 switch ($xaction->getNewValue()) { 41 case PhabricatorAuditActionConstants::CLOSE: 42 return true; 43 case PhabricatorAuditActionConstants::ACCEPT: 44 if ($object->getAuditStatus() == $fully_audited) { 45 return true; 46 } 47 break; 48 } 49 } 50 51 return false; 52 } 53 54 public function willPublishStory($commit) { 55 $requests = id(new DiffusionCommitQuery()) 56 ->setViewer($this->getViewer()) 57 ->withPHIDs(array($commit->getPHID())) 58 ->needAuditRequests(true) 59 ->executeOne() 60 ->getAudits(); 61 62 // TODO: This is messy and should be generalized, but we don't have a good 63 // query for it yet. Since we run in the daemons, just do the easiest thing 64 // we can for the moment. Figure out who all of the "active" (need to 65 // audit) and "passive" (no action necessary) users are. 66 67 $auditor_phids = mpull($requests, 'getAuditorPHID'); 68 $objects = id(new PhabricatorObjectQuery()) 69 ->setViewer($this->getViewer()) 70 ->withPHIDs($auditor_phids) 71 ->execute(); 72 73 $active = array(); 74 $passive = array(); 75 76 foreach ($requests as $request) { 77 $status = $request->getAuditStatus(); 78 79 $object = idx($objects, $request->getAuditorPHID()); 80 if (!$object) { 81 continue; 82 } 83 84 $request_phids = array(); 85 if ($object instanceof PhabricatorUser) { 86 $request_phids = array($object->getPHID()); 87 } else if ($object instanceof PhabricatorOwnersPackage) { 88 $request_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs( 89 array($object->getID())); 90 } else if ($object instanceof PhabricatorProject) { 91 $project = id(new PhabricatorProjectQuery()) 92 ->setViewer($this->getViewer()) 93 ->withIDs(array($object->getID())) 94 ->needMembers(true) 95 ->executeOne(); 96 $request_phids = $project->getMemberPHIDs(); 97 } else { 98 // Dunno what this is. 99 $request_phids = array(); 100 } 101 102 switch ($status) { 103 case PhabricatorAuditStatusConstants::AUDIT_REQUIRED: 104 case PhabricatorAuditStatusConstants::AUDIT_REQUESTED: 105 case PhabricatorAuditStatusConstants::CONCERNED: 106 $active += array_fuse($request_phids); 107 break; 108 default: 109 $passive += array_fuse($request_phids); 110 break; 111 } 112 } 113 114 115 // Remove "Active" users from the "Passive" list. 116 $passive = array_diff_key($passive, $active); 117 118 $this->activePHIDs = $active; 119 $this->passivePHIDs = $passive; 120 $this->auditRequests = $requests; 121 122 return $commit; 123 } 124 125 public function getOwnerPHID($object) { 126 return $object->getAuthorPHID(); 127 } 128 129 public function getActiveUserPHIDs($object) { 130 return $this->activePHIDs; 131 } 132 133 public function getPassiveUserPHIDs($object) { 134 return $this->passivePHIDs; 135 } 136 137 public function getCCUserPHIDs($object) { 138 return PhabricatorSubscribersQuery::loadSubscribersForPHID( 139 $object->getPHID()); 140 } 141 142 public function getObjectTitle($object) { 143 $prefix = $this->getTitlePrefix($object); 144 145 $repository = $object->getRepository(); 146 $name = $repository->formatCommitName($object->getCommitIdentifier()); 147 148 $title = $object->getSummary(); 149 150 return ltrim("{$prefix} {$name}: {$title}"); 151 } 152 153 public function getObjectURI($object) { 154 $repository = $object->getRepository(); 155 $name = $repository->formatCommitName($object->getCommitIdentifier()); 156 return PhabricatorEnv::getProductionURI('/'.$name); 157 } 158 159 public function getObjectDescription($object) { 160 $data = $object->loadCommitData(); 161 if ($data) { 162 return $data->getCommitMessage(); 163 } 164 return null; 165 } 166 167 public function isObjectClosed($object) { 168 switch ($object->getAuditStatus()) { 169 case PhabricatorAuditCommitStatusConstants::NEEDS_AUDIT: 170 case PhabricatorAuditCommitStatusConstants::CONCERN_RAISED: 171 case PhabricatorAuditCommitStatusConstants::PARTIALLY_AUDITED: 172 return false; 173 default: 174 return true; 175 } 176 } 177 178 public function getResponsibilityTitle($object) { 179 $prefix = $this->getTitlePrefix($object); 180 return pht('%s Audit', $prefix); 181 } 182 183 private function getTitlePrefix(PhabricatorRepositoryCommit $commit) { 184 $prefix_key = 'metamta.diffusion.subject-prefix'; 185 return PhabricatorEnv::getEnvConfig($prefix_key); 186 } 187 188 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |