@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add commits/audits to Asana bridge

Summary: Ref T2852. Adds sync for commits/audits.

Test Plan: {F51660}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2852

Differential Revision: https://secure.phabricator.com/D6573

+194 -1
+2
src/__phutil_library_map__.php
··· 446 446 'DiffusionCommitTagsController' => 'applications/diffusion/controller/DiffusionCommitTagsController.php', 447 447 'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php', 448 448 'DiffusionDiffController' => 'applications/diffusion/controller/DiffusionDiffController.php', 449 + 'DiffusionDoorkeeperCommitFeedStoryPublisher' => 'applications/diffusion/doorkeeper/DiffusionDoorkeeperCommitFeedStoryPublisher.php', 449 450 'DiffusionEmptyResultView' => 'applications/diffusion/view/DiffusionEmptyResultView.php', 450 451 'DiffusionExpandCommitQueryException' => 'applications/diffusion/exception/DiffusionExpandCommitQueryException.php', 451 452 'DiffusionExpandShortNameQuery' => 'applications/diffusion/query/expandshortname/DiffusionExpandShortNameQuery.php', ··· 2436 2437 'DiffusionCommitTagsController' => 'DiffusionController', 2437 2438 'DiffusionController' => 'PhabricatorController', 2438 2439 'DiffusionDiffController' => 'DiffusionController', 2440 + 'DiffusionDoorkeeperCommitFeedStoryPublisher' => 'DoorkeeperFeedStoryPublisher', 2439 2441 'DiffusionEmptyResultView' => 'DiffusionView', 2440 2442 'DiffusionExpandCommitQueryException' => 'Exception', 2441 2443 'DiffusionExpandShortNameQuery' => 'DiffusionQuery',
+163
src/applications/diffusion/doorkeeper/DiffusionDoorkeeperCommitFeedStoryPublisher.php
··· 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 ($object instanceof PhabricatorRepositoryCommit); 16 + } 17 + 18 + public function willPublishStory($commit) { 19 + $requests = id(new PhabricatorAuditQuery()) 20 + ->withCommitPHIDs(array($commit->getPHID())) 21 + ->execute(); 22 + 23 + // TODO: This is messy and should be generalized, but we don't have a good 24 + // query for it yet. Since we run in the daemons, just do the easiest thing 25 + // we can for the moment. Figure out who all of the "active" (need to 26 + // audit) and "passive" (no action necessary) user are. 27 + 28 + $auditor_phids = mpull($requests, 'getAuditorPHID'); 29 + $objects = id(new PhabricatorObjectHandleData($auditor_phids)) 30 + ->setViewer($this->getViewer()) 31 + ->loadObjects(); 32 + 33 + $active = array(); 34 + $passive = array(); 35 + 36 + foreach ($requests as $request) { 37 + $status = $request->getAuditStatus(); 38 + if ($status == PhabricatorAuditStatusConstants::CC) { 39 + // We handle these specially below. 40 + continue; 41 + } 42 + 43 + $object = idx($objects, $request->getAuditorPHID()); 44 + if (!$object) { 45 + continue; 46 + } 47 + 48 + $request_phids = array(); 49 + if ($object instanceof PhabricatorUser) { 50 + $request_phids = array($object->getPHID()); 51 + } else if ($object instanceof PhabricatorOwnersPackage) { 52 + $request_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs( 53 + array($object->getID())); 54 + } else if ($object instanceof PhabricatorProject) { 55 + $request_phids = $object->loadMemberPHIDs(); 56 + } else { 57 + // Dunno what this is. 58 + $request_phids = array(); 59 + } 60 + 61 + switch ($status) { 62 + case PhabricatorAuditStatusConstants::AUDIT_REQUIRED: 63 + case PhabricatorAuditStatusConstants::AUDIT_REQUESTED: 64 + case PhabricatorAuditStatusConstants::CONCERNED: 65 + $active += array_fuse($request_phids); 66 + break; 67 + default: 68 + $passive += array_fuse($request_phids); 69 + break; 70 + } 71 + } 72 + 73 + 74 + 75 + // Remove "Active" users from the "Passive" list. 76 + $passive = array_diff_key($passive, $active); 77 + 78 + $this->activePHIDs = $active; 79 + $this->passivePHIDs = $passive; 80 + $this->auditRequests = $requests; 81 + 82 + return $commit; 83 + } 84 + 85 + public function getOwnerPHID($object) { 86 + return $object->getAuthorPHID(); 87 + } 88 + 89 + public function getActiveUserPHIDs($object) { 90 + return $this->activePHIDs; 91 + } 92 + 93 + public function getPassiveUserPHIDs($object) { 94 + return $this->passivePHIDs; 95 + } 96 + 97 + public function getCCUserPHIDs($object) { 98 + $ccs = array(); 99 + foreach ($this->getAuditRequests() as $request) { 100 + if ($request->getAuditStatus() == PhabricatorAuditStatusConstants::CC) { 101 + $ccs[] = $request->getAuditorPHID(); 102 + } 103 + } 104 + return $ccs; 105 + } 106 + 107 + public function getObjectTitle($object) { 108 + $prefix = $this->getTitlePrefix($object); 109 + 110 + $repository = $object->getRepository(); 111 + $name = $repository->formatCommitName($object->getCommitIdentifier()); 112 + 113 + $title = $object->getSummary(); 114 + 115 + return "{$prefix} {$name}: {$title}"; 116 + } 117 + 118 + public function getObjectURI($object) { 119 + $repository = $object->getRepository(); 120 + $name = $repository->formatCommitName($object->getCommitIdentifier()); 121 + return PhabricatorEnv::getProductionURI('/'.$name); 122 + } 123 + 124 + public function getObjectDescription($object) { 125 + $data = $object->loadCommitData(); 126 + if ($data) { 127 + return $data->getCommitMessage(); 128 + } 129 + return null; 130 + } 131 + 132 + public function isObjectClosed($object) { 133 + switch ($object->getAuditStatus()) { 134 + case PhabricatorAuditCommitStatusConstants::NEEDS_AUDIT: 135 + case PhabricatorAuditCommitStatusConstants::CONCERN_RAISED: 136 + case PhabricatorAuditCommitStatusConstants::PARTIALLY_AUDITED: 137 + return false; 138 + default: 139 + return true; 140 + } 141 + } 142 + 143 + public function getResponsibilityTitle($object) { 144 + $prefix = $this->getTitlePrefix($object); 145 + return pht('%s Audit', $prefix); 146 + } 147 + 148 + public function getStoryText($object) { 149 + $story = $this->getFeedStory(); 150 + if ($story instanceof PhabricatorFeedStoryAudit) { 151 + $text = $story->renderForAsanaBridge(); 152 + } else { 153 + $text = $story->renderText(); 154 + } 155 + return $text; 156 + } 157 + 158 + private function getTitlePrefix(PhabricatorRepositoryCommit $commit) { 159 + $prefix_key = 'metamta.diffusion.subject-prefix'; 160 + return PhabricatorEnv::getEnvConfig($prefix_key); 161 + } 162 + 163 + }
+27
src/applications/feed/story/PhabricatorFeedStoryAudit.php
··· 44 44 45 45 return $text; 46 46 } 47 + 48 + 49 + // TODO: At some point, make feed rendering not terrible and remove this 50 + // hacky mess. 51 + public function renderForAsanaBridge() { 52 + $data = $this->getStoryData(); 53 + $comment = $data->getValue('content'); 54 + 55 + $author_name = $this->getHandle($this->getAuthorPHID())->getName(); 56 + $action = $this->getValue('action'); 57 + $verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($action); 58 + 59 + $title = "{$author_name} {$verb} this commit."; 60 + if (strlen($comment)) { 61 + $engine = PhabricatorMarkupEngine::newMarkupEngine(array()) 62 + ->setConfig('viewer', new PhabricatorUser()) 63 + ->setMode(PhutilRemarkupEngine::MODE_TEXT); 64 + 65 + $comment = $engine->markupText($comment); 66 + 67 + $title .= "\n\n"; 68 + $title .= $comment; 69 + } 70 + 71 + return $title; 72 + } 73 + 47 74 }
+2 -1
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 2 2 3 3 final class PhabricatorRepositoryCommit 4 4 extends PhabricatorRepositoryDAO 5 - implements PhabricatorPolicyInterface, 5 + implements 6 + PhabricatorPolicyInterface, 6 7 PhabricatorTokenReceiverInterface { 7 8 8 9 protected $repositoryID;