@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 CustomField to Diffusion and add a "branches" field

Summary:
Ref T4588. Request from @zeeg. Adds a "BRANCHES" field to commit emails, so the branches the commit appears on are shown.

I've implemented this with CustomField, but in a very light way.

Test Plan: Used `scripts/repository/reparse.php --herald` to generate mail, got a BRANCHES section where applicable.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: aran, epriestley, zeeg

Maniphest Tasks: T4588

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

+109 -2
+5
src/__phutil_library_map__.php
··· 1281 1281 'PhabricatorChatLogEvent' => 'applications/chatlog/storage/PhabricatorChatLogEvent.php', 1282 1282 'PhabricatorChatLogEventType' => 'applications/chatlog/constants/PhabricatorChatLogEventType.php', 1283 1283 'PhabricatorChatLogQuery' => 'applications/chatlog/PhabricatorChatLogQuery.php', 1284 + 'PhabricatorCommitBranchesField' => 'applications/repository/customfield/PhabricatorCommitBranchesField.php', 1285 + 'PhabricatorCommitCustomField' => 'applications/repository/customfield/PhabricatorCommitCustomField.php', 1284 1286 'PhabricatorCommonPasswords' => 'applications/auth/constants/PhabricatorCommonPasswords.php', 1285 1287 'PhabricatorConduitAPIController' => 'applications/conduit/controller/PhabricatorConduitAPIController.php', 1286 1288 'PhabricatorConduitCertificateToken' => 'applications/conduit/storage/PhabricatorConduitCertificateToken.php', ··· 3958 3960 ), 3959 3961 'PhabricatorChatLogEventType' => 'PhabricatorChatLogConstants', 3960 3962 'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 3963 + 'PhabricatorCommitBranchesField' => 'PhabricatorCommitCustomField', 3964 + 'PhabricatorCommitCustomField' => 'PhabricatorCustomField', 3961 3965 'PhabricatorCommonPasswords' => 'Phobject', 3962 3966 'PhabricatorConduitAPIController' => 'PhabricatorConduitController', 3963 3967 'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO', ··· 4668 4672 2 => 'PhabricatorFlaggableInterface', 4669 4673 3 => 'PhabricatorTokenReceiverInterface', 4670 4674 4 => 'HarbormasterBuildableInterface', 4675 + 5 => 'PhabricatorCustomFieldInterface', 4671 4676 ), 4672 4677 'PhabricatorRepositoryCommitChangeParserWorker' => 'PhabricatorRepositoryCommitParserWorker', 4673 4678 'PhabricatorRepositoryCommitData' => 'PhabricatorRepositoryDAO',
+37
src/applications/repository/customfield/PhabricatorCommitBranchesField.php
··· 1 + <?php 2 + 3 + final class PhabricatorCommitBranchesField 4 + extends PhabricatorCommitCustomField { 5 + 6 + public function getFieldKey() { 7 + return 'diffusion:branches'; 8 + } 9 + 10 + public function shouldAppearInApplicationTransactions() { 11 + return true; 12 + } 13 + 14 + public function buildApplicationTransactionMailBody( 15 + PhabricatorApplicationTransaction $xaction, 16 + PhabricatorMetaMTAMailBody $body) { 17 + 18 + $params = array( 19 + 'contains' => $this->getObject()->getCommitIdentifier(), 20 + 'callsign' => $this->getObject()->getRepository()->getCallsign(), 21 + ); 22 + 23 + $branches_raw = id(new ConduitCall('diffusion.branchquery', $params)) 24 + ->setUser($this->getViewer()) 25 + ->execute(); 26 + 27 + $branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches_raw); 28 + if (!$branches) { 29 + return; 30 + } 31 + $branch_names = mpull($branches, 'getShortName'); 32 + sort($branch_names); 33 + 34 + $body->addTextSection(pht('BRANCHES'), implode(', ', $branch_names)); 35 + } 36 + 37 + }
+7
src/applications/repository/customfield/PhabricatorCommitCustomField.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorCommitCustomField 4 + extends PhabricatorCustomField { 5 + 6 + 7 + }
+26 -1
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 6 6 PhabricatorPolicyInterface, 7 7 PhabricatorFlaggableInterface, 8 8 PhabricatorTokenReceiverInterface, 9 - HarbormasterBuildableInterface { 9 + HarbormasterBuildableInterface, 10 + PhabricatorCustomFieldInterface { 10 11 11 12 protected $repositoryID; 12 13 protected $phid; ··· 29 30 private $commitData = self::ATTACHABLE; 30 31 private $audits; 31 32 private $repository = self::ATTACHABLE; 33 + private $customFields = self::ATTACHABLE; 32 34 33 35 public function attachRepository(PhabricatorRepository $repository) { 34 36 $this->repository = $repository; ··· 245 247 246 248 public function getHarbormasterContainerPHID() { 247 249 return $this->getRepository()->getPHID(); 250 + } 251 + 252 + 253 + /* -( PhabricatorCustomFieldInterface )------------------------------------ */ 254 + 255 + 256 + public function getCustomFieldSpecificationForRole($role) { 257 + // TODO: We could make this configurable eventually, but just use the 258 + // defaults for now. 259 + return array(); 260 + } 261 + 262 + public function getCustomFieldBaseClass() { 263 + return 'PhabricatorCommitCustomField'; 264 + } 265 + 266 + public function getCustomFields() { 267 + return $this->assertAttached($this->customFields); 268 + } 269 + 270 + public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) { 271 + $this->customFields = $fields; 272 + return $this; 248 273 } 249 274 250 275 }
+17
src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
··· 24 24 PhabricatorRepository $repository, 25 25 PhabricatorRepositoryCommit $commit) { 26 26 27 + $commit->attachRepository($repository); 28 + 27 29 // Don't take any actions on an importing repository. Principally, this 28 30 // avoids generating thousands of audits or emails when you import an 29 31 // established repository on an existing install. ··· 155 157 $body = new PhabricatorMetaMTAMailBody(); 156 158 $body->addRawSection($description); 157 159 $body->addTextSection(pht('DETAILS'), $commit_uri); 160 + 161 + // TODO: This should be integrated properly once we move to 162 + // ApplicationTransactions. 163 + $field_list = PhabricatorCustomField::getObjectFields( 164 + $commit, 165 + PhabricatorCustomField::ROLE_APPLICATIONTRANSACTIONS); 166 + $field_list 167 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 168 + ->readFieldsFromStorage($commit); 169 + foreach ($field_list->getFields() as $field) { 170 + $field->buildApplicationTransactionMailBody( 171 + new DifferentialTransaction(), // Bogus object to satisfy typehint. 172 + $body); 173 + } 174 + 158 175 $body->addTextSection(pht('DIFFERENTIAL REVISION'), $differential); 159 176 $body->addTextSection(pht('AFFECTED FILES'), $files); 160 177 $body->addReplySection($reply_handler->getReplyHandlerInstructions());
+17 -1
src/infrastructure/customfield/field/PhabricatorCustomField.php
··· 1002 1002 return false; 1003 1003 } 1004 1004 1005 + /** 1006 + * TODO: this is only used by Diffusion right now and everything is completely 1007 + * faked since Diffusion doesn't use ApplicationTransactions yet. This should 1008 + * get fleshed out as we have more use cases. 1009 + * 1010 + * @task appxaction 1011 + */ 1012 + public function buildApplicationTransactionMailBody( 1013 + PhabricatorApplicationTransaction $xaction, 1014 + PhabricatorMetaMTAMailBody $body) { 1015 + if ($this->proxy) { 1016 + return $this->proxy->buildApplicationTransactionMailBody($xaction, $body); 1017 + } 1018 + return; 1019 + } 1020 + 1021 + 1005 1022 1006 1023 /* -( Edit View )---------------------------------------------------------- */ 1007 1024 ··· 1193 1210 } 1194 1211 throw new PhabricatorCustomFieldImplementationIncompleteException($this); 1195 1212 } 1196 - 1197 1213 1198 1214 }