@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+102 -66
+44 -44
src/__celerity_resource_map__.php
··· 3670 3670 ), 3671 3671 'phabricator-zindex-css' => 3672 3672 array( 3673 - 'uri' => '/res/1767701c/rsrc/css/core/z-index.css', 3673 + 'uri' => '/res/b443d508/rsrc/css/core/z-index.css', 3674 3674 'type' => 'css', 3675 3675 'requires' => 3676 3676 array( ··· 4171 4171 ), array( 4172 4172 'packages' => 4173 4173 array( 4174 - '5f35f9d7' => 4174 + 'beac5d1a' => 4175 4175 array( 4176 4176 'name' => 'core.pkg.css', 4177 4177 'symbols' => ··· 4218 4218 39 => 'phabricator-property-list-view-css', 4219 4219 40 => 'phabricator-tag-view-css', 4220 4220 ), 4221 - 'uri' => '/res/pkg/5f35f9d7/core.pkg.css', 4221 + 'uri' => '/res/pkg/beac5d1a/core.pkg.css', 4222 4222 'type' => 'css', 4223 4223 ), 4224 4224 '8977e356' => ··· 4409 4409 ), 4410 4410 'reverse' => 4411 4411 array( 4412 - 'aphront-dialog-view-css' => '5f35f9d7', 4413 - 'aphront-error-view-css' => '5f35f9d7', 4414 - 'aphront-list-filter-view-css' => '5f35f9d7', 4415 - 'aphront-pager-view-css' => '5f35f9d7', 4416 - 'aphront-panel-view-css' => '5f35f9d7', 4417 - 'aphront-table-view-css' => '5f35f9d7', 4418 - 'aphront-tokenizer-control-css' => '5f35f9d7', 4419 - 'aphront-tooltip-css' => '5f35f9d7', 4420 - 'aphront-typeahead-control-css' => '5f35f9d7', 4412 + 'aphront-dialog-view-css' => 'beac5d1a', 4413 + 'aphront-error-view-css' => 'beac5d1a', 4414 + 'aphront-list-filter-view-css' => 'beac5d1a', 4415 + 'aphront-pager-view-css' => 'beac5d1a', 4416 + 'aphront-panel-view-css' => 'beac5d1a', 4417 + 'aphront-table-view-css' => 'beac5d1a', 4418 + 'aphront-tokenizer-control-css' => 'beac5d1a', 4419 + 'aphront-tooltip-css' => 'beac5d1a', 4420 + 'aphront-typeahead-control-css' => 'beac5d1a', 4421 4421 'differential-changeset-view-css' => '09216861', 4422 4422 'differential-core-view-css' => '09216861', 4423 4423 'differential-inline-comment-editor' => 'd07a3bc2', ··· 4431 4431 'differential-table-of-contents-css' => '09216861', 4432 4432 'diffusion-commit-view-css' => 'c8ce2d88', 4433 4433 'diffusion-icons-css' => 'c8ce2d88', 4434 - 'global-drag-and-drop-css' => '5f35f9d7', 4434 + 'global-drag-and-drop-css' => 'beac5d1a', 4435 4435 'inline-comment-summary-css' => '09216861', 4436 4436 'javelin-aphlict' => '8977e356', 4437 4437 'javelin-behavior' => '2dbbb7d1', ··· 4504 4504 'javelin-util' => '2dbbb7d1', 4505 4505 'javelin-vector' => '2dbbb7d1', 4506 4506 'javelin-workflow' => '2dbbb7d1', 4507 - 'lightbox-attachment-css' => '5f35f9d7', 4507 + 'lightbox-attachment-css' => 'beac5d1a', 4508 4508 'maniphest-task-summary-css' => '06bacb9a', 4509 4509 'maniphest-transaction-detail-css' => '06bacb9a', 4510 - 'phabricator-action-list-view-css' => '5f35f9d7', 4511 - 'phabricator-application-launch-view-css' => '5f35f9d7', 4510 + 'phabricator-action-list-view-css' => 'beac5d1a', 4511 + 'phabricator-application-launch-view-css' => 'beac5d1a', 4512 4512 'phabricator-busy' => '8977e356', 4513 4513 'phabricator-content-source-view-css' => '09216861', 4514 - 'phabricator-core-css' => '5f35f9d7', 4515 - 'phabricator-crumbs-view-css' => '5f35f9d7', 4514 + 'phabricator-core-css' => 'beac5d1a', 4515 + 'phabricator-crumbs-view-css' => 'beac5d1a', 4516 4516 'phabricator-drag-and-drop-file-upload' => 'd07a3bc2', 4517 4517 'phabricator-dropdown-menu' => '8977e356', 4518 4518 'phabricator-file-upload' => '8977e356', 4519 - 'phabricator-filetree-view-css' => '5f35f9d7', 4520 - 'phabricator-flag-css' => '5f35f9d7', 4521 - 'phabricator-header-view-css' => '5f35f9d7', 4519 + 'phabricator-filetree-view-css' => 'beac5d1a', 4520 + 'phabricator-flag-css' => 'beac5d1a', 4521 + 'phabricator-header-view-css' => 'beac5d1a', 4522 4522 'phabricator-hovercard' => '8977e356', 4523 - 'phabricator-jump-nav' => '5f35f9d7', 4523 + 'phabricator-jump-nav' => 'beac5d1a', 4524 4524 'phabricator-keyboard-shortcut' => '8977e356', 4525 4525 'phabricator-keyboard-shortcut-manager' => '8977e356', 4526 - 'phabricator-main-menu-view' => '5f35f9d7', 4526 + 'phabricator-main-menu-view' => 'beac5d1a', 4527 4527 'phabricator-menu-item' => '8977e356', 4528 - 'phabricator-nav-view-css' => '5f35f9d7', 4528 + 'phabricator-nav-view-css' => 'beac5d1a', 4529 4529 'phabricator-notification' => '8977e356', 4530 - 'phabricator-notification-css' => '5f35f9d7', 4531 - 'phabricator-notification-menu-css' => '5f35f9d7', 4532 - 'phabricator-object-item-list-view-css' => '5f35f9d7', 4530 + 'phabricator-notification-css' => 'beac5d1a', 4531 + 'phabricator-notification-menu-css' => 'beac5d1a', 4532 + 'phabricator-object-item-list-view-css' => 'beac5d1a', 4533 4533 'phabricator-object-selector-css' => '09216861', 4534 4534 'phabricator-phtize' => '8977e356', 4535 4535 'phabricator-prefab' => '8977e356', 4536 4536 'phabricator-project-tag-css' => '06bacb9a', 4537 - 'phabricator-property-list-view-css' => '5f35f9d7', 4538 - 'phabricator-remarkup-css' => '5f35f9d7', 4537 + 'phabricator-property-list-view-css' => 'beac5d1a', 4538 + 'phabricator-remarkup-css' => 'beac5d1a', 4539 4539 'phabricator-shaped-request' => 'd07a3bc2', 4540 - 'phabricator-side-menu-view-css' => '5f35f9d7', 4541 - 'phabricator-standard-page-view' => '5f35f9d7', 4542 - 'phabricator-tag-view-css' => '5f35f9d7', 4540 + 'phabricator-side-menu-view-css' => 'beac5d1a', 4541 + 'phabricator-standard-page-view' => 'beac5d1a', 4542 + 'phabricator-tag-view-css' => 'beac5d1a', 4543 4543 'phabricator-textareautils' => '8977e356', 4544 4544 'phabricator-tooltip' => '8977e356', 4545 - 'phabricator-transaction-view-css' => '5f35f9d7', 4546 - 'phabricator-zindex-css' => '5f35f9d7', 4547 - 'phui-button-css' => '5f35f9d7', 4548 - 'phui-form-css' => '5f35f9d7', 4549 - 'phui-form-view-css' => '5f35f9d7', 4550 - 'phui-icon-view-css' => '5f35f9d7', 4551 - 'phui-spacing-css' => '5f35f9d7', 4552 - 'sprite-apps-large-css' => '5f35f9d7', 4553 - 'sprite-gradient-css' => '5f35f9d7', 4554 - 'sprite-icons-css' => '5f35f9d7', 4555 - 'sprite-menu-css' => '5f35f9d7', 4556 - 'syntax-highlighting-css' => '5f35f9d7', 4545 + 'phabricator-transaction-view-css' => 'beac5d1a', 4546 + 'phabricator-zindex-css' => 'beac5d1a', 4547 + 'phui-button-css' => 'beac5d1a', 4548 + 'phui-form-css' => 'beac5d1a', 4549 + 'phui-form-view-css' => 'beac5d1a', 4550 + 'phui-icon-view-css' => 'beac5d1a', 4551 + 'phui-spacing-css' => 'beac5d1a', 4552 + 'sprite-apps-large-css' => 'beac5d1a', 4553 + 'sprite-gradient-css' => 'beac5d1a', 4554 + 'sprite-icons-css' => 'beac5d1a', 4555 + 'sprite-menu-css' => 'beac5d1a', 4556 + 'syntax-highlighting-css' => 'beac5d1a', 4557 4557 ), 4558 4558 ));
+17 -2
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 18 18 protected $commitData; 19 19 20 20 protected $emailPHIDs = array(); 21 + protected $addCCPHIDs = array(); 21 22 protected $auditMap = array(); 22 23 23 24 protected $affectedPaths; ··· 95 96 case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 96 97 return array( 97 98 self::ACTION_ADD_CC, 98 - self::ACTION_REMOVE_CC, 99 99 self::ACTION_EMAIL, 100 100 self::ACTION_AUDIT, 101 101 self::ACTION_NOTHING, ··· 103 103 case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 104 104 return array( 105 105 self::ACTION_ADD_CC, 106 - self::ACTION_REMOVE_CC, 107 106 self::ACTION_EMAIL, 108 107 self::ACTION_FLAG, 109 108 self::ACTION_AUDIT, ··· 143 142 144 143 public function getEmailPHIDs() { 145 144 return array_keys($this->emailPHIDs); 145 + } 146 + 147 + public function getAddCCMap() { 148 + return $this->addCCPHIDs; 146 149 } 147 150 148 151 public function getAuditMap() { ··· 322 325 $effect, 323 326 true, 324 327 pht('Added address to email targets.')); 328 + break; 329 + case self::ACTION_ADD_CC: 330 + foreach ($effect->getTarget() as $phid) { 331 + if (empty($this->addCCPHIDs[$phid])) { 332 + $this->addCCPHIDs[$phid] = array(); 333 + } 334 + $this->addCCPHIDs[$phid][] = $effect->getRuleID(); 335 + } 336 + $result[] = new HeraldApplyTranscript( 337 + $effect, 338 + true, 339 + pht('Added address to CC.')); 325 340 break; 326 341 case self::ACTION_AUDIT: 327 342 foreach ($effect->getTarget() as $phid) {
+41 -20
src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
··· 41 41 $xscript = $engine->getTranscript(); 42 42 43 43 $audit_phids = $adapter->getAuditMap(); 44 - if ($audit_phids) { 45 - $this->createAudits($commit, $audit_phids, $rules); 44 + $cc_phids = $adapter->getAddCCMap(); 45 + if ($audit_phids || $cc_phids) { 46 + $this->createAudits($commit, $audit_phids, $cc_phids, $rules); 46 47 } 47 48 48 49 $explicit_auditors = $this->createAuditsFromCommitMessage($commit, $data); ··· 59 60 $email_phids = array_unique( 60 61 array_merge( 61 62 $explicit_auditors, 63 + array_keys($cc_phids), 62 64 $herald_targets)); 63 65 if (!$email_phids) { 64 66 return; ··· 174 176 private function createAudits( 175 177 PhabricatorRepositoryCommit $commit, 176 178 array $map, 179 + array $ccmap, 177 180 array $rules) { 178 181 assert_instances_of($rules, 'HeraldRule'); 179 182 ··· 183 186 $requests = mpull($requests, null, 'getAuditorPHID'); 184 187 185 188 $rules = mpull($rules, null, 'getID'); 186 - foreach ($map as $phid => $rule_ids) { 187 - $request = idx($requests, $phid); 188 - if ($request) { 189 - continue; 190 - } 191 - $reasons = array(); 192 - foreach ($rule_ids as $id) { 193 - $rule_name = '?'; 194 - if ($rules[$id]) { 195 - $rule_name = $rules[$id]->getName(); 189 + 190 + $maps = array( 191 + PhabricatorAuditStatusConstants::AUDIT_REQUIRED => $map, 192 + PhabricatorAuditStatusConstants::CC => $ccmap, 193 + ); 194 + 195 + foreach ($maps as $status => $map) { 196 + foreach ($map as $phid => $rule_ids) { 197 + $request = idx($requests, $phid); 198 + if ($request) { 199 + continue; 200 + } 201 + $reasons = array(); 202 + foreach ($rule_ids as $id) { 203 + $rule_name = '?'; 204 + if ($rules[$id]) { 205 + $rule_name = $rules[$id]->getName(); 206 + } 207 + if ($status == PhabricatorAuditStatusConstants::AUDIT_REQUIRED) { 208 + $reasons[] = pht( 209 + 'Herald Rule #%d "%s" Triggered Audit', 210 + $id, 211 + $rule_name); 212 + } else { 213 + $reasons[] = pht( 214 + 'Herald Rule #%d "%s" Triggered CC', 215 + $id, 216 + $rule_name); 217 + } 196 218 } 197 - $reasons[] = 'Herald Rule #'.$id.' "'.$rule_name.'" Triggered Audit'; 219 + 220 + $request = new PhabricatorRepositoryAuditRequest(); 221 + $request->setCommitPHID($commit->getPHID()); 222 + $request->setAuditorPHID($phid); 223 + $request->setAuditStatus($status); 224 + $request->setAuditReasons($reasons); 225 + $request->save(); 198 226 } 199 - 200 - $request = new PhabricatorRepositoryAuditRequest(); 201 - $request->setCommitPHID($commit->getPHID()); 202 - $request->setAuditorPHID($phid); 203 - $request->setAuditStatus(PhabricatorAuditStatusConstants::AUDIT_REQUIRED); 204 - $request->setAuditReasons($reasons); 205 - $request->save(); 206 227 } 207 228 208 229 $commit->updateAuditStatus($requests);