@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.

Introduce an AuditStatus object for commits and move some callsites to it

Summary:
Ref T13195. See PHI851. Add an object, analogous to the `DifferentialRevisionStatus` object, to handle audit status management.

This will primarily make it easier to swap storage over to strings later, but also cleans things up a bit.

Test Plan: Viewed audit/commit lists, saw sensible state icons. Ran `bin/audit synchronize`, got sensible output.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13195

Differential Revision: https://secure.phabricator.com/D19646

+66 -22
+44
src/applications/audit/constants/PhabricatorAuditCommitStatusConstants.php
··· 2 2 3 3 final class PhabricatorAuditCommitStatusConstants extends Phobject { 4 4 5 + private $key; 6 + private $spec = array(); 7 + 5 8 const NONE = 0; 6 9 const NEEDS_AUDIT = 1; 7 10 const CONCERN_RAISED = 2; ··· 15 18 const MODERN_PARTIALLY_AUDITED = 'partially-audited'; 16 19 const MODERN_AUDITED = 'audited'; 17 20 const MODERN_NEEDS_VERIFICATION = 'needs-verification'; 21 + 22 + public static function newForLegacyStatus($status) { 23 + $map = self::getMap(); 24 + 25 + foreach ($map as $key => $spec) { 26 + if (idx($spec, 'legacy') == $status) { 27 + return self::newForStatus($key); 28 + } 29 + } 30 + 31 + return self::newForStatus($status); 32 + } 33 + 34 + public static function newForStatus($status) { 35 + $result = new self(); 36 + 37 + $result->key = $status; 38 + 39 + $map = self::getMap(); 40 + if (isset($map[$status])) { 41 + $result->spec = $map[$status]; 42 + } 43 + 44 + return $result; 45 + } 46 + 47 + public function getKey() { 48 + return $this->key; 49 + } 50 + 51 + public function getIcon() { 52 + return idx($this->spec, 'icon'); 53 + } 54 + 55 + public function getColor() { 56 + return idx($this->spec, 'color'); 57 + } 58 + 59 + public function getName() { 60 + return idx($this->spec, 'name', pht('Unknown ("%s")', $this->key)); 61 + } 18 62 19 63 public static function getStatusNameMap() { 20 64 $map = self::getMap();
+5 -7
src/applications/audit/management/PhabricatorAuditSynchronizeManagementWorkflow.php
··· 30 30 continue; 31 31 } 32 32 33 - $old_status = $commit->getAuditStatus(); 33 + $old_status = $commit->getAuditStatusObject(); 34 34 $commit->updateAuditStatus($commit->getAudits()); 35 - $new_status = $commit->getAuditStatus(); 35 + $new_status = $commit->getAuditStatusObject(); 36 36 37 - if ($old_status == $new_status) { 37 + if ($old_status->getKey() == $new_status->getKey()) { 38 38 echo tsprintf( 39 39 "%s\n", 40 40 pht( ··· 46 46 pht( 47 47 'Updating "%s": "%s" -> "%s".', 48 48 $commit->getDisplayName(), 49 - PhabricatorAuditCommitStatusConstants::getStatusName( 50 - $old_status), 51 - PhabricatorAuditCommitStatusConstants::getStatusName( 52 - $new_status))); 49 + $old_status->getName(), 50 + $new_status->getName())); 53 51 54 52 $commit->save(); 55 53 }
+4 -7
src/applications/audit/view/PhabricatorAuditListView.php
··· 120 120 $commit_desc = $this->getCommitDescription($commit_phid); 121 121 $committed = phabricator_datetime($commit->getEpoch(), $viewer); 122 122 123 - $status = $commit->getAuditStatus(); 123 + $status = $commit->getAuditStatusObject(); 124 124 125 - $status_text = 126 - PhabricatorAuditCommitStatusConstants::getStatusName($status); 127 - $status_color = 128 - PhabricatorAuditCommitStatusConstants::getStatusColor($status); 129 - $status_icon = 130 - PhabricatorAuditCommitStatusConstants::getStatusIcon($status); 125 + $status_text = $status->getName(); 126 + $status_color = $status->getColor(); 127 + $status_icon = $status->getIcon(); 131 128 132 129 $author_phid = $commit->getAuthorPHID(); 133 130 if ($author_phid) {
+4 -4
src/applications/diffusion/view/DiffusionHistoryTableView.php
··· 114 114 'type' => $history->getFileType(), 115 115 )); 116 116 117 - $status = $commit->getAuditStatus(); 118 - $icon = PhabricatorAuditCommitStatusConstants::getStatusIcon($status); 119 - $color = PhabricatorAuditCommitStatusConstants::getStatusColor($status); 120 - $name = PhabricatorAuditCommitStatusConstants::getStatusName($status); 117 + $status = $commit->getAuditStatusObject(); 118 + $icon = $status->getIcon(); 119 + $color = $status->getColor(); 120 + $name = $status->getName(); 121 121 122 122 $audit_view = id(new PHUIIconView()) 123 123 ->setIcon($icon, $color)
+4 -4
src/applications/repository/phid/PhabricatorRepositoryCommitPHIDType.php
··· 82 82 $handle->setURI($commit->getURI()); 83 83 $handle->setTimestamp($commit->getEpoch()); 84 84 85 - $status = $commit->getAuditStatus(); 86 - $icon = PhabricatorAuditCommitStatusConstants::getStatusIcon($status); 87 - $color = PhabricatorAuditCommitStatusConstants::getStatusColor($status); 88 - $name = PhabricatorAuditCommitStatusConstants::getStatusName($status); 85 + $status = $commit->getAuditStatusObject(); 86 + $icon = $status->getIcon(); 87 + $color = $status->getColor(); 88 + $name = $status->getName(); 89 89 90 90 $handle 91 91 ->setStateIcon($icon)
+5
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 530 530 return $data->getCommitDetail('authorPHID'); 531 531 } 532 532 533 + public function getAuditStatusObject() { 534 + $status = $this->getAuditStatus(); 535 + return PhabricatorAuditCommitStatusConstants::newForLegacyStatus($status); 536 + } 537 + 533 538 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 534 539 535 540 public function getCapabilities() {