Path: blob/master/src/applications/diffusion/doorkeeper/DiffusionDoorkeeperCommitFeedStoryPublisher.php
12241 views
<?php12final class DiffusionDoorkeeperCommitFeedStoryPublisher3extends DoorkeeperFeedStoryPublisher {45private $auditRequests;6private $activePHIDs;7private $passivePHIDs;89private function getAuditRequests() {10return $this->auditRequests;11}1213public function canPublishStory(PhabricatorFeedStory $story, $object) {14return15($story instanceof PhabricatorApplicationTransactionFeedStory) &&16($object instanceof PhabricatorRepositoryCommit);17}1819public function isStoryAboutObjectCreation($object) {20// TODO: Although creation stories exist, they currently don't have a21// primary object PHID set, so they'll never make it here because they22// won't pass `canPublishStory()`.23return false;24}2526public function isStoryAboutObjectClosure($object) {27// TODO: This isn't quite accurate, but pretty close: check if this story28// is a close (which clearly is about object closure) or is an "Accept" and29// the commit is fully audited (which is almost certainly a closure).30// After ApplicationTransactions, we could annotate feed stories more31// explicitly.3233$story = $this->getFeedStory();34$xaction = $story->getPrimaryTransaction();35switch ($xaction->getTransactionType()) {36case PhabricatorAuditActionConstants::ACTION:37switch ($xaction->getNewValue()) {38case PhabricatorAuditActionConstants::CLOSE:39return true;40case PhabricatorAuditActionConstants::ACCEPT:41if ($object->isAuditStatusAudited()) {42return true;43}44break;45}46}4748return false;49}5051public function willPublishStory($commit) {52$requests = id(new DiffusionCommitQuery())53->setViewer($this->getViewer())54->withPHIDs(array($commit->getPHID()))55->needAuditRequests(true)56->executeOne()57->getAudits();5859// TODO: This is messy and should be generalized, but we don't have a good60// query for it yet. Since we run in the daemons, just do the easiest thing61// we can for the moment. Figure out who all of the "active" (need to62// audit) and "passive" (no action necessary) users are.6364$auditor_phids = mpull($requests, 'getAuditorPHID');65$objects = id(new PhabricatorObjectQuery())66->setViewer($this->getViewer())67->withPHIDs($auditor_phids)68->execute();6970$active = array();71$passive = array();7273foreach ($requests as $request) {74$status = $request->getAuditStatus();7576$object = idx($objects, $request->getAuditorPHID());77if (!$object) {78continue;79}8081$request_phids = array();82if ($object instanceof PhabricatorUser) {83$request_phids = array($object->getPHID());84} else if ($object instanceof PhabricatorOwnersPackage) {85$request_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(86array($object->getID()));87} else if ($object instanceof PhabricatorProject) {88$project = id(new PhabricatorProjectQuery())89->setViewer($this->getViewer())90->withIDs(array($object->getID()))91->needMembers(true)92->executeOne();93$request_phids = $project->getMemberPHIDs();94} else {95// Dunno what this is.96$request_phids = array();97}9899switch ($status) {100case PhabricatorAuditRequestStatus::AUDIT_REQUIRED:101case PhabricatorAuditRequestStatus::AUDIT_REQUESTED:102case PhabricatorAuditRequestStatus::CONCERNED:103$active += array_fuse($request_phids);104break;105default:106$passive += array_fuse($request_phids);107break;108}109}110111112// Remove "Active" users from the "Passive" list.113$passive = array_diff_key($passive, $active);114115$this->activePHIDs = $active;116$this->passivePHIDs = $passive;117$this->auditRequests = $requests;118119return $commit;120}121122public function getOwnerPHID($object) {123return $object->getAuthorPHID();124}125126public function getActiveUserPHIDs($object) {127return $this->activePHIDs;128}129130public function getPassiveUserPHIDs($object) {131return $this->passivePHIDs;132}133134public function getCCUserPHIDs($object) {135return PhabricatorSubscribersQuery::loadSubscribersForPHID(136$object->getPHID());137}138139public function getObjectTitle($object) {140$prefix = $this->getTitlePrefix($object);141142$repository = $object->getRepository();143$name = $repository->formatCommitName($object->getCommitIdentifier());144145$title = $object->getSummary();146147return ltrim("{$prefix} {$name}: {$title}");148}149150public function getObjectURI($object) {151$repository = $object->getRepository();152$name = $repository->formatCommitName($object->getCommitIdentifier());153return PhabricatorEnv::getProductionURI('/'.$name);154}155156public function getObjectDescription($object) {157$data = $object->loadCommitData();158if ($data) {159return $data->getCommitMessage();160}161return null;162}163164public function isObjectClosed($object) {165return $object->getAuditStatusObject()->getIsClosed();166}167168public function getResponsibilityTitle($object) {169$prefix = $this->getTitlePrefix($object);170return pht('%s Audit', $prefix);171}172173private function getTitlePrefix(PhabricatorRepositoryCommit $commit) {174return pht('[Diffusion]');175}176177}178179180