mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 11:30:55 +01:00
Modernize all Herald DifferentialDiff fields
Summary: Ref T8726. This deals with all the Differential diff fields, same deal as previous changes. Test Plan: - Wrote a rule with every field. - Migrated it. - Saw the same rule working. - Rigged the hell out of transcripts (diffs normally do not generate transcripts, because the only action is "block" and they don't exist yet when Herald runs). - Verified that all fields looked sensible in the transcript. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8726 Differential Revision: https://secure.phabricator.com/D13590
This commit is contained in:
parent
ae81f86a67
commit
c013108675
13 changed files with 319 additions and 68 deletions
55
resources/sql/autopatches/20150707.herald.1.sql
Normal file
55
resources/sql/autopatches/20150707.herald.1.sql
Normal file
|
@ -0,0 +1,55 @@
|
|||
UPDATE {$NAMESPACE}_herald.herald_condition c
|
||||
JOIN {$NAMESPACE}_herald.herald_rule r
|
||||
ON c.ruleID = r.id
|
||||
SET c.fieldName = 'differential.diff.affected'
|
||||
WHERE r.contentType = 'differential.diff'
|
||||
AND c.fieldName = 'diff-file';
|
||||
|
||||
UPDATE {$NAMESPACE}_herald.herald_condition c
|
||||
JOIN {$NAMESPACE}_herald.herald_rule r
|
||||
ON c.ruleID = r.id
|
||||
SET c.fieldName = 'differential.diff.author'
|
||||
WHERE r.contentType = 'differential.diff'
|
||||
AND c.fieldName = 'author';
|
||||
|
||||
UPDATE {$NAMESPACE}_herald.herald_condition c
|
||||
JOIN {$NAMESPACE}_herald.herald_rule r
|
||||
ON c.ruleID = r.id
|
||||
SET c.fieldName = 'differential.diff.author.projects'
|
||||
WHERE r.contentType = 'differential.diff'
|
||||
AND c.fieldName = 'authorprojects';
|
||||
|
||||
UPDATE {$NAMESPACE}_herald.herald_condition c
|
||||
JOIN {$NAMESPACE}_herald.herald_rule r
|
||||
ON c.ruleID = r.id
|
||||
SET c.fieldName = 'differential.diff.new'
|
||||
WHERE r.contentType = 'differential.diff'
|
||||
AND c.fieldName = 'diff-added-content';
|
||||
|
||||
UPDATE {$NAMESPACE}_herald.herald_condition c
|
||||
JOIN {$NAMESPACE}_herald.herald_rule r
|
||||
ON c.ruleID = r.id
|
||||
SET c.fieldName = 'differential.diff.content'
|
||||
WHERE r.contentType = 'differential.diff'
|
||||
AND c.fieldName = 'diff-content';
|
||||
|
||||
UPDATE {$NAMESPACE}_herald.herald_condition c
|
||||
JOIN {$NAMESPACE}_herald.herald_rule r
|
||||
ON c.ruleID = r.id
|
||||
SET c.fieldName = 'differential.diff.old'
|
||||
WHERE r.contentType = 'differential.diff'
|
||||
AND c.fieldName = 'diff-removed-content';
|
||||
|
||||
UPDATE {$NAMESPACE}_herald.herald_condition c
|
||||
JOIN {$NAMESPACE}_herald.herald_rule r
|
||||
ON c.ruleID = r.id
|
||||
SET c.fieldName = 'differential.diff.repository'
|
||||
WHERE r.contentType = 'differential.diff'
|
||||
AND c.fieldName = 'repository';
|
||||
|
||||
UPDATE {$NAMESPACE}_herald.herald_condition c
|
||||
JOIN {$NAMESPACE}_herald.herald_rule r
|
||||
ON c.ruleID = r.id
|
||||
SET c.fieldName = 'differential.diff.repository.projects'
|
||||
WHERE r.contentType = 'differential.diff'
|
||||
AND c.fieldName = 'repository-projects';
|
|
@ -350,12 +350,21 @@ phutil_register_library_map(array(
|
|||
'DifferentialDependenciesField' => 'applications/differential/customfield/DifferentialDependenciesField.php',
|
||||
'DifferentialDependsOnField' => 'applications/differential/customfield/DifferentialDependsOnField.php',
|
||||
'DifferentialDiff' => 'applications/differential/storage/DifferentialDiff.php',
|
||||
'DifferentialDiffAffectedFilesHeraldField' => 'applications/differential/herald/DifferentialDiffAffectedFilesHeraldField.php',
|
||||
'DifferentialDiffAuthorHeraldField' => 'applications/differential/herald/DifferentialDiffAuthorHeraldField.php',
|
||||
'DifferentialDiffAuthorProjectsHeraldField' => 'applications/differential/herald/DifferentialDiffAuthorProjectsHeraldField.php',
|
||||
'DifferentialDiffContentAddedHeraldField' => 'applications/differential/herald/DifferentialDiffContentAddedHeraldField.php',
|
||||
'DifferentialDiffContentHeraldField' => 'applications/differential/herald/DifferentialDiffContentHeraldField.php',
|
||||
'DifferentialDiffContentRemovedHeraldField' => 'applications/differential/herald/DifferentialDiffContentRemovedHeraldField.php',
|
||||
'DifferentialDiffCreateController' => 'applications/differential/controller/DifferentialDiffCreateController.php',
|
||||
'DifferentialDiffEditor' => 'applications/differential/editor/DifferentialDiffEditor.php',
|
||||
'DifferentialDiffHeraldField' => 'applications/differential/herald/DifferentialDiffHeraldField.php',
|
||||
'DifferentialDiffInlineCommentQuery' => 'applications/differential/query/DifferentialDiffInlineCommentQuery.php',
|
||||
'DifferentialDiffPHIDType' => 'applications/differential/phid/DifferentialDiffPHIDType.php',
|
||||
'DifferentialDiffProperty' => 'applications/differential/storage/DifferentialDiffProperty.php',
|
||||
'DifferentialDiffQuery' => 'applications/differential/query/DifferentialDiffQuery.php',
|
||||
'DifferentialDiffRepositoryHeraldField' => 'applications/differential/herald/DifferentialDiffRepositoryHeraldField.php',
|
||||
'DifferentialDiffRepositoryProjectsHeraldField' => 'applications/differential/herald/DifferentialDiffRepositoryProjectsHeraldField.php',
|
||||
'DifferentialDiffTableOfContentsView' => 'applications/differential/view/DifferentialDiffTableOfContentsView.php',
|
||||
'DifferentialDiffTestCase' => 'applications/differential/storage/__tests__/DifferentialDiffTestCase.php',
|
||||
'DifferentialDiffTransaction' => 'applications/differential/storage/DifferentialDiffTransaction.php',
|
||||
|
@ -960,8 +969,8 @@ phutil_register_library_map(array(
|
|||
'HeraldController' => 'applications/herald/controller/HeraldController.php',
|
||||
'HeraldCustomAction' => 'applications/herald/extension/HeraldCustomAction.php',
|
||||
'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php',
|
||||
'HeraldDifferentialAdapter' => 'applications/herald/adapter/HeraldDifferentialAdapter.php',
|
||||
'HeraldDifferentialDiffAdapter' => 'applications/herald/adapter/HeraldDifferentialDiffAdapter.php',
|
||||
'HeraldDifferentialAdapter' => 'applications/differential/herald/HeraldDifferentialAdapter.php',
|
||||
'HeraldDifferentialDiffAdapter' => 'applications/differential/herald/HeraldDifferentialDiffAdapter.php',
|
||||
'HeraldDifferentialRevisionAdapter' => 'applications/herald/adapter/HeraldDifferentialRevisionAdapter.php',
|
||||
'HeraldDisableController' => 'applications/herald/controller/HeraldDisableController.php',
|
||||
'HeraldEffect' => 'applications/herald/engine/HeraldEffect.php',
|
||||
|
@ -3790,12 +3799,21 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationTransactionInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
),
|
||||
'DifferentialDiffAffectedFilesHeraldField' => 'DifferentialDiffHeraldField',
|
||||
'DifferentialDiffAuthorHeraldField' => 'DifferentialDiffHeraldField',
|
||||
'DifferentialDiffAuthorProjectsHeraldField' => 'DifferentialDiffHeraldField',
|
||||
'DifferentialDiffContentAddedHeraldField' => 'DifferentialDiffHeraldField',
|
||||
'DifferentialDiffContentHeraldField' => 'DifferentialDiffHeraldField',
|
||||
'DifferentialDiffContentRemovedHeraldField' => 'DifferentialDiffHeraldField',
|
||||
'DifferentialDiffCreateController' => 'DifferentialController',
|
||||
'DifferentialDiffEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'DifferentialDiffHeraldField' => 'HeraldField',
|
||||
'DifferentialDiffInlineCommentQuery' => 'PhabricatorDiffInlineCommentQuery',
|
||||
'DifferentialDiffPHIDType' => 'PhabricatorPHIDType',
|
||||
'DifferentialDiffProperty' => 'DifferentialDAO',
|
||||
'DifferentialDiffQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'DifferentialDiffRepositoryHeraldField' => 'DifferentialDiffHeraldField',
|
||||
'DifferentialDiffRepositoryProjectsHeraldField' => 'DifferentialDiffHeraldField',
|
||||
'DifferentialDiffTableOfContentsView' => 'AphrontView',
|
||||
'DifferentialDiffTestCase' => 'PhutilTestCase',
|
||||
'DifferentialDiffTransaction' => 'PhabricatorApplicationTransaction',
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialDiffAffectedFilesHeraldField
|
||||
extends DifferentialDiffHeraldField {
|
||||
|
||||
const FIELDCONST = 'differential.diff.affected';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Affected files');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return $this->getAdapter()->loadAffectedPaths();
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardConditions() {
|
||||
return self::STANDARD_TEXT_LIST;
|
||||
}
|
||||
|
||||
public function getHeraldFieldValueType($condition) {
|
||||
switch ($condition) {
|
||||
case HeraldAdapter::CONDITION_EXISTS:
|
||||
case HeraldAdapter::CONDITION_NOT_EXISTS:
|
||||
return HeraldAdapter::VALUE_NONE;
|
||||
default:
|
||||
return HeraldAdapter::VALUE_TEXT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialDiffAuthorHeraldField
|
||||
extends DifferentialDiffHeraldField {
|
||||
|
||||
const FIELDCONST = 'differential.diff.author';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Author');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return $object->getAuthorPHID();
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardConditions() {
|
||||
return self::STANDARD_PHID;
|
||||
}
|
||||
|
||||
public function getHeraldFieldValueType($condition) {
|
||||
return HeraldAdapter::VALUE_USER;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialDiffAuthorProjectsHeraldField
|
||||
extends DifferentialDiffHeraldField {
|
||||
|
||||
const FIELDCONST = 'differential.diff.author.projects';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht("Author's projects");
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||
$object->getAuthorPHID(),
|
||||
PhabricatorProjectMemberOfProjectEdgeType::EDGECONST);
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardConditions() {
|
||||
return self::STANDARD_LIST;
|
||||
}
|
||||
|
||||
public function getHeraldFieldValueType($condition) {
|
||||
switch ($condition) {
|
||||
case HeraldAdapter::CONDITION_EXISTS:
|
||||
case HeraldAdapter::CONDITION_NOT_EXISTS:
|
||||
return HeraldAdapter::VALUE_NONE;
|
||||
default:
|
||||
return HeraldAdapter::VALUE_PROJECT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialDiffContentAddedHeraldField
|
||||
extends DifferentialDiffHeraldField {
|
||||
|
||||
const FIELDCONST = 'differential.diff.new';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Added file content');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return $this->getAdapter()->loadAddedContentDictionary();
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardConditions() {
|
||||
return self::STANDARD_TEXT_MAP;
|
||||
}
|
||||
|
||||
public function getHeraldFieldValueType($condition) {
|
||||
return HeraldAdapter::VALUE_TEXT;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialDiffContentHeraldField
|
||||
extends DifferentialDiffHeraldField {
|
||||
|
||||
const FIELDCONST = 'differential.diff.content';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Changed file content');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return $this->getAdapter()->loadContentDictionary();
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardConditions() {
|
||||
return self::STANDARD_TEXT_MAP;
|
||||
}
|
||||
|
||||
public function getHeraldFieldValueType($condition) {
|
||||
return HeraldAdapter::VALUE_TEXT;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialDiffContentRemovedHeraldField
|
||||
extends DifferentialDiffHeraldField {
|
||||
|
||||
const FIELDCONST = 'differential.diff.old';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Removed file content');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return $this->getAdapter()->loadRemovedContentDictionary();
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardConditions() {
|
||||
return self::STANDARD_TEXT_MAP;
|
||||
}
|
||||
|
||||
public function getHeraldFieldValueType($condition) {
|
||||
return HeraldAdapter::VALUE_TEXT;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
abstract class DifferentialDiffHeraldField extends HeraldField {
|
||||
|
||||
public function supportsObject($object) {
|
||||
return ($object instanceof DifferentialDiff);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialDiffRepositoryHeraldField
|
||||
extends DifferentialDiffHeraldField {
|
||||
|
||||
const FIELDCONST = 'differential.diff.repository';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Repository');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
$repository = $this->getAdapter()->loadRepository();
|
||||
|
||||
if (!$repository) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $repository->getPHID();
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardConditions() {
|
||||
return self::STANDARD_PHID_NULLABLE;
|
||||
}
|
||||
|
||||
public function getHeraldFieldValueType($condition) {
|
||||
switch ($condition) {
|
||||
case HeraldAdapter::CONDITION_EXISTS:
|
||||
case HeraldAdapter::CONDITION_NOT_EXISTS:
|
||||
return HeraldAdapter::VALUE_NONE;
|
||||
default:
|
||||
return HeraldAdapter::VALUE_REPOSITORY;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialDiffRepositoryProjectsHeraldField
|
||||
extends DifferentialDiffHeraldField {
|
||||
|
||||
const FIELDCONST = 'differential.diff.repository.projects';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Repository projects');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
$repository = $this->getAdapter()->loadRepository();
|
||||
if (!$repository) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||
$repository->getPHID(),
|
||||
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardConditions() {
|
||||
return self::STANDARD_LIST;
|
||||
}
|
||||
|
||||
public function getHeraldFieldValueType($condition) {
|
||||
switch ($condition) {
|
||||
case HeraldAdapter::CONDITION_EXISTS:
|
||||
case HeraldAdapter::CONDITION_NOT_EXISTS:
|
||||
return HeraldAdapter::VALUE_NONE;
|
||||
default:
|
||||
return HeraldAdapter::VALUE_PROJECT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -25,7 +25,6 @@ abstract class HeraldDifferentialAdapter extends HeraldAdapter {
|
|||
$repository = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withPHIDs(array($repository_phid))
|
||||
->needProjectPHIDs(true)
|
||||
->executeOne();
|
||||
} else {
|
||||
$repository = null;
|
||||
|
@ -38,7 +37,7 @@ abstract class HeraldDifferentialAdapter extends HeraldAdapter {
|
|||
}
|
||||
|
||||
|
||||
protected function loadAffectedPaths() {
|
||||
public function loadAffectedPaths() {
|
||||
$changesets = $this->loadChangesets();
|
||||
|
||||
$paths = array();
|
||||
|
@ -62,18 +61,18 @@ abstract class HeraldDifferentialAdapter extends HeraldAdapter {
|
|||
return $changeset->getAbsoluteRepositoryPath($repository, $diff);
|
||||
}
|
||||
|
||||
protected function loadContentDictionary() {
|
||||
public function loadContentDictionary() {
|
||||
$add_lines = DifferentialHunk::FLAG_LINES_ADDED;
|
||||
$rem_lines = DifferentialHunk::FLAG_LINES_REMOVED;
|
||||
$mask = ($add_lines | $rem_lines);
|
||||
return $this->loadContentWithMask($mask);
|
||||
}
|
||||
|
||||
protected function loadAddedContentDictionary() {
|
||||
public function loadAddedContentDictionary() {
|
||||
return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_ADDED);
|
||||
}
|
||||
|
||||
protected function loadRemovedContentDictionary() {
|
||||
public function loadRemovedContentDictionary() {
|
||||
return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_REMOVED);
|
||||
}
|
||||
|
|
@ -53,31 +53,12 @@ final class HeraldDifferentialDiffAdapter extends HeraldDifferentialAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
public function getFields() {
|
||||
return array_merge(
|
||||
array(
|
||||
self::FIELD_AUTHOR,
|
||||
self::FIELD_AUTHOR_PROJECTS,
|
||||
self::FIELD_REPOSITORY,
|
||||
self::FIELD_REPOSITORY_PROJECTS,
|
||||
self::FIELD_DIFF_FILE,
|
||||
self::FIELD_DIFF_CONTENT,
|
||||
self::FIELD_DIFF_ADDED_CONTENT,
|
||||
self::FIELD_DIFF_REMOVED_CONTENT,
|
||||
),
|
||||
parent::getFields());
|
||||
}
|
||||
|
||||
public function getRepetitionOptions() {
|
||||
return array(
|
||||
HeraldRepetitionPolicyConfig::FIRST,
|
||||
);
|
||||
}
|
||||
|
||||
public function getPHID() {
|
||||
return $this->getObject()->getPHID();
|
||||
}
|
||||
|
||||
public function getHeraldName() {
|
||||
return pht('New Diff');
|
||||
}
|
||||
|
@ -88,48 +69,6 @@ final class HeraldDifferentialDiffAdapter extends HeraldDifferentialAdapter {
|
|||
) + parent::getActionNameMap($rule_type);
|
||||
}
|
||||
|
||||
public function getHeraldField($field) {
|
||||
switch ($field) {
|
||||
case self::FIELD_AUTHOR:
|
||||
return $this->getObject()->getAuthorPHID();
|
||||
break;
|
||||
case self::FIELD_AUTHOR_PROJECTS:
|
||||
$author_phid = $this->getHeraldField(self::FIELD_AUTHOR);
|
||||
if (!$author_phid) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$projects = id(new PhabricatorProjectQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withMemberPHIDs(array($author_phid))
|
||||
->execute();
|
||||
|
||||
return mpull($projects, 'getPHID');
|
||||
case self::FIELD_DIFF_FILE:
|
||||
return $this->loadAffectedPaths();
|
||||
case self::FIELD_REPOSITORY:
|
||||
$repository = $this->loadRepository();
|
||||
if (!$repository) {
|
||||
return null;
|
||||
}
|
||||
return $repository->getPHID();
|
||||
case self::FIELD_REPOSITORY_PROJECTS:
|
||||
$repository = $this->loadRepository();
|
||||
if (!$repository) {
|
||||
return array();
|
||||
}
|
||||
return $repository->getProjectPHIDs();
|
||||
case self::FIELD_DIFF_CONTENT:
|
||||
return $this->loadContentDictionary();
|
||||
case self::FIELD_DIFF_ADDED_CONTENT:
|
||||
return $this->loadAddedContentDictionary();
|
||||
case self::FIELD_DIFF_REMOVED_CONTENT:
|
||||
return $this->loadRemovedContentDictionary();
|
||||
}
|
||||
|
||||
return parent::getHeraldField($field);
|
||||
}
|
||||
|
||||
public function getActions($rule_type) {
|
||||
switch ($rule_type) {
|
||||
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
Loading…
Reference in a new issue