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

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
This commit is contained in:
epriestley 2018-09-07 08:30:18 -07:00
parent ab4d33bede
commit a1ce23b9f5
6 changed files with 66 additions and 22 deletions

View file

@ -2,6 +2,9 @@
final class PhabricatorAuditCommitStatusConstants extends Phobject {
private $key;
private $spec = array();
const NONE = 0;
const NEEDS_AUDIT = 1;
const CONCERN_RAISED = 2;
@ -16,6 +19,47 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
const MODERN_AUDITED = 'audited';
const MODERN_NEEDS_VERIFICATION = 'needs-verification';
public static function newForLegacyStatus($status) {
$map = self::getMap();
foreach ($map as $key => $spec) {
if (idx($spec, 'legacy') == $status) {
return self::newForStatus($key);
}
}
return self::newForStatus($status);
}
public static function newForStatus($status) {
$result = new self();
$result->key = $status;
$map = self::getMap();
if (isset($map[$status])) {
$result->spec = $map[$status];
}
return $result;
}
public function getKey() {
return $this->key;
}
public function getIcon() {
return idx($this->spec, 'icon');
}
public function getColor() {
return idx($this->spec, 'color');
}
public function getName() {
return idx($this->spec, 'name', pht('Unknown ("%s")', $this->key));
}
public static function getStatusNameMap() {
$map = self::getMap();
return ipull($map, 'name', 'legacy');

View file

@ -30,11 +30,11 @@ final class PhabricatorAuditSynchronizeManagementWorkflow
continue;
}
$old_status = $commit->getAuditStatus();
$old_status = $commit->getAuditStatusObject();
$commit->updateAuditStatus($commit->getAudits());
$new_status = $commit->getAuditStatus();
$new_status = $commit->getAuditStatusObject();
if ($old_status == $new_status) {
if ($old_status->getKey() == $new_status->getKey()) {
echo tsprintf(
"%s\n",
pht(
@ -46,10 +46,8 @@ final class PhabricatorAuditSynchronizeManagementWorkflow
pht(
'Updating "%s": "%s" -> "%s".',
$commit->getDisplayName(),
PhabricatorAuditCommitStatusConstants::getStatusName(
$old_status),
PhabricatorAuditCommitStatusConstants::getStatusName(
$new_status)));
$old_status->getName(),
$new_status->getName()));
$commit->save();
}

View file

@ -120,14 +120,11 @@ final class PhabricatorAuditListView extends AphrontView {
$commit_desc = $this->getCommitDescription($commit_phid);
$committed = phabricator_datetime($commit->getEpoch(), $viewer);
$status = $commit->getAuditStatus();
$status = $commit->getAuditStatusObject();
$status_text =
PhabricatorAuditCommitStatusConstants::getStatusName($status);
$status_color =
PhabricatorAuditCommitStatusConstants::getStatusColor($status);
$status_icon =
PhabricatorAuditCommitStatusConstants::getStatusIcon($status);
$status_text = $status->getName();
$status_color = $status->getColor();
$status_icon = $status->getIcon();
$author_phid = $commit->getAuthorPHID();
if ($author_phid) {

View file

@ -114,10 +114,10 @@ final class DiffusionHistoryTableView extends DiffusionHistoryView {
'type' => $history->getFileType(),
));
$status = $commit->getAuditStatus();
$icon = PhabricatorAuditCommitStatusConstants::getStatusIcon($status);
$color = PhabricatorAuditCommitStatusConstants::getStatusColor($status);
$name = PhabricatorAuditCommitStatusConstants::getStatusName($status);
$status = $commit->getAuditStatusObject();
$icon = $status->getIcon();
$color = $status->getColor();
$name = $status->getName();
$audit_view = id(new PHUIIconView())
->setIcon($icon, $color)

View file

@ -82,10 +82,10 @@ final class PhabricatorRepositoryCommitPHIDType extends PhabricatorPHIDType {
$handle->setURI($commit->getURI());
$handle->setTimestamp($commit->getEpoch());
$status = $commit->getAuditStatus();
$icon = PhabricatorAuditCommitStatusConstants::getStatusIcon($status);
$color = PhabricatorAuditCommitStatusConstants::getStatusColor($status);
$name = PhabricatorAuditCommitStatusConstants::getStatusName($status);
$status = $commit->getAuditStatusObject();
$icon = $status->getIcon();
$color = $status->getColor();
$name = $status->getName();
$handle
->setStateIcon($icon)

View file

@ -530,6 +530,11 @@ final class PhabricatorRepositoryCommit
return $data->getCommitDetail('authorPHID');
}
public function getAuditStatusObject() {
$status = $this->getAuditStatus();
return PhabricatorAuditCommitStatusConstants::newForLegacyStatus($status);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {