mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 23:40:57 +01:00
Add "Project tags added" and "Project tags removed" fields in Herald
Summary: Ref T13480. These fields don't serve a specific strong use case, but are broadly reasonable capabilities after "state" vs "change" actions were relaxed by T13283. Test Plan: Wrote rules using the new fields, added and removed projects (and did neither) to fire them / not fire them. Inspected the transcripts to see the project PHIDs making it to the field values. Maniphest Tasks: T13480 Differential Revision: https://secure.phabricator.com/D20946
This commit is contained in:
parent
6ccb6a6463
commit
6c4500046f
6 changed files with 127 additions and 18 deletions
|
@ -4382,6 +4382,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorProjectSubprojectsProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php',
|
||||
'PhabricatorProjectSubtypeDatasource' => 'applications/project/typeahead/PhabricatorProjectSubtypeDatasource.php',
|
||||
'PhabricatorProjectSubtypesConfigType' => 'applications/project/config/PhabricatorProjectSubtypesConfigType.php',
|
||||
'PhabricatorProjectTagsAddedField' => 'applications/project/herald/PhabricatorProjectTagsAddedField.php',
|
||||
'PhabricatorProjectTagsField' => 'applications/project/herald/PhabricatorProjectTagsField.php',
|
||||
'PhabricatorProjectTagsRemovedField' => 'applications/project/herald/PhabricatorProjectTagsRemovedField.php',
|
||||
'PhabricatorProjectTestDataGenerator' => 'applications/project/lipsum/PhabricatorProjectTestDataGenerator.php',
|
||||
'PhabricatorProjectTransaction' => 'applications/project/storage/PhabricatorProjectTransaction.php',
|
||||
'PhabricatorProjectTransactionEditor' => 'applications/project/editor/PhabricatorProjectTransactionEditor.php',
|
||||
|
@ -7679,7 +7682,7 @@ phutil_register_library_map(array(
|
|||
'HeraldPreCommitContentAdapter' => 'HeraldPreCommitAdapter',
|
||||
'HeraldPreCommitRefAdapter' => 'HeraldPreCommitAdapter',
|
||||
'HeraldPreventActionGroup' => 'HeraldActionGroup',
|
||||
'HeraldProjectsField' => 'HeraldField',
|
||||
'HeraldProjectsField' => 'PhabricatorProjectTagsField',
|
||||
'HeraldRecursiveConditionsException' => 'Exception',
|
||||
'HeraldRelatedFieldGroup' => 'HeraldFieldGroup',
|
||||
'HeraldRemarkupFieldValue' => 'HeraldFieldValue',
|
||||
|
@ -10943,6 +10946,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorProjectSubprojectsProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
||||
'PhabricatorProjectSubtypeDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'PhabricatorProjectSubtypesConfigType' => 'PhabricatorJSONConfigType',
|
||||
'PhabricatorProjectTagsAddedField' => 'PhabricatorProjectTagsField',
|
||||
'PhabricatorProjectTagsField' => 'HeraldField',
|
||||
'PhabricatorProjectTagsRemovedField' => 'PhabricatorProjectTagsField',
|
||||
'PhabricatorProjectTestDataGenerator' => 'PhabricatorTestDataGenerator',
|
||||
'PhabricatorProjectTransaction' => 'PhabricatorModularTransaction',
|
||||
'PhabricatorProjectTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
|
|
|
@ -241,6 +241,51 @@ abstract class HeraldField extends Phobject {
|
|||
return false;
|
||||
}
|
||||
|
||||
final protected function getAppliedTransactionsOfTypes(array $types) {
|
||||
$types = array_fuse($types);
|
||||
$xactions = $this->getAdapter()->getAppliedTransactions();
|
||||
|
||||
$result = array();
|
||||
foreach ($xactions as $key => $xaction) {
|
||||
$xaction_type = $xaction->getTransactionType();
|
||||
if (isset($types[$xaction_type])) {
|
||||
$result[$key] = $xaction;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
final protected function getAppliedEdgeTransactionOfType($edge_type) {
|
||||
$edge_xactions = $this->getAppliedTransactionsOfTypes(
|
||||
array(
|
||||
PhabricatorTransactions::TYPE_EDGE,
|
||||
));
|
||||
|
||||
$results = array();
|
||||
foreach ($edge_xactions as $edge_xaction) {
|
||||
$xaction_edge_type = $edge_xaction->getMetadataValue('edge:type');
|
||||
if ($xaction_edge_type == $edge_type) {
|
||||
$results[] = $edge_xaction;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($results) > 1) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Found more than one ("%s") applied edge transactions with given '.
|
||||
'edge type ("%s"); expected zero or one.',
|
||||
phutil_count($results),
|
||||
$edge_type));
|
||||
}
|
||||
|
||||
if ($results) {
|
||||
return head($results);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function isFieldAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class HeraldProjectsField extends HeraldField {
|
||||
final class HeraldProjectsField
|
||||
extends PhabricatorProjectTagsField {
|
||||
|
||||
const FIELDCONST = 'projects';
|
||||
|
||||
|
@ -8,26 +9,10 @@ final class HeraldProjectsField extends HeraldField {
|
|||
return pht('Project tags');
|
||||
}
|
||||
|
||||
public function getFieldGroupKey() {
|
||||
return HeraldSupportFieldGroup::FIELDGROUPKEY;
|
||||
}
|
||||
|
||||
public function supportsObject($object) {
|
||||
return ($object instanceof PhabricatorProjectInterface);
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||
$object->getPHID(),
|
||||
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardType() {
|
||||
return self::STANDARD_PHID_LIST;
|
||||
}
|
||||
|
||||
protected function getDatasource() {
|
||||
return new PhabricatorProjectDatasource();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorProjectTagsAddedField
|
||||
extends PhabricatorProjectTagsField {
|
||||
|
||||
const FIELDCONST = 'projects.added';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Project tags added');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
$xaction = $this->getProjectTagsTransaction();
|
||||
if (!$xaction) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$record = PhabricatorEdgeChangeRecord::newFromTransaction($xaction);
|
||||
|
||||
return $record->getAddedPHIDs();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
abstract class PhabricatorProjectTagsField
|
||||
extends HeraldField {
|
||||
|
||||
public function getFieldGroupKey() {
|
||||
return HeraldSupportFieldGroup::FIELDGROUPKEY;
|
||||
}
|
||||
|
||||
public function supportsObject($object) {
|
||||
return ($object instanceof PhabricatorProjectInterface);
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardType() {
|
||||
return self::STANDARD_PHID_LIST;
|
||||
}
|
||||
|
||||
protected function getDatasource() {
|
||||
return new PhabricatorProjectDatasource();
|
||||
}
|
||||
|
||||
final protected function getProjectTagsTransaction() {
|
||||
return $this->getAppliedEdgeTransactionOfType(
|
||||
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorProjectTagsRemovedField
|
||||
extends PhabricatorProjectTagsField {
|
||||
|
||||
const FIELDCONST = 'projects.removed';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Project tags removed');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
$xaction = $this->getProjectTagsTransaction();
|
||||
if (!$xaction) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$record = PhabricatorEdgeChangeRecord::newFromTransaction($xaction);
|
||||
|
||||
return $record->getRemovedPHIDs();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue