mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 14:30:56 +01:00
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
This commit is contained in:
parent
69399dfc2a
commit
611f670720
6 changed files with 109 additions and 2 deletions
|
@ -1281,6 +1281,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorChatLogEvent' => 'applications/chatlog/storage/PhabricatorChatLogEvent.php',
|
'PhabricatorChatLogEvent' => 'applications/chatlog/storage/PhabricatorChatLogEvent.php',
|
||||||
'PhabricatorChatLogEventType' => 'applications/chatlog/constants/PhabricatorChatLogEventType.php',
|
'PhabricatorChatLogEventType' => 'applications/chatlog/constants/PhabricatorChatLogEventType.php',
|
||||||
'PhabricatorChatLogQuery' => 'applications/chatlog/PhabricatorChatLogQuery.php',
|
'PhabricatorChatLogQuery' => 'applications/chatlog/PhabricatorChatLogQuery.php',
|
||||||
|
'PhabricatorCommitBranchesField' => 'applications/repository/customfield/PhabricatorCommitBranchesField.php',
|
||||||
|
'PhabricatorCommitCustomField' => 'applications/repository/customfield/PhabricatorCommitCustomField.php',
|
||||||
'PhabricatorCommonPasswords' => 'applications/auth/constants/PhabricatorCommonPasswords.php',
|
'PhabricatorCommonPasswords' => 'applications/auth/constants/PhabricatorCommonPasswords.php',
|
||||||
'PhabricatorConduitAPIController' => 'applications/conduit/controller/PhabricatorConduitAPIController.php',
|
'PhabricatorConduitAPIController' => 'applications/conduit/controller/PhabricatorConduitAPIController.php',
|
||||||
'PhabricatorConduitCertificateToken' => 'applications/conduit/storage/PhabricatorConduitCertificateToken.php',
|
'PhabricatorConduitCertificateToken' => 'applications/conduit/storage/PhabricatorConduitCertificateToken.php',
|
||||||
|
@ -3958,6 +3960,8 @@ phutil_register_library_map(array(
|
||||||
),
|
),
|
||||||
'PhabricatorChatLogEventType' => 'PhabricatorChatLogConstants',
|
'PhabricatorChatLogEventType' => 'PhabricatorChatLogConstants',
|
||||||
'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
|
'PhabricatorCommitBranchesField' => 'PhabricatorCommitCustomField',
|
||||||
|
'PhabricatorCommitCustomField' => 'PhabricatorCustomField',
|
||||||
'PhabricatorCommonPasswords' => 'Phobject',
|
'PhabricatorCommonPasswords' => 'Phobject',
|
||||||
'PhabricatorConduitAPIController' => 'PhabricatorConduitController',
|
'PhabricatorConduitAPIController' => 'PhabricatorConduitController',
|
||||||
'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO',
|
'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO',
|
||||||
|
@ -4668,6 +4672,7 @@ phutil_register_library_map(array(
|
||||||
2 => 'PhabricatorFlaggableInterface',
|
2 => 'PhabricatorFlaggableInterface',
|
||||||
3 => 'PhabricatorTokenReceiverInterface',
|
3 => 'PhabricatorTokenReceiverInterface',
|
||||||
4 => 'HarbormasterBuildableInterface',
|
4 => 'HarbormasterBuildableInterface',
|
||||||
|
5 => 'PhabricatorCustomFieldInterface',
|
||||||
),
|
),
|
||||||
'PhabricatorRepositoryCommitChangeParserWorker' => 'PhabricatorRepositoryCommitParserWorker',
|
'PhabricatorRepositoryCommitChangeParserWorker' => 'PhabricatorRepositoryCommitParserWorker',
|
||||||
'PhabricatorRepositoryCommitData' => 'PhabricatorRepositoryDAO',
|
'PhabricatorRepositoryCommitData' => 'PhabricatorRepositoryDAO',
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorCommitBranchesField
|
||||||
|
extends PhabricatorCommitCustomField {
|
||||||
|
|
||||||
|
public function getFieldKey() {
|
||||||
|
return 'diffusion:branches';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shouldAppearInApplicationTransactions() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildApplicationTransactionMailBody(
|
||||||
|
PhabricatorApplicationTransaction $xaction,
|
||||||
|
PhabricatorMetaMTAMailBody $body) {
|
||||||
|
|
||||||
|
$params = array(
|
||||||
|
'contains' => $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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhabricatorCommitCustomField
|
||||||
|
extends PhabricatorCustomField {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -6,7 +6,8 @@ final class PhabricatorRepositoryCommit
|
||||||
PhabricatorPolicyInterface,
|
PhabricatorPolicyInterface,
|
||||||
PhabricatorFlaggableInterface,
|
PhabricatorFlaggableInterface,
|
||||||
PhabricatorTokenReceiverInterface,
|
PhabricatorTokenReceiverInterface,
|
||||||
HarbormasterBuildableInterface {
|
HarbormasterBuildableInterface,
|
||||||
|
PhabricatorCustomFieldInterface {
|
||||||
|
|
||||||
protected $repositoryID;
|
protected $repositoryID;
|
||||||
protected $phid;
|
protected $phid;
|
||||||
|
@ -29,6 +30,7 @@ final class PhabricatorRepositoryCommit
|
||||||
private $commitData = self::ATTACHABLE;
|
private $commitData = self::ATTACHABLE;
|
||||||
private $audits;
|
private $audits;
|
||||||
private $repository = self::ATTACHABLE;
|
private $repository = self::ATTACHABLE;
|
||||||
|
private $customFields = self::ATTACHABLE;
|
||||||
|
|
||||||
public function attachRepository(PhabricatorRepository $repository) {
|
public function attachRepository(PhabricatorRepository $repository) {
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
|
@ -247,4 +249,27 @@ final class PhabricatorRepositoryCommit
|
||||||
return $this->getRepository()->getPHID();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ final class PhabricatorRepositoryCommitHeraldWorker
|
||||||
PhabricatorRepository $repository,
|
PhabricatorRepository $repository,
|
||||||
PhabricatorRepositoryCommit $commit) {
|
PhabricatorRepositoryCommit $commit) {
|
||||||
|
|
||||||
|
$commit->attachRepository($repository);
|
||||||
|
|
||||||
// Don't take any actions on an importing repository. Principally, this
|
// Don't take any actions on an importing repository. Principally, this
|
||||||
// avoids generating thousands of audits or emails when you import an
|
// avoids generating thousands of audits or emails when you import an
|
||||||
// established repository on an existing install.
|
// established repository on an existing install.
|
||||||
|
@ -155,6 +157,21 @@ final class PhabricatorRepositoryCommitHeraldWorker
|
||||||
$body = new PhabricatorMetaMTAMailBody();
|
$body = new PhabricatorMetaMTAMailBody();
|
||||||
$body->addRawSection($description);
|
$body->addRawSection($description);
|
||||||
$body->addTextSection(pht('DETAILS'), $commit_uri);
|
$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('DIFFERENTIAL REVISION'), $differential);
|
||||||
$body->addTextSection(pht('AFFECTED FILES'), $files);
|
$body->addTextSection(pht('AFFECTED FILES'), $files);
|
||||||
$body->addReplySection($reply_handler->getReplyHandlerInstructions());
|
$body->addReplySection($reply_handler->getReplyHandlerInstructions());
|
||||||
|
|
|
@ -1002,6 +1002,23 @@ abstract class PhabricatorCustomField {
|
||||||
return false;
|
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 )---------------------------------------------------------- */
|
/* -( Edit View )---------------------------------------------------------- */
|
||||||
|
|
||||||
|
@ -1194,5 +1211,4 @@ abstract class PhabricatorCustomField {
|
||||||
throw new PhabricatorCustomFieldImplementationIncompleteException($this);
|
throw new PhabricatorCustomFieldImplementationIncompleteException($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue