1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

Implement "Add to CC" rule for Audits

Summary:
D6660 accidentally allowed you to build Herald rules for commits that take action "Add to CC", but provided no implementation.

Someone at Facebook then wrote such a rule.

Fix forward since there's no real reason not to allow this.

Test Plan: Used `./scripts/repository/reparse.php --herald rXnnnn` to trigger rules. Observed rule trigger and subsequent subscription.

Reviewers: wez, btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D6845
This commit is contained in:
epriestley 2013-08-29 17:03:40 -07:00
parent b16d5b9ba4
commit b932c606cb
3 changed files with 103 additions and 67 deletions

View file

@ -3670,7 +3670,7 @@ celerity_register_resource_map(array(
),
'phabricator-zindex-css' =>
array(
'uri' => '/res/1767701c/rsrc/css/core/z-index.css',
'uri' => '/res/b443d508/rsrc/css/core/z-index.css',
'type' => 'css',
'requires' =>
array(
@ -4171,7 +4171,7 @@ celerity_register_resource_map(array(
), array(
'packages' =>
array(
'5f35f9d7' =>
'beac5d1a' =>
array(
'name' => 'core.pkg.css',
'symbols' =>
@ -4218,7 +4218,7 @@ celerity_register_resource_map(array(
39 => 'phabricator-property-list-view-css',
40 => 'phabricator-tag-view-css',
),
'uri' => '/res/pkg/5f35f9d7/core.pkg.css',
'uri' => '/res/pkg/beac5d1a/core.pkg.css',
'type' => 'css',
),
'8977e356' =>
@ -4409,15 +4409,15 @@ celerity_register_resource_map(array(
),
'reverse' =>
array(
'aphront-dialog-view-css' => '5f35f9d7',
'aphront-error-view-css' => '5f35f9d7',
'aphront-list-filter-view-css' => '5f35f9d7',
'aphront-pager-view-css' => '5f35f9d7',
'aphront-panel-view-css' => '5f35f9d7',
'aphront-table-view-css' => '5f35f9d7',
'aphront-tokenizer-control-css' => '5f35f9d7',
'aphront-tooltip-css' => '5f35f9d7',
'aphront-typeahead-control-css' => '5f35f9d7',
'aphront-dialog-view-css' => 'beac5d1a',
'aphront-error-view-css' => 'beac5d1a',
'aphront-list-filter-view-css' => 'beac5d1a',
'aphront-pager-view-css' => 'beac5d1a',
'aphront-panel-view-css' => 'beac5d1a',
'aphront-table-view-css' => 'beac5d1a',
'aphront-tokenizer-control-css' => 'beac5d1a',
'aphront-tooltip-css' => 'beac5d1a',
'aphront-typeahead-control-css' => 'beac5d1a',
'differential-changeset-view-css' => '09216861',
'differential-core-view-css' => '09216861',
'differential-inline-comment-editor' => 'd07a3bc2',
@ -4431,7 +4431,7 @@ celerity_register_resource_map(array(
'differential-table-of-contents-css' => '09216861',
'diffusion-commit-view-css' => 'c8ce2d88',
'diffusion-icons-css' => 'c8ce2d88',
'global-drag-and-drop-css' => '5f35f9d7',
'global-drag-and-drop-css' => 'beac5d1a',
'inline-comment-summary-css' => '09216861',
'javelin-aphlict' => '8977e356',
'javelin-behavior' => '2dbbb7d1',
@ -4504,55 +4504,55 @@ celerity_register_resource_map(array(
'javelin-util' => '2dbbb7d1',
'javelin-vector' => '2dbbb7d1',
'javelin-workflow' => '2dbbb7d1',
'lightbox-attachment-css' => '5f35f9d7',
'lightbox-attachment-css' => 'beac5d1a',
'maniphest-task-summary-css' => '06bacb9a',
'maniphest-transaction-detail-css' => '06bacb9a',
'phabricator-action-list-view-css' => '5f35f9d7',
'phabricator-application-launch-view-css' => '5f35f9d7',
'phabricator-action-list-view-css' => 'beac5d1a',
'phabricator-application-launch-view-css' => 'beac5d1a',
'phabricator-busy' => '8977e356',
'phabricator-content-source-view-css' => '09216861',
'phabricator-core-css' => '5f35f9d7',
'phabricator-crumbs-view-css' => '5f35f9d7',
'phabricator-core-css' => 'beac5d1a',
'phabricator-crumbs-view-css' => 'beac5d1a',
'phabricator-drag-and-drop-file-upload' => 'd07a3bc2',
'phabricator-dropdown-menu' => '8977e356',
'phabricator-file-upload' => '8977e356',
'phabricator-filetree-view-css' => '5f35f9d7',
'phabricator-flag-css' => '5f35f9d7',
'phabricator-header-view-css' => '5f35f9d7',
'phabricator-filetree-view-css' => 'beac5d1a',
'phabricator-flag-css' => 'beac5d1a',
'phabricator-header-view-css' => 'beac5d1a',
'phabricator-hovercard' => '8977e356',
'phabricator-jump-nav' => '5f35f9d7',
'phabricator-jump-nav' => 'beac5d1a',
'phabricator-keyboard-shortcut' => '8977e356',
'phabricator-keyboard-shortcut-manager' => '8977e356',
'phabricator-main-menu-view' => '5f35f9d7',
'phabricator-main-menu-view' => 'beac5d1a',
'phabricator-menu-item' => '8977e356',
'phabricator-nav-view-css' => '5f35f9d7',
'phabricator-nav-view-css' => 'beac5d1a',
'phabricator-notification' => '8977e356',
'phabricator-notification-css' => '5f35f9d7',
'phabricator-notification-menu-css' => '5f35f9d7',
'phabricator-object-item-list-view-css' => '5f35f9d7',
'phabricator-notification-css' => 'beac5d1a',
'phabricator-notification-menu-css' => 'beac5d1a',
'phabricator-object-item-list-view-css' => 'beac5d1a',
'phabricator-object-selector-css' => '09216861',
'phabricator-phtize' => '8977e356',
'phabricator-prefab' => '8977e356',
'phabricator-project-tag-css' => '06bacb9a',
'phabricator-property-list-view-css' => '5f35f9d7',
'phabricator-remarkup-css' => '5f35f9d7',
'phabricator-property-list-view-css' => 'beac5d1a',
'phabricator-remarkup-css' => 'beac5d1a',
'phabricator-shaped-request' => 'd07a3bc2',
'phabricator-side-menu-view-css' => '5f35f9d7',
'phabricator-standard-page-view' => '5f35f9d7',
'phabricator-tag-view-css' => '5f35f9d7',
'phabricator-side-menu-view-css' => 'beac5d1a',
'phabricator-standard-page-view' => 'beac5d1a',
'phabricator-tag-view-css' => 'beac5d1a',
'phabricator-textareautils' => '8977e356',
'phabricator-tooltip' => '8977e356',
'phabricator-transaction-view-css' => '5f35f9d7',
'phabricator-zindex-css' => '5f35f9d7',
'phui-button-css' => '5f35f9d7',
'phui-form-css' => '5f35f9d7',
'phui-form-view-css' => '5f35f9d7',
'phui-icon-view-css' => '5f35f9d7',
'phui-spacing-css' => '5f35f9d7',
'sprite-apps-large-css' => '5f35f9d7',
'sprite-gradient-css' => '5f35f9d7',
'sprite-icons-css' => '5f35f9d7',
'sprite-menu-css' => '5f35f9d7',
'syntax-highlighting-css' => '5f35f9d7',
'phabricator-transaction-view-css' => 'beac5d1a',
'phabricator-zindex-css' => 'beac5d1a',
'phui-button-css' => 'beac5d1a',
'phui-form-css' => 'beac5d1a',
'phui-form-view-css' => 'beac5d1a',
'phui-icon-view-css' => 'beac5d1a',
'phui-spacing-css' => 'beac5d1a',
'sprite-apps-large-css' => 'beac5d1a',
'sprite-gradient-css' => 'beac5d1a',
'sprite-icons-css' => 'beac5d1a',
'sprite-menu-css' => 'beac5d1a',
'syntax-highlighting-css' => 'beac5d1a',
),
));

View file

@ -18,6 +18,7 @@ final class HeraldCommitAdapter extends HeraldAdapter {
protected $commitData;
protected $emailPHIDs = array();
protected $addCCPHIDs = array();
protected $auditMap = array();
protected $affectedPaths;
@ -95,7 +96,6 @@ final class HeraldCommitAdapter extends HeraldAdapter {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
return array(
self::ACTION_ADD_CC,
self::ACTION_REMOVE_CC,
self::ACTION_EMAIL,
self::ACTION_AUDIT,
self::ACTION_NOTHING,
@ -103,7 +103,6 @@ final class HeraldCommitAdapter extends HeraldAdapter {
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
return array(
self::ACTION_ADD_CC,
self::ACTION_REMOVE_CC,
self::ACTION_EMAIL,
self::ACTION_FLAG,
self::ACTION_AUDIT,
@ -145,6 +144,10 @@ final class HeraldCommitAdapter extends HeraldAdapter {
return array_keys($this->emailPHIDs);
}
public function getAddCCMap() {
return $this->addCCPHIDs;
}
public function getAuditMap() {
return $this->auditMap;
}
@ -323,6 +326,18 @@ final class HeraldCommitAdapter extends HeraldAdapter {
true,
pht('Added address to email targets.'));
break;
case self::ACTION_ADD_CC:
foreach ($effect->getTarget() as $phid) {
if (empty($this->addCCPHIDs[$phid])) {
$this->addCCPHIDs[$phid] = array();
}
$this->addCCPHIDs[$phid][] = $effect->getRuleID();
}
$result[] = new HeraldApplyTranscript(
$effect,
true,
pht('Added address to CC.'));
break;
case self::ACTION_AUDIT:
foreach ($effect->getTarget() as $phid) {
if (empty($this->auditMap[$phid])) {

View file

@ -41,8 +41,9 @@ final class PhabricatorRepositoryCommitHeraldWorker
$xscript = $engine->getTranscript();
$audit_phids = $adapter->getAuditMap();
if ($audit_phids) {
$this->createAudits($commit, $audit_phids, $rules);
$cc_phids = $adapter->getAddCCMap();
if ($audit_phids || $cc_phids) {
$this->createAudits($commit, $audit_phids, $cc_phids, $rules);
}
$explicit_auditors = $this->createAuditsFromCommitMessage($commit, $data);
@ -59,6 +60,7 @@ final class PhabricatorRepositoryCommitHeraldWorker
$email_phids = array_unique(
array_merge(
$explicit_auditors,
array_keys($cc_phids),
$herald_targets));
if (!$email_phids) {
return;
@ -174,6 +176,7 @@ final class PhabricatorRepositoryCommitHeraldWorker
private function createAudits(
PhabricatorRepositoryCommit $commit,
array $map,
array $ccmap,
array $rules) {
assert_instances_of($rules, 'HeraldRule');
@ -183,26 +186,44 @@ final class PhabricatorRepositoryCommitHeraldWorker
$requests = mpull($requests, null, 'getAuditorPHID');
$rules = mpull($rules, null, 'getID');
foreach ($map as $phid => $rule_ids) {
$request = idx($requests, $phid);
if ($request) {
continue;
}
$reasons = array();
foreach ($rule_ids as $id) {
$rule_name = '?';
if ($rules[$id]) {
$rule_name = $rules[$id]->getName();
}
$reasons[] = 'Herald Rule #'.$id.' "'.$rule_name.'" Triggered Audit';
}
$request = new PhabricatorRepositoryAuditRequest();
$request->setCommitPHID($commit->getPHID());
$request->setAuditorPHID($phid);
$request->setAuditStatus(PhabricatorAuditStatusConstants::AUDIT_REQUIRED);
$request->setAuditReasons($reasons);
$request->save();
$maps = array(
PhabricatorAuditStatusConstants::AUDIT_REQUIRED => $map,
PhabricatorAuditStatusConstants::CC => $ccmap,
);
foreach ($maps as $status => $map) {
foreach ($map as $phid => $rule_ids) {
$request = idx($requests, $phid);
if ($request) {
continue;
}
$reasons = array();
foreach ($rule_ids as $id) {
$rule_name = '?';
if ($rules[$id]) {
$rule_name = $rules[$id]->getName();
}
if ($status == PhabricatorAuditStatusConstants::AUDIT_REQUIRED) {
$reasons[] = pht(
'Herald Rule #%d "%s" Triggered Audit',
$id,
$rule_name);
} else {
$reasons[] = pht(
'Herald Rule #%d "%s" Triggered CC',
$id,
$rule_name);
}
}
$request = new PhabricatorRepositoryAuditRequest();
$request->setCommitPHID($commit->getPHID());
$request->setAuditorPHID($phid);
$request->setAuditStatus($status);
$request->setAuditReasons($reasons);
$request->save();
}
}
$commit->updateAuditStatus($requests);