From 611f6707204cd8bec3ba958212d21c24a472a6e5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 12 Mar 2014 11:30:33 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 5 +++ .../PhabricatorCommitBranchesField.php | 37 +++++++++++++++++++ .../PhabricatorCommitCustomField.php | 7 ++++ .../storage/PhabricatorRepositoryCommit.php | 27 +++++++++++++- ...habricatorRepositoryCommitHeraldWorker.php | 17 +++++++++ .../field/PhabricatorCustomField.php | 18 ++++++++- 6 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 src/applications/repository/customfield/PhabricatorCommitBranchesField.php create mode 100644 src/applications/repository/customfield/PhabricatorCommitCustomField.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 79e43bd443..5d83dbe2f2 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1281,6 +1281,8 @@ phutil_register_library_map(array( 'PhabricatorChatLogEvent' => 'applications/chatlog/storage/PhabricatorChatLogEvent.php', 'PhabricatorChatLogEventType' => 'applications/chatlog/constants/PhabricatorChatLogEventType.php', 'PhabricatorChatLogQuery' => 'applications/chatlog/PhabricatorChatLogQuery.php', + 'PhabricatorCommitBranchesField' => 'applications/repository/customfield/PhabricatorCommitBranchesField.php', + 'PhabricatorCommitCustomField' => 'applications/repository/customfield/PhabricatorCommitCustomField.php', 'PhabricatorCommonPasswords' => 'applications/auth/constants/PhabricatorCommonPasswords.php', 'PhabricatorConduitAPIController' => 'applications/conduit/controller/PhabricatorConduitAPIController.php', 'PhabricatorConduitCertificateToken' => 'applications/conduit/storage/PhabricatorConduitCertificateToken.php', @@ -3958,6 +3960,8 @@ phutil_register_library_map(array( ), 'PhabricatorChatLogEventType' => 'PhabricatorChatLogConstants', 'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorCommitBranchesField' => 'PhabricatorCommitCustomField', + 'PhabricatorCommitCustomField' => 'PhabricatorCustomField', 'PhabricatorCommonPasswords' => 'Phobject', 'PhabricatorConduitAPIController' => 'PhabricatorConduitController', 'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO', @@ -4668,6 +4672,7 @@ phutil_register_library_map(array( 2 => 'PhabricatorFlaggableInterface', 3 => 'PhabricatorTokenReceiverInterface', 4 => 'HarbormasterBuildableInterface', + 5 => 'PhabricatorCustomFieldInterface', ), 'PhabricatorRepositoryCommitChangeParserWorker' => 'PhabricatorRepositoryCommitParserWorker', 'PhabricatorRepositoryCommitData' => 'PhabricatorRepositoryDAO', diff --git a/src/applications/repository/customfield/PhabricatorCommitBranchesField.php b/src/applications/repository/customfield/PhabricatorCommitBranchesField.php new file mode 100644 index 0000000000..ed07a8fb29 --- /dev/null +++ b/src/applications/repository/customfield/PhabricatorCommitBranchesField.php @@ -0,0 +1,37 @@ + $this->getObject()->getCommitIdentifier(), + 'callsign' => $this->getObject()->getRepository()->getCallsign(), + ); + + $branches_raw = id(new ConduitCall('diffusion.branchquery', $params)) + ->setUser($this->getViewer()) + ->execute(); + + $branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches_raw); + if (!$branches) { + return; + } + $branch_names = mpull($branches, 'getShortName'); + sort($branch_names); + + $body->addTextSection(pht('BRANCHES'), implode(', ', $branch_names)); + } + +} diff --git a/src/applications/repository/customfield/PhabricatorCommitCustomField.php b/src/applications/repository/customfield/PhabricatorCommitCustomField.php new file mode 100644 index 0000000000..523f145054 --- /dev/null +++ b/src/applications/repository/customfield/PhabricatorCommitCustomField.php @@ -0,0 +1,7 @@ +repository = $repository; @@ -247,4 +249,27 @@ final class PhabricatorRepositoryCommit return $this->getRepository()->getPHID(); } + +/* -( PhabricatorCustomFieldInterface )------------------------------------ */ + + + public function getCustomFieldSpecificationForRole($role) { + // TODO: We could make this configurable eventually, but just use the + // defaults for now. + return array(); + } + + public function getCustomFieldBaseClass() { + return 'PhabricatorCommitCustomField'; + } + + public function getCustomFields() { + return $this->assertAttached($this->customFields); + } + + public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) { + $this->customFields = $fields; + return $this; + } + } diff --git a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php index ed0adb826c..3d86805fd8 100644 --- a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php +++ b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php @@ -24,6 +24,8 @@ final class PhabricatorRepositoryCommitHeraldWorker PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit) { + $commit->attachRepository($repository); + // Don't take any actions on an importing repository. Principally, this // avoids generating thousands of audits or emails when you import an // established repository on an existing install. @@ -155,6 +157,21 @@ final class PhabricatorRepositoryCommitHeraldWorker $body = new PhabricatorMetaMTAMailBody(); $body->addRawSection($description); $body->addTextSection(pht('DETAILS'), $commit_uri); + + // TODO: This should be integrated properly once we move to + // ApplicationTransactions. + $field_list = PhabricatorCustomField::getObjectFields( + $commit, + PhabricatorCustomField::ROLE_APPLICATIONTRANSACTIONS); + $field_list + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->readFieldsFromStorage($commit); + foreach ($field_list->getFields() as $field) { + $field->buildApplicationTransactionMailBody( + new DifferentialTransaction(), // Bogus object to satisfy typehint. + $body); + } + $body->addTextSection(pht('DIFFERENTIAL REVISION'), $differential); $body->addTextSection(pht('AFFECTED FILES'), $files); $body->addReplySection($reply_handler->getReplyHandlerInstructions()); diff --git a/src/infrastructure/customfield/field/PhabricatorCustomField.php b/src/infrastructure/customfield/field/PhabricatorCustomField.php index c2d00decdd..11a5ccc41f 100644 --- a/src/infrastructure/customfield/field/PhabricatorCustomField.php +++ b/src/infrastructure/customfield/field/PhabricatorCustomField.php @@ -1002,6 +1002,23 @@ abstract class PhabricatorCustomField { return false; } + /** + * TODO: this is only used by Diffusion right now and everything is completely + * faked since Diffusion doesn't use ApplicationTransactions yet. This should + * get fleshed out as we have more use cases. + * + * @task appxaction + */ + public function buildApplicationTransactionMailBody( + PhabricatorApplicationTransaction $xaction, + PhabricatorMetaMTAMailBody $body) { + if ($this->proxy) { + return $this->proxy->buildApplicationTransactionMailBody($xaction, $body); + } + return; + } + + /* -( Edit View )---------------------------------------------------------- */ @@ -1194,5 +1211,4 @@ abstract class PhabricatorCustomField { throw new PhabricatorCustomFieldImplementationIncompleteException($this); } - }