Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / herald / DiffusionAuditorsHeraldAction.php
blobbd75799f03117e7678d9728f9c6487c63b097581
1 <?php
3 abstract class DiffusionAuditorsHeraldAction
4 extends HeraldAction {
6 const DO_AUTHORS = 'do.authors';
7 const DO_ADD_AUDITORS = 'do.add-auditors';
9 public function getActionGroupKey() {
10 return HeraldApplicationActionGroup::ACTIONGROUPKEY;
13 public function supportsObject($object) {
14 return ($object instanceof PhabricatorRepositoryCommit);
17 protected function applyAuditors(array $phids, HeraldRule $rule) {
18 $adapter = $this->getAdapter();
19 $object = $adapter->getObject();
21 $auditors = $object->getAudits();
23 // Don't try to add commit authors as auditors.
24 $authors = array();
25 foreach ($phids as $key => $phid) {
26 if ($phid == $object->getAuthorPHID()) {
27 $authors[] = $phid;
28 unset($phids[$key]);
32 if ($authors) {
33 $this->logEffect(self::DO_AUTHORS, $authors);
34 if (!$phids) {
35 return;
39 $current = array();
40 foreach ($auditors as $auditor) {
41 $current[] = $auditor->getAuditorPHID();
44 $allowed_types = array(
45 PhabricatorPeopleUserPHIDType::TYPECONST,
46 PhabricatorProjectProjectPHIDType::TYPECONST,
47 PhabricatorOwnersPackagePHIDType::TYPECONST,
50 $targets = $this->loadStandardTargets($phids, $allowed_types, $current);
51 if (!$targets) {
52 return;
55 $phids = array_fuse(array_keys($targets));
57 $xaction = $adapter->newTransaction()
58 ->setTransactionType(DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE)
59 ->setNewValue(
60 array(
61 '+' => $phids,
62 ));
64 $adapter->queueTransaction($xaction);
66 $this->logEffect(self::DO_ADD_AUDITORS, $phids);
69 protected function getActionEffectMap() {
70 return array(
71 self::DO_AUTHORS => array(
72 'icon' => 'fa-user',
73 'color' => 'grey',
74 'name' => pht('Commit Author'),
76 self::DO_ADD_AUDITORS => array(
77 'icon' => 'fa-user',
78 'color' => 'green',
79 'name' => pht('Added Auditors'),
84 protected function renderActionEffectDescription($type, $data) {
85 switch ($type) {
86 case self::DO_AUTHORS:
87 return pht(
88 'Declined to add commit author as auditor: %s.',
89 $this->renderHandleList($data));
90 case self::DO_ADD_AUDITORS:
91 return pht(
92 'Added %s auditor(s): %s.',
93 phutil_count($data),
94 $this->renderHandleList($data));