1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 17:30:59 +01:00

Herald - add field + condition for Diffusion Commits for "On autoclose branch"

Summary:
Fixes T1461.

Adds

- FIELD_ALWAYS - now you could add this to a content type to always get notified
- FIELD_REPOSITORY_AUTOCLOSE_BRANCH - solves T1461
- CONDITION_UNCONDITIONALLY - used by these two fields to not show any value for the user to select

Test Plan: made a herald rule where diffs on autoclose branches would get flagged blue. made a diff on an autoclose branch and committed it. commit was flagged!

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Maniphest Tasks: T1461

Differential Revision: https://secure.phabricator.com/D7210
This commit is contained in:
Bob Trahan 2013-10-03 17:53:12 -07:00
parent 5200145b21
commit 3cf17cc67f
7 changed files with 113 additions and 66 deletions

View file

@ -20,24 +20,26 @@ abstract class HeraldAdapter {
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';
const FIELD_CONTENT_SOURCE = 'contentsource'; const FIELD_CONTENT_SOURCE = 'contentsource';
const FIELD_ALWAYS = 'always';
const CONDITION_CONTAINS = 'contains'; const CONDITION_CONTAINS = 'contains';
const CONDITION_NOT_CONTAINS = '!contains'; const CONDITION_NOT_CONTAINS = '!contains';
const CONDITION_IS = 'is'; const CONDITION_IS = 'is';
const CONDITION_IS_NOT = '!is'; const CONDITION_IS_NOT = '!is';
const CONDITION_IS_ANY = 'isany'; const CONDITION_IS_ANY = 'isany';
const CONDITION_IS_NOT_ANY = '!isany'; const CONDITION_IS_NOT_ANY = '!isany';
const CONDITION_INCLUDE_ALL = 'all'; const CONDITION_INCLUDE_ALL = 'all';
const CONDITION_INCLUDE_ANY = 'any'; const CONDITION_INCLUDE_ANY = 'any';
const CONDITION_INCLUDE_NONE = 'none'; const CONDITION_INCLUDE_NONE = 'none';
const CONDITION_IS_ME = 'me'; const CONDITION_IS_ME = 'me';
const CONDITION_IS_NOT_ME = '!me'; const CONDITION_IS_NOT_ME = '!me';
const CONDITION_REGEXP = 'regexp'; const CONDITION_REGEXP = 'regexp';
const CONDITION_RULE = 'conditions'; const CONDITION_RULE = 'conditions';
const CONDITION_NOT_RULE = '!conditions'; const CONDITION_NOT_RULE = '!conditions';
const CONDITION_EXISTS = 'exists'; const CONDITION_EXISTS = 'exists';
const CONDITION_NOT_EXISTS = '!exists'; const CONDITION_NOT_EXISTS = '!exists';
const CONDITION_REGEXP_PAIR = 'regexp-pair'; const CONDITION_UNCONDITIONALLY = 'unconditionally';
const CONDITION_REGEXP_PAIR = 'regexp-pair';
const ACTION_ADD_CC = 'addcc'; const ACTION_ADD_CC = 'addcc';
const ACTION_REMOVE_CC = 'remcc'; const ACTION_REMOVE_CC = 'remcc';
@ -79,6 +81,8 @@ abstract class HeraldAdapter {
return null; return null;
case self::FIELD_CONTENT_SOURCE: case self::FIELD_CONTENT_SOURCE:
return $this->getContentSource()->getSource(); return $this->getContentSource()->getSource();
case self::FIELD_ALWAYS:
return true;
default: default:
throw new Exception( throw new Exception(
"Unknown field '{$field_name}'!"); "Unknown field '{$field_name}'!");
@ -105,7 +109,11 @@ abstract class HeraldAdapter {
/* -( Fields )------------------------------------------------------------- */ /* -( Fields )------------------------------------------------------------- */
abstract public function getFields(); public function getFields() {
return array(
self::FIELD_ALWAYS,
);
}
public function getFieldNameMap() { public function getFieldNameMap() {
return array( return array(
@ -124,7 +132,8 @@ abstract class HeraldAdapter {
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 =>
pht("Any affected package's owner"), pht("Any affected package's owner"),
self:: FIELD_CONTENT_SOURCE => pht('Content Source') self::FIELD_CONTENT_SOURCE => pht('Content Source'),
self::FIELD_ALWAYS => pht('Always'),
); );
} }
@ -150,6 +159,7 @@ abstract class HeraldAdapter {
self::CONDITION_NOT_RULE => pht('does not match:'), self::CONDITION_NOT_RULE => pht('does not match:'),
self::CONDITION_EXISTS => pht('exists'), self::CONDITION_EXISTS => pht('exists'),
self::CONDITION_NOT_EXISTS => pht('does not exist'), self::CONDITION_NOT_EXISTS => pht('does not exist'),
self::CONDITION_UNCONDITIONALLY => '', // don't show anything!
self::CONDITION_REGEXP_PAIR => pht('matches regexp pair'), self::CONDITION_REGEXP_PAIR => pht('matches regexp pair'),
); );
} }
@ -208,6 +218,10 @@ abstract class HeraldAdapter {
self::CONDITION_IS, self::CONDITION_IS,
self::CONDITION_IS_NOT, self::CONDITION_IS_NOT,
); );
case self::FIELD_ALWAYS:
return array(
self::CONDITION_UNCONDITIONALLY,
);
default: default:
throw new Exception( throw new Exception(
"This adapter does not define conditions for field '{$field}'!"); "This adapter does not define conditions for field '{$field}'!");
@ -281,6 +295,8 @@ abstract class HeraldAdapter {
return (bool)$field_value; return (bool)$field_value;
case self::CONDITION_NOT_EXISTS: case self::CONDITION_NOT_EXISTS:
return !$field_value; return !$field_value;
case self::CONDITION_UNCONDITIONALLY:
return (bool)$field_value;
case self::CONDITION_REGEXP: case self::CONDITION_REGEXP:
foreach ((array)$field_value as $value) { foreach ((array)$field_value as $value) {
// We add the 'S' flag because we use the regexp multiple times. // We add the 'S' flag because we use the regexp multiple times.
@ -422,6 +438,7 @@ abstract class HeraldAdapter {
case self::CONDITION_NOT_RULE: case self::CONDITION_NOT_RULE:
case self::CONDITION_EXISTS: case self::CONDITION_EXISTS:
case self::CONDITION_NOT_EXISTS: case self::CONDITION_NOT_EXISTS:
case self::CONDITION_UNCONDITIONALLY:
// No explicit validation for these types, although there probably // No explicit validation for these types, although there probably
// should be in some cases. // should be in some cases.
break; break;
@ -559,6 +576,7 @@ abstract class HeraldAdapter {
case self::CONDITION_IS_NOT_ME: case self::CONDITION_IS_NOT_ME:
case self::CONDITION_EXISTS: case self::CONDITION_EXISTS:
case self::CONDITION_NOT_EXISTS: case self::CONDITION_NOT_EXISTS:
case self::CONDITION_UNCONDITIONALLY:
return self::VALUE_NONE; return self::VALUE_NONE;
case self::CONDITION_RULE: case self::CONDITION_RULE:
case self::CONDITION_NOT_RULE: case self::CONDITION_NOT_RULE:

View file

@ -5,10 +5,11 @@
*/ */
final class HeraldCommitAdapter extends HeraldAdapter { final class HeraldCommitAdapter extends HeraldAdapter {
const FIELD_NEED_AUDIT_FOR_PACKAGE = 'need-audit-for-package'; const FIELD_NEED_AUDIT_FOR_PACKAGE = 'need-audit-for-package';
const FIELD_DIFFERENTIAL_REVISION = 'differential-revision'; const FIELD_DIFFERENTIAL_REVISION = 'differential-revision';
const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers'; const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers';
const FIELD_DIFFERENTIAL_CCS = 'differential-ccs'; const FIELD_DIFFERENTIAL_CCS = 'differential-ccs';
const FIELD_REPOSITORY_AUTOCLOSE_BRANCH = 'repository-autoclose-branch';
protected $diff; protected $diff;
protected $revision; protected $revision;
@ -46,26 +47,30 @@ final class HeraldCommitAdapter extends HeraldAdapter {
self::FIELD_DIFFERENTIAL_REVISION => pht('Differential revision'), self::FIELD_DIFFERENTIAL_REVISION => pht('Differential revision'),
self::FIELD_DIFFERENTIAL_REVIEWERS => pht('Differential reviewers'), self::FIELD_DIFFERENTIAL_REVIEWERS => pht('Differential reviewers'),
self::FIELD_DIFFERENTIAL_CCS => pht('Differential CCs'), self::FIELD_DIFFERENTIAL_CCS => pht('Differential CCs'),
self::FIELD_REPOSITORY_AUTOCLOSE_BRANCH => pht('On autoclose branch'),
) + parent::getFieldNameMap(); ) + parent::getFieldNameMap();
} }
public function getFields() { public function getFields() {
return array( return array_merge(
self::FIELD_BODY, array(
self::FIELD_AUTHOR, self::FIELD_BODY,
self::FIELD_COMMITTER, self::FIELD_AUTHOR,
self::FIELD_REVIEWER, self::FIELD_COMMITTER,
self::FIELD_REPOSITORY, self::FIELD_REVIEWER,
self::FIELD_DIFF_FILE, self::FIELD_REPOSITORY,
self::FIELD_DIFF_CONTENT, self::FIELD_DIFF_FILE,
self::FIELD_RULE, self::FIELD_DIFF_CONTENT,
self::FIELD_AFFECTED_PACKAGE, self::FIELD_RULE,
self::FIELD_AFFECTED_PACKAGE_OWNER, self::FIELD_AFFECTED_PACKAGE,
self::FIELD_NEED_AUDIT_FOR_PACKAGE, self::FIELD_AFFECTED_PACKAGE_OWNER,
self::FIELD_DIFFERENTIAL_REVISION, self::FIELD_NEED_AUDIT_FOR_PACKAGE,
self::FIELD_DIFFERENTIAL_REVIEWERS, self::FIELD_DIFFERENTIAL_REVISION,
self::FIELD_DIFFERENTIAL_CCS, self::FIELD_DIFFERENTIAL_REVIEWERS,
); self::FIELD_DIFFERENTIAL_CCS,
self::FIELD_REPOSITORY_AUTOCLOSE_BRANCH,
),
parent::getFields());
} }
public function getConditionsForField($field) { public function getConditionsForField($field) {
@ -94,6 +99,10 @@ final class HeraldCommitAdapter extends HeraldAdapter {
self::CONDITION_INCLUDE_ANY, self::CONDITION_INCLUDE_ANY,
self::CONDITION_INCLUDE_NONE, self::CONDITION_INCLUDE_NONE,
); );
case self::FIELD_REPOSITORY_AUTOCLOSE_BRANCH:
return array(
self::CONDITION_UNCONDITIONALLY,
);
} }
return parent::getConditionsForField($field); return parent::getConditionsForField($field);
} }
@ -307,6 +316,10 @@ final class HeraldCommitAdapter extends HeraldAdapter {
return array(); return array();
} }
return $revision->getCCPHIDs(); return $revision->getCCPHIDs();
case self::FIELD_REPOSITORY_AUTOCLOSE_BRANCH:
return $this->repository->shouldAutocloseCommit(
$this->commit,
$this->commitData);
} }
return parent::getHeraldField($field); return parent::getHeraldField($field);

View file

@ -34,19 +34,21 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
} }
public function getFields() { public function getFields() {
return array( return array_merge(
self::FIELD_TITLE, array(
self::FIELD_BODY, self::FIELD_TITLE,
self::FIELD_AUTHOR, self::FIELD_BODY,
self::FIELD_REVIEWERS, self::FIELD_AUTHOR,
self::FIELD_CC, self::FIELD_REVIEWERS,
self::FIELD_REPOSITORY, self::FIELD_CC,
self::FIELD_DIFF_FILE, self::FIELD_REPOSITORY,
self::FIELD_DIFF_CONTENT, self::FIELD_DIFF_FILE,
self::FIELD_RULE, self::FIELD_DIFF_CONTENT,
self::FIELD_AFFECTED_PACKAGE, self::FIELD_RULE,
self::FIELD_AFFECTED_PACKAGE_OWNER, self::FIELD_AFFECTED_PACKAGE,
); self::FIELD_AFFECTED_PACKAGE_OWNER,
),
parent::getFields());
} }
public function getRepetitionOptions() { public function getRepetitionOptions() {

View file

@ -47,13 +47,15 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
} }
public function getFields() { public function getFields() {
return array( return array_merge(
self::FIELD_TITLE, array(
self::FIELD_BODY, self::FIELD_TITLE,
self::FIELD_AUTHOR, self::FIELD_BODY,
self::FIELD_CC, self::FIELD_AUTHOR,
self::FIELD_CONTENT_SOURCE, self::FIELD_CC,
); self::FIELD_CONTENT_SOURCE,
),
parent::getFields());
} }
public function getActions($rule_type) { public function getActions($rule_type) {

View file

@ -29,12 +29,14 @@ final class HeraldPholioMockAdapter extends HeraldAdapter {
} }
public function getFields() { public function getFields() {
return array( return array_merge(
self::FIELD_TITLE, array(
self::FIELD_BODY, self::FIELD_TITLE,
self::FIELD_AUTHOR, self::FIELD_BODY,
self::FIELD_CC, self::FIELD_AUTHOR,
); self::FIELD_CC,
),
parent::getFields());
} }
public function getActions($rule_type) { public function getActions($rule_type) {

View file

@ -13,7 +13,7 @@ final class HeraldRule extends HeraldDAO
protected $repetitionPolicy; protected $repetitionPolicy;
protected $ruleType; protected $ruleType;
protected $configVersion = 10; protected $configVersion = 11;
private $ruleApplied = self::ATTACHABLE; // phids for which this rule has been applied private $ruleApplied = self::ATTACHABLE; // phids for which this rule has been applied
private $validAuthor = self::ATTACHABLE; private $validAuthor = self::ATTACHABLE;

View file

@ -163,6 +163,16 @@ JX.install('HeraldRuleEditor', {
JX.DOM.setContent(condition_cell, condition_select); JX.DOM.setContent(condition_cell, condition_select);
this._onconditionchange(r); this._onconditionchange(r);
var condition_name = this._config.conditions[row_id][1];
switch (condition_name) {
case 'unconditionally':
JX.DOM.hide(condition_cell);
break;
default:
JX.DOM.show(condition_cell);
break;
}
}, },
_onconditionchange : function(r) { _onconditionchange : function(r) {
var target = JX.DOM.find(r, 'select', 'condition-select'); var target = JX.DOM.find(r, 'select', 'condition-select');