mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Allow Herald pre-commit rules to act on repository projects
Summary: Fixes T4264. Adds: - New "Repository's projects" field to Herald pre-commit rules, so you can write global rules which act based on projects. - Allows pre-ref/pre-content rules to bind to projects, and fire for all repositories in that project, so users with limited power can write rules which apply to many repositories. - The pre-ref and pre-content classes were starting to share a fair amount of code, so I made them both extend an abstract base class. Test Plan: Wrote new pre-ref and pre-content rules bound to projects, then pushed commits into repositories in those projects and not in those projects. The "repository projects" field populated, and the rules fired for repositories in the relevant projects. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4264 Differential Revision: https://secure.phabricator.com/D7883
This commit is contained in:
parent
ee2680794f
commit
2cfc3acf32
8 changed files with 158 additions and 239 deletions
|
@ -13,6 +13,7 @@ $engine = new DiffusionCommitHookEngine();
|
||||||
$repository = id(new PhabricatorRepositoryQuery())
|
$repository = id(new PhabricatorRepositoryQuery())
|
||||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
->withCallsigns(array($argv[1]))
|
->withCallsigns(array($argv[1]))
|
||||||
|
->needProjectPHIDs(true)
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
if (!$repository) {
|
if (!$repository) {
|
||||||
|
|
|
@ -778,6 +778,7 @@ phutil_register_library_map(array(
|
||||||
'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php',
|
'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php',
|
||||||
'HeraldPHIDTypeRule' => 'applications/herald/phid/HeraldPHIDTypeRule.php',
|
'HeraldPHIDTypeRule' => 'applications/herald/phid/HeraldPHIDTypeRule.php',
|
||||||
'HeraldPholioMockAdapter' => 'applications/herald/adapter/HeraldPholioMockAdapter.php',
|
'HeraldPholioMockAdapter' => 'applications/herald/adapter/HeraldPholioMockAdapter.php',
|
||||||
|
'HeraldPreCommitAdapter' => 'applications/diffusion/herald/HeraldPreCommitAdapter.php',
|
||||||
'HeraldPreCommitContentAdapter' => 'applications/diffusion/herald/HeraldPreCommitContentAdapter.php',
|
'HeraldPreCommitContentAdapter' => 'applications/diffusion/herald/HeraldPreCommitContentAdapter.php',
|
||||||
'HeraldPreCommitRefAdapter' => 'applications/diffusion/herald/HeraldPreCommitRefAdapter.php',
|
'HeraldPreCommitRefAdapter' => 'applications/diffusion/herald/HeraldPreCommitRefAdapter.php',
|
||||||
'HeraldRecursiveConditionsException' => 'applications/herald/engine/exception/HeraldRecursiveConditionsException.php',
|
'HeraldRecursiveConditionsException' => 'applications/herald/engine/exception/HeraldRecursiveConditionsException.php',
|
||||||
|
@ -3251,8 +3252,9 @@ phutil_register_library_map(array(
|
||||||
'HeraldNewController' => 'HeraldController',
|
'HeraldNewController' => 'HeraldController',
|
||||||
'HeraldPHIDTypeRule' => 'PhabricatorPHIDType',
|
'HeraldPHIDTypeRule' => 'PhabricatorPHIDType',
|
||||||
'HeraldPholioMockAdapter' => 'HeraldAdapter',
|
'HeraldPholioMockAdapter' => 'HeraldAdapter',
|
||||||
'HeraldPreCommitContentAdapter' => 'HeraldAdapter',
|
'HeraldPreCommitAdapter' => 'HeraldAdapter',
|
||||||
'HeraldPreCommitRefAdapter' => 'HeraldAdapter',
|
'HeraldPreCommitContentAdapter' => 'HeraldPreCommitAdapter',
|
||||||
|
'HeraldPreCommitRefAdapter' => 'HeraldPreCommitAdapter',
|
||||||
'HeraldRecursiveConditionsException' => 'Exception',
|
'HeraldRecursiveConditionsException' => 'Exception',
|
||||||
'HeraldRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
'HeraldRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
||||||
'HeraldRule' =>
|
'HeraldRule' =>
|
||||||
|
|
113
src/applications/diffusion/herald/HeraldPreCommitAdapter.php
Normal file
113
src/applications/diffusion/herald/HeraldPreCommitAdapter.php
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class HeraldPreCommitAdapter extends HeraldAdapter {
|
||||||
|
|
||||||
|
private $log;
|
||||||
|
private $hookEngine;
|
||||||
|
|
||||||
|
public function setPushLog(PhabricatorRepositoryPushLog $log) {
|
||||||
|
$this->log = $log;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHookEngine(DiffusionCommitHookEngine $engine) {
|
||||||
|
$this->hookEngine = $engine;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHookEngine() {
|
||||||
|
return $this->hookEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdapterApplicationClass() {
|
||||||
|
return 'PhabricatorApplicationDiffusion';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getObject() {
|
||||||
|
return $this->log;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsRuleType($rule_type) {
|
||||||
|
switch ($rule_type) {
|
||||||
|
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
||||||
|
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
||||||
|
return true;
|
||||||
|
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canTriggerOnObject($object) {
|
||||||
|
if ($object instanceof PhabricatorRepository) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($object instanceof PhabricatorProject) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function explainValidTriggerObjects() {
|
||||||
|
return pht(
|
||||||
|
'This rule can trigger for **repositories** or **projects**.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTriggerObjectPHIDs() {
|
||||||
|
return array_merge(
|
||||||
|
array(
|
||||||
|
$this->hookEngine->getRepository()->getPHID(),
|
||||||
|
$this->getPHID(),
|
||||||
|
),
|
||||||
|
$this->hookEngine->getRepository()->getProjectPHIDs());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActions($rule_type) {
|
||||||
|
switch ($rule_type) {
|
||||||
|
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
||||||
|
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
||||||
|
return array(
|
||||||
|
self::ACTION_BLOCK,
|
||||||
|
self::ACTION_NOTHING
|
||||||
|
);
|
||||||
|
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
||||||
|
return array(
|
||||||
|
self::ACTION_NOTHING,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPHID() {
|
||||||
|
return $this->getObject()->getPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyHeraldEffects(array $effects) {
|
||||||
|
assert_instances_of($effects, 'HeraldEffect');
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
foreach ($effects as $effect) {
|
||||||
|
$action = $effect->getAction();
|
||||||
|
switch ($action) {
|
||||||
|
case self::ACTION_NOTHING:
|
||||||
|
$result[] = new HeraldApplyTranscript(
|
||||||
|
$effect,
|
||||||
|
true,
|
||||||
|
pht('Did nothing.'));
|
||||||
|
break;
|
||||||
|
case self::ACTION_BLOCK:
|
||||||
|
$result[] = new HeraldApplyTranscript(
|
||||||
|
$effect,
|
||||||
|
true,
|
||||||
|
pht('Blocked push.'));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception(pht('No rules to handle action "%s"!', $action));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,32 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
final class HeraldPreCommitContentAdapter extends HeraldPreCommitAdapter {
|
||||||
|
|
||||||
private $log;
|
|
||||||
private $hookEngine;
|
|
||||||
private $changesets;
|
private $changesets;
|
||||||
private $commitRef;
|
private $commitRef;
|
||||||
private $fields;
|
private $fields;
|
||||||
private $revision = false;
|
private $revision = false;
|
||||||
|
|
||||||
public function setPushLog(PhabricatorRepositoryPushLog $log) {
|
|
||||||
$this->log = $log;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHookEngine(DiffusionCommitHookEngine $engine) {
|
|
||||||
$this->hookEngine = $engine;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAdapterApplicationClass() {
|
|
||||||
return 'PhabricatorApplicationDiffusion';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getObject() {
|
|
||||||
return $this->log;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAdapterContentName() {
|
public function getAdapterContentName() {
|
||||||
return pht('Commit Hook: Commit Content');
|
return pht('Commit Hook: Commit Content');
|
||||||
}
|
}
|
||||||
|
@ -41,41 +21,6 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
"Hook rules can block changes.");
|
"Hook rules can block changes.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsRuleType($rule_type) {
|
|
||||||
switch ($rule_type) {
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
|
||||||
return true;
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function canTriggerOnObject($object) {
|
|
||||||
if ($object instanceof PhabricatorRepository) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function explainValidTriggerObjects() {
|
|
||||||
return pht(
|
|
||||||
'This rule can trigger for **repositories**.');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTriggerObjectPHIDs() {
|
|
||||||
return array(
|
|
||||||
$this->hookEngine->getRepository()->getPHID(),
|
|
||||||
$this->getPHID(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFieldNameMap() {
|
|
||||||
return array(
|
|
||||||
) + parent::getFieldNameMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFields() {
|
public function getFields() {
|
||||||
return array_merge(
|
return array_merge(
|
||||||
array(
|
array(
|
||||||
|
@ -90,6 +35,7 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
self::FIELD_DIFF_ADDED_CONTENT,
|
self::FIELD_DIFF_ADDED_CONTENT,
|
||||||
self::FIELD_DIFF_REMOVED_CONTENT,
|
self::FIELD_DIFF_REMOVED_CONTENT,
|
||||||
self::FIELD_REPOSITORY,
|
self::FIELD_REPOSITORY,
|
||||||
|
self::FIELD_REPOSITORY_PROJECTS,
|
||||||
self::FIELD_PUSHER,
|
self::FIELD_PUSHER,
|
||||||
self::FIELD_PUSHER_PROJECTS,
|
self::FIELD_PUSHER_PROJECTS,
|
||||||
self::FIELD_DIFFERENTIAL_REVISION,
|
self::FIELD_DIFFERENTIAL_REVISION,
|
||||||
|
@ -102,37 +48,8 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
parent::getFields());
|
parent::getFields());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConditionsForField($field) {
|
|
||||||
switch ($field) {
|
|
||||||
}
|
|
||||||
return parent::getConditionsForField($field);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getActions($rule_type) {
|
|
||||||
switch ($rule_type) {
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
|
||||||
return array(
|
|
||||||
self::ACTION_BLOCK,
|
|
||||||
self::ACTION_NOTHING
|
|
||||||
);
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
|
||||||
return array(
|
|
||||||
self::ACTION_NOTHING,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getValueTypeForFieldAndCondition($field, $condition) {
|
|
||||||
return parent::getValueTypeForFieldAndCondition($field, $condition);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPHID() {
|
|
||||||
return $this->getObject()->getPHID();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHeraldName() {
|
public function getHeraldName() {
|
||||||
return pht('Push Log');
|
return pht('Push Log (Content)');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHeraldField($field) {
|
public function getHeraldField($field) {
|
||||||
|
@ -159,11 +76,13 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
case self::FIELD_DIFF_REMOVED_CONTENT:
|
case self::FIELD_DIFF_REMOVED_CONTENT:
|
||||||
return $this->getDiffContent('-');
|
return $this->getDiffContent('-');
|
||||||
case self::FIELD_REPOSITORY:
|
case self::FIELD_REPOSITORY:
|
||||||
return $this->hookEngine->getRepository()->getPHID();
|
return $this->getHookEngine()->getRepository()->getPHID();
|
||||||
|
case self::FIELD_REPOSITORY_PROJECTS:
|
||||||
|
return $this->getHookEngine()->getRepository()->getProjectPHIDs();
|
||||||
case self::FIELD_PUSHER:
|
case self::FIELD_PUSHER:
|
||||||
return $this->hookEngine->getViewer()->getPHID();
|
return $this->getHookEngine()->getViewer()->getPHID();
|
||||||
case self::FIELD_PUSHER_PROJECTS:
|
case self::FIELD_PUSHER_PROJECTS:
|
||||||
return $this->hookEngine->loadViewerProjectPHIDsForHerald();
|
return $this->getHookEngine()->loadViewerProjectPHIDsForHerald();
|
||||||
case self::FIELD_DIFFERENTIAL_REVISION:
|
case self::FIELD_DIFFERENTIAL_REVISION:
|
||||||
$revision = $this->getRevision();
|
$revision = $this->getRevision();
|
||||||
if (!$revision) {
|
if (!$revision) {
|
||||||
|
@ -199,38 +118,11 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
return parent::getHeraldField($field);
|
return parent::getHeraldField($field);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyHeraldEffects(array $effects) {
|
|
||||||
assert_instances_of($effects, 'HeraldEffect');
|
|
||||||
|
|
||||||
$result = array();
|
|
||||||
foreach ($effects as $effect) {
|
|
||||||
$action = $effect->getAction();
|
|
||||||
switch ($action) {
|
|
||||||
case self::ACTION_NOTHING:
|
|
||||||
$result[] = new HeraldApplyTranscript(
|
|
||||||
$effect,
|
|
||||||
true,
|
|
||||||
pht('Did nothing.'));
|
|
||||||
break;
|
|
||||||
case self::ACTION_BLOCK:
|
|
||||||
$result[] = new HeraldApplyTranscript(
|
|
||||||
$effect,
|
|
||||||
true,
|
|
||||||
pht('Blocked push.'));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Exception(pht('No rules to handle action "%s"!', $action));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getDiffContent($type) {
|
private function getDiffContent($type) {
|
||||||
if ($this->changesets === null) {
|
if ($this->changesets === null) {
|
||||||
try {
|
try {
|
||||||
$this->changesets = $this->hookEngine->loadChangesetsForCommit(
|
$this->changesets = $this->getHookEngine()->loadChangesetsForCommit(
|
||||||
$this->log->getRefNew());
|
$this->getObject()->getRefNew());
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
$this->changesets = $ex;
|
$this->changesets = $ex;
|
||||||
}
|
}
|
||||||
|
@ -277,14 +169,14 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
|
|
||||||
private function getCommitRef() {
|
private function getCommitRef() {
|
||||||
if ($this->commitRef === null) {
|
if ($this->commitRef === null) {
|
||||||
$this->commitRef = $this->hookEngine->loadCommitRefForCommit(
|
$this->commitRef = $this->getHookEngine()->loadCommitRefForCommit(
|
||||||
$this->log->getRefNew());
|
$this->getObject()->getRefNew());
|
||||||
}
|
}
|
||||||
return $this->commitRef;
|
return $this->commitRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAuthorPHID() {
|
private function getAuthorPHID() {
|
||||||
$repository = $this->hookEngine->getRepository();
|
$repository = $this->getHookEngine()->getRepository();
|
||||||
$vcs = $repository->getVersionControlSystem();
|
$vcs = $repository->getVersionControlSystem();
|
||||||
switch ($vcs) {
|
switch ($vcs) {
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||||
|
@ -297,12 +189,12 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
return $this->lookupUser($author);
|
return $this->lookupUser($author);
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
||||||
// In Subversion, the pusher is always the author.
|
// In Subversion, the pusher is always the author.
|
||||||
return $this->hookEngine->getViewer()->getPHID();
|
return $this->getHookEngine()->getViewer()->getPHID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCommitterPHID() {
|
private function getCommitterPHID() {
|
||||||
$repository = $this->hookEngine->getRepository();
|
$repository = $this->getHookEngine()->getRepository();
|
||||||
$vcs = $repository->getVersionControlSystem();
|
$vcs = $repository->getVersionControlSystem();
|
||||||
switch ($vcs) {
|
switch ($vcs) {
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||||
|
@ -321,12 +213,12 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
return $phid;
|
return $phid;
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
||||||
// In Subversion, the pusher is always the committer.
|
// In Subversion, the pusher is always the committer.
|
||||||
return $this->hookEngine->getViewer()->getPHID();
|
return $this->getHookEngine()->getViewer()->getPHID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAuthorRaw() {
|
private function getAuthorRaw() {
|
||||||
$repository = $this->hookEngine->getRepository();
|
$repository = $this->getHookEngine()->getRepository();
|
||||||
$vcs = $repository->getVersionControlSystem();
|
$vcs = $repository->getVersionControlSystem();
|
||||||
switch ($vcs) {
|
switch ($vcs) {
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||||
|
@ -335,12 +227,12 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
return $ref->getAuthor();
|
return $ref->getAuthor();
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
||||||
// In Subversion, the pusher is always the author.
|
// In Subversion, the pusher is always the author.
|
||||||
return $this->hookEngine->getViewer()->getUsername();
|
return $this->getHookEngine()->getViewer()->getUsername();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCommitterRaw() {
|
private function getCommitterRaw() {
|
||||||
$repository = $this->hookEngine->getRepository();
|
$repository = $this->getHookEngine()->getRepository();
|
||||||
$vcs = $repository->getVersionControlSystem();
|
$vcs = $repository->getVersionControlSystem();
|
||||||
switch ($vcs) {
|
switch ($vcs) {
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||||
|
@ -355,7 +247,7 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
return $ref->getAuthor();
|
return $ref->getAuthor();
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
||||||
// In Subversion, the pusher is always the committer.
|
// In Subversion, the pusher is always the committer.
|
||||||
return $this->hookEngine->getViewer()->getUsername();
|
return $this->getHookEngine()->getViewer()->getUsername();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +260,7 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
private function getCommitFields() {
|
private function getCommitFields() {
|
||||||
if ($this->fields === null) {
|
if ($this->fields === null) {
|
||||||
$this->fields = id(new DiffusionLowLevelCommitFieldsQuery())
|
$this->fields = id(new DiffusionLowLevelCommitFieldsQuery())
|
||||||
->setRepository($this->hookEngine->getRepository())
|
->setRepository($this->getHookEngine()->getRepository())
|
||||||
->withCommitRef($this->getCommitRef())
|
->withCommitRef($this->getCommitRef())
|
||||||
->execute();
|
->execute();
|
||||||
}
|
}
|
||||||
|
@ -394,14 +286,14 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getIsMergeCommit() {
|
private function getIsMergeCommit() {
|
||||||
$repository = $this->hookEngine->getRepository();
|
$repository = $this->getHookEngine()->getRepository();
|
||||||
$vcs = $repository->getVersionControlSystem();
|
$vcs = $repository->getVersionControlSystem();
|
||||||
switch ($vcs) {
|
switch ($vcs) {
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
||||||
$parents = id(new DiffusionLowLevelParentsQuery())
|
$parents = id(new DiffusionLowLevelParentsQuery())
|
||||||
->setRepository($repository)
|
->setRepository($repository)
|
||||||
->withIdentifier($this->log->getRefNew())
|
->withIdentifier($this->getObject()->getRefNew())
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
return (count($parents) > 1);
|
return (count($parents) > 1);
|
||||||
|
@ -414,7 +306,8 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBranches() {
|
private function getBranches() {
|
||||||
return $this->hookEngine->loadBranches($this->log->getRefNew());
|
return $this->getHookEngine()->loadBranches(
|
||||||
|
$this->getObject()->getRefNew());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class HeraldPreCommitRefAdapter extends HeraldAdapter {
|
final class HeraldPreCommitRefAdapter extends HeraldPreCommitAdapter {
|
||||||
|
|
||||||
private $log;
|
|
||||||
private $hookEngine;
|
|
||||||
|
|
||||||
const FIELD_REF_TYPE = 'ref-type';
|
const FIELD_REF_TYPE = 'ref-type';
|
||||||
const FIELD_REF_NAME = 'ref-name';
|
const FIELD_REF_NAME = 'ref-name';
|
||||||
|
@ -12,24 +9,6 @@ final class HeraldPreCommitRefAdapter extends HeraldAdapter {
|
||||||
const VALUE_REF_TYPE = 'value-ref-type';
|
const VALUE_REF_TYPE = 'value-ref-type';
|
||||||
const VALUE_REF_CHANGE = 'value-ref-change';
|
const VALUE_REF_CHANGE = 'value-ref-change';
|
||||||
|
|
||||||
public function setPushLog(PhabricatorRepositoryPushLog $log) {
|
|
||||||
$this->log = $log;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHookEngine(DiffusionCommitHookEngine $engine) {
|
|
||||||
$this->hookEngine = $engine;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAdapterApplicationClass() {
|
|
||||||
return 'PhabricatorApplicationDiffusion';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getObject() {
|
|
||||||
return $this->log;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAdapterContentName() {
|
public function getAdapterContentName() {
|
||||||
return pht('Commit Hook: Branches/Tags/Bookmarks');
|
return pht('Commit Hook: Branches/Tags/Bookmarks');
|
||||||
}
|
}
|
||||||
|
@ -44,36 +23,6 @@ final class HeraldPreCommitRefAdapter extends HeraldAdapter {
|
||||||
"Hook rules can block changes.");
|
"Hook rules can block changes.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsRuleType($rule_type) {
|
|
||||||
switch ($rule_type) {
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
|
||||||
return true;
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function canTriggerOnObject($object) {
|
|
||||||
if ($object instanceof PhabricatorRepository) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function explainValidTriggerObjects() {
|
|
||||||
return pht(
|
|
||||||
'This rule can trigger for **repositories**.');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTriggerObjectPHIDs() {
|
|
||||||
return array(
|
|
||||||
$this->hookEngine->getRepository()->getPHID(),
|
|
||||||
$this->getPHID(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFieldNameMap() {
|
public function getFieldNameMap() {
|
||||||
return array(
|
return array(
|
||||||
self::FIELD_REF_TYPE => pht('Ref type'),
|
self::FIELD_REF_TYPE => pht('Ref type'),
|
||||||
|
@ -89,6 +38,7 @@ final class HeraldPreCommitRefAdapter extends HeraldAdapter {
|
||||||
self::FIELD_REF_NAME,
|
self::FIELD_REF_NAME,
|
||||||
self::FIELD_REF_CHANGE,
|
self::FIELD_REF_CHANGE,
|
||||||
self::FIELD_REPOSITORY,
|
self::FIELD_REPOSITORY,
|
||||||
|
self::FIELD_REPOSITORY_PROJECTS,
|
||||||
self::FIELD_PUSHER,
|
self::FIELD_PUSHER,
|
||||||
self::FIELD_PUSHER_PROJECTS,
|
self::FIELD_PUSHER_PROJECTS,
|
||||||
self::FIELD_RULE,
|
self::FIELD_RULE,
|
||||||
|
@ -119,21 +69,6 @@ final class HeraldPreCommitRefAdapter extends HeraldAdapter {
|
||||||
return parent::getConditionsForField($field);
|
return parent::getConditionsForField($field);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getActions($rule_type) {
|
|
||||||
switch ($rule_type) {
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
|
||||||
return array(
|
|
||||||
self::ACTION_BLOCK,
|
|
||||||
self::ACTION_NOTHING
|
|
||||||
);
|
|
||||||
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
|
||||||
return array(
|
|
||||||
self::ACTION_NOTHING,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getValueTypeForFieldAndCondition($field, $condition) {
|
public function getValueTypeForFieldAndCondition($field, $condition) {
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case self::FIELD_REF_TYPE:
|
case self::FIELD_REF_TYPE:
|
||||||
|
@ -145,12 +80,8 @@ final class HeraldPreCommitRefAdapter extends HeraldAdapter {
|
||||||
return parent::getValueTypeForFieldAndCondition($field, $condition);
|
return parent::getValueTypeForFieldAndCondition($field, $condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPHID() {
|
|
||||||
return $this->getObject()->getPHID();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHeraldName() {
|
public function getHeraldName() {
|
||||||
return pht('Push Log');
|
return pht('Push Log (Ref)');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHeraldField($field) {
|
public function getHeraldField($field) {
|
||||||
|
@ -163,42 +94,16 @@ final class HeraldPreCommitRefAdapter extends HeraldAdapter {
|
||||||
case self::FIELD_REF_CHANGE:
|
case self::FIELD_REF_CHANGE:
|
||||||
return $log->getChangeFlags();
|
return $log->getChangeFlags();
|
||||||
case self::FIELD_REPOSITORY:
|
case self::FIELD_REPOSITORY:
|
||||||
return $this->hookEngine->getRepository()->getPHID();
|
return $this->getHookEngine()->getRepository()->getPHID();
|
||||||
|
case self::FIELD_REPOSITORY_PROJECTS:
|
||||||
|
return $this->getHookEngine()->getRepository()->getProjectPHIDs();
|
||||||
case self::FIELD_PUSHER:
|
case self::FIELD_PUSHER:
|
||||||
return $this->hookEngine->getViewer()->getPHID();
|
return $this->getHookEngine()->getViewer()->getPHID();
|
||||||
case self::FIELD_PUSHER_PROJECTS:
|
case self::FIELD_PUSHER_PROJECTS:
|
||||||
return $this->hookEngine->loadViewerProjectPHIDsForHerald();
|
return $this->getHookEngine()->loadViewerProjectPHIDsForHerald();
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getHeraldField($field);
|
return parent::getHeraldField($field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function applyHeraldEffects(array $effects) {
|
|
||||||
assert_instances_of($effects, 'HeraldEffect');
|
|
||||||
|
|
||||||
$result = array();
|
|
||||||
foreach ($effects as $effect) {
|
|
||||||
$action = $effect->getAction();
|
|
||||||
switch ($action) {
|
|
||||||
case self::ACTION_NOTHING:
|
|
||||||
$result[] = new HeraldApplyTranscript(
|
|
||||||
$effect,
|
|
||||||
true,
|
|
||||||
pht('Did nothing.'));
|
|
||||||
break;
|
|
||||||
case self::ACTION_BLOCK:
|
|
||||||
$result[] = new HeraldApplyTranscript(
|
|
||||||
$effect,
|
|
||||||
true,
|
|
||||||
pht('Blocked push.'));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Exception(pht('No rules to handle action "%s"!', $action));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ abstract class HeraldAdapter {
|
||||||
const FIELD_DIFF_ADDED_CONTENT = 'diff-added-content';
|
const FIELD_DIFF_ADDED_CONTENT = 'diff-added-content';
|
||||||
const FIELD_DIFF_REMOVED_CONTENT = 'diff-removed-content';
|
const FIELD_DIFF_REMOVED_CONTENT = 'diff-removed-content';
|
||||||
const FIELD_REPOSITORY = 'repository';
|
const FIELD_REPOSITORY = 'repository';
|
||||||
|
const FIELD_REPOSITORY_PROJECTS = 'repository-projects';
|
||||||
const FIELD_RULE = 'rule';
|
const FIELD_RULE = 'rule';
|
||||||
const FIELD_AFFECTED_PACKAGE = 'affected-package';
|
const FIELD_AFFECTED_PACKAGE = 'affected-package';
|
||||||
const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner';
|
const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner';
|
||||||
|
@ -193,6 +194,7 @@ abstract class HeraldAdapter {
|
||||||
self::FIELD_DIFF_ADDED_CONTENT => pht('Any added file content'),
|
self::FIELD_DIFF_ADDED_CONTENT => pht('Any added file content'),
|
||||||
self::FIELD_DIFF_REMOVED_CONTENT => pht('Any removed file content'),
|
self::FIELD_DIFF_REMOVED_CONTENT => pht('Any removed file content'),
|
||||||
self::FIELD_REPOSITORY => pht('Repository'),
|
self::FIELD_REPOSITORY => pht('Repository'),
|
||||||
|
self::FIELD_REPOSITORY_PROJECTS => pht('Repository\'s projects'),
|
||||||
self::FIELD_RULE => pht('Another Herald rule'),
|
self::FIELD_RULE => pht('Another Herald rule'),
|
||||||
self::FIELD_AFFECTED_PACKAGE => pht('Any affected package'),
|
self::FIELD_AFFECTED_PACKAGE => pht('Any affected package'),
|
||||||
self::FIELD_AFFECTED_PACKAGE_OWNER =>
|
self::FIELD_AFFECTED_PACKAGE_OWNER =>
|
||||||
|
@ -283,6 +285,7 @@ abstract class HeraldAdapter {
|
||||||
case self::FIELD_AFFECTED_PACKAGE:
|
case self::FIELD_AFFECTED_PACKAGE:
|
||||||
case self::FIELD_AFFECTED_PACKAGE_OWNER:
|
case self::FIELD_AFFECTED_PACKAGE_OWNER:
|
||||||
case self::FIELD_PUSHER_PROJECTS:
|
case self::FIELD_PUSHER_PROJECTS:
|
||||||
|
case self::FIELD_REPOSITORY_PROJECTS:
|
||||||
return array(
|
return array(
|
||||||
self::CONDITION_INCLUDE_ALL,
|
self::CONDITION_INCLUDE_ALL,
|
||||||
self::CONDITION_INCLUDE_ANY,
|
self::CONDITION_INCLUDE_ANY,
|
||||||
|
@ -713,6 +716,7 @@ abstract class HeraldAdapter {
|
||||||
case self::FIELD_AUTHOR_PROJECTS:
|
case self::FIELD_AUTHOR_PROJECTS:
|
||||||
case self::FIELD_PUSHER_PROJECTS:
|
case self::FIELD_PUSHER_PROJECTS:
|
||||||
case self::FIELD_PROJECTS:
|
case self::FIELD_PROJECTS:
|
||||||
|
case self::FIELD_REPOSITORY_PROJECTS:
|
||||||
return self::VALUE_PROJECT;
|
return self::VALUE_PROJECT;
|
||||||
case self::FIELD_REVIEWERS:
|
case self::FIELD_REVIEWERS:
|
||||||
return self::VALUE_USER_OR_PROJECT;
|
return self::VALUE_USER_OR_PROJECT;
|
||||||
|
|
|
@ -172,7 +172,8 @@ final class HeraldNewController extends HeraldController {
|
||||||
->appendRemarkupInstructions(
|
->appendRemarkupInstructions(
|
||||||
pht(
|
pht(
|
||||||
'Choose the object this rule will act on (for example, enter '.
|
'Choose the object this rule will act on (for example, enter '.
|
||||||
'`rX` to act on the `rX` repository).'))
|
'`rX` to act on the `rX` repository, or `#project` to act on '.
|
||||||
|
'a project).'))
|
||||||
->appendRemarkupInstructions(
|
->appendRemarkupInstructions(
|
||||||
$adapter->explainValidTriggerObjects())
|
$adapter->explainValidTriggerObjects())
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
|
|
@ -17,7 +17,7 @@ final class HeraldRule extends HeraldDAO
|
||||||
protected $isDisabled = 0;
|
protected $isDisabled = 0;
|
||||||
protected $triggerObjectPHID;
|
protected $triggerObjectPHID;
|
||||||
|
|
||||||
protected $configVersion = 23;
|
protected $configVersion = 24;
|
||||||
|
|
||||||
// phids for which this rule has been applied
|
// phids for which this rule has been applied
|
||||||
private $ruleApplied = self::ATTACHABLE;
|
private $ruleApplied = self::ATTACHABLE;
|
||||||
|
|
Loading…
Reference in a new issue