1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 02:32:42 +01:00

Add Owners Package support for "Commit Hook: Content" Herald rules

Summary:
See PHI370. Support the "Affected packages" and "Affected package owners" Herald fields in pre-commit hooks.

I believe there's no technical reason these fields aren't supported and this was just overlooked.

Test Plan: Wrote a rule which makes use of the new fields, pushed commits through it. Checked transcripts and saw sensible-looking values.

Differential Revision: https://secure.phabricator.com/D19104
This commit is contained in:
epriestley 2018-02-16 04:30:48 -08:00
parent 45403b162a
commit f713e1dfc1
5 changed files with 85 additions and 1 deletions

View file

@ -812,6 +812,8 @@ phutil_register_library_map(array(
'DiffusionPreCommitContentHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentHeraldField.php',
'DiffusionPreCommitContentMergeHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentMergeHeraldField.php',
'DiffusionPreCommitContentMessageHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentMessageHeraldField.php',
'DiffusionPreCommitContentPackageHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentPackageHeraldField.php',
'DiffusionPreCommitContentPackageOwnerHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentPackageOwnerHeraldField.php',
'DiffusionPreCommitContentPusherHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentPusherHeraldField.php',
'DiffusionPreCommitContentPusherIsCommitterHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentPusherIsCommitterHeraldField.php',
'DiffusionPreCommitContentPusherProjectsHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentPusherProjectsHeraldField.php',
@ -6007,6 +6009,8 @@ phutil_register_library_map(array(
'DiffusionPreCommitContentHeraldField' => 'HeraldField',
'DiffusionPreCommitContentMergeHeraldField' => 'DiffusionPreCommitContentHeraldField',
'DiffusionPreCommitContentMessageHeraldField' => 'DiffusionPreCommitContentHeraldField',
'DiffusionPreCommitContentPackageHeraldField' => 'DiffusionPreCommitContentHeraldField',
'DiffusionPreCommitContentPackageOwnerHeraldField' => 'DiffusionPreCommitContentHeraldField',
'DiffusionPreCommitContentPusherHeraldField' => 'DiffusionPreCommitContentHeraldField',
'DiffusionPreCommitContentPusherIsCommitterHeraldField' => 'DiffusionPreCommitContentHeraldField',
'DiffusionPreCommitContentPusherProjectsHeraldField' => 'DiffusionPreCommitContentHeraldField',

View file

@ -0,0 +1,29 @@
<?php
final class DiffusionPreCommitContentPackageHeraldField
extends DiffusionPreCommitContentHeraldField {
const FIELDCONST = 'diffusion.pre.content.package';
public function getHeraldFieldName() {
return pht('Affected packages');
}
public function getFieldGroupKey() {
return HeraldRelatedFieldGroup::FIELDGROUPKEY;
}
public function getHeraldFieldValue($object) {
$packages = $this->getAdapter()->loadAffectedPackages();
return mpull($packages, 'getPHID');
}
protected function getHeraldFieldStandardType() {
return self::STANDARD_PHID_LIST;
}
protected function getDatasource() {
return new PhabricatorOwnersPackageDatasource();
}
}

View file

@ -0,0 +1,34 @@
<?php
final class DiffusionPreCommitContentPackageOwnerHeraldField
extends DiffusionPreCommitContentHeraldField {
const FIELDCONST = 'diffusion.pre.content.package.owners';
public function getHeraldFieldName() {
return pht('Affected package owners');
}
public function getFieldGroupKey() {
return HeraldRelatedFieldGroup::FIELDGROUPKEY;
}
public function getHeraldFieldValue($object) {
$packages = $this->getAdapter()->loadAffectedPackages();
if (!$packages) {
return array();
}
$owners = PhabricatorOwnersOwner::loadAllForPackages($packages);
return mpull($owners, 'getUserPHID');
}
protected function getHeraldFieldStandardType() {
return self::STANDARD_PHID_LIST;
}
protected function getDatasource() {
return new PhabricatorProjectOrUserDatasource();
}
}

View file

@ -7,6 +7,8 @@ final class HeraldPreCommitContentAdapter extends HeraldPreCommitAdapter {
private $fields;
private $revision = false;
private $affectedPackages;
public function getAdapterContentName() {
return pht('Commit Hook: Commit Content');
}
@ -223,4 +225,16 @@ final class HeraldPreCommitContentAdapter extends HeraldPreCommitAdapter {
$this->getObject()->getRefNew());
}
public function loadAffectedPackages() {
if ($this->affectedPackages === null) {
$packages = PhabricatorOwnersPackage::loadAffectedPackages(
$this->getHookEngine()->getRepository(),
$this->getDiffContent('name'));
$this->affectedPackages = $packages;
}
return $this->affectedPackages;
}
}

View file

@ -18,7 +18,9 @@ final class PhabricatorEmailFormatSettingsPanel
}
public function isManagementPanel() {
if (!$this->isUserPanel()) {
return false;
/*
if (!$this->isUserPanel()) {
return false;
}
@ -27,6 +29,7 @@ final class PhabricatorEmailFormatSettingsPanel
}
return false;
*/
}
public function isTemplatePanel() {