mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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:
parent
ab4d33bede
commit
a1ce23b9f5
6 changed files with 66 additions and 22 deletions
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
final class PhabricatorAuditCommitStatusConstants extends Phobject {
|
final class PhabricatorAuditCommitStatusConstants extends Phobject {
|
||||||
|
|
||||||
|
private $key;
|
||||||
|
private $spec = array();
|
||||||
|
|
||||||
const NONE = 0;
|
const NONE = 0;
|
||||||
const NEEDS_AUDIT = 1;
|
const NEEDS_AUDIT = 1;
|
||||||
const CONCERN_RAISED = 2;
|
const CONCERN_RAISED = 2;
|
||||||
|
@ -16,6 +19,47 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
|
||||||
const MODERN_AUDITED = 'audited';
|
const MODERN_AUDITED = 'audited';
|
||||||
const MODERN_NEEDS_VERIFICATION = 'needs-verification';
|
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() {
|
public static function getStatusNameMap() {
|
||||||
$map = self::getMap();
|
$map = self::getMap();
|
||||||
return ipull($map, 'name', 'legacy');
|
return ipull($map, 'name', 'legacy');
|
||||||
|
|
|
@ -30,11 +30,11 @@ final class PhabricatorAuditSynchronizeManagementWorkflow
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$old_status = $commit->getAuditStatus();
|
$old_status = $commit->getAuditStatusObject();
|
||||||
$commit->updateAuditStatus($commit->getAudits());
|
$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(
|
echo tsprintf(
|
||||||
"%s\n",
|
"%s\n",
|
||||||
pht(
|
pht(
|
||||||
|
@ -46,10 +46,8 @@ final class PhabricatorAuditSynchronizeManagementWorkflow
|
||||||
pht(
|
pht(
|
||||||
'Updating "%s": "%s" -> "%s".',
|
'Updating "%s": "%s" -> "%s".',
|
||||||
$commit->getDisplayName(),
|
$commit->getDisplayName(),
|
||||||
PhabricatorAuditCommitStatusConstants::getStatusName(
|
$old_status->getName(),
|
||||||
$old_status),
|
$new_status->getName()));
|
||||||
PhabricatorAuditCommitStatusConstants::getStatusName(
|
|
||||||
$new_status)));
|
|
||||||
|
|
||||||
$commit->save();
|
$commit->save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,14 +120,11 @@ final class PhabricatorAuditListView extends AphrontView {
|
||||||
$commit_desc = $this->getCommitDescription($commit_phid);
|
$commit_desc = $this->getCommitDescription($commit_phid);
|
||||||
$committed = phabricator_datetime($commit->getEpoch(), $viewer);
|
$committed = phabricator_datetime($commit->getEpoch(), $viewer);
|
||||||
|
|
||||||
$status = $commit->getAuditStatus();
|
$status = $commit->getAuditStatusObject();
|
||||||
|
|
||||||
$status_text =
|
$status_text = $status->getName();
|
||||||
PhabricatorAuditCommitStatusConstants::getStatusName($status);
|
$status_color = $status->getColor();
|
||||||
$status_color =
|
$status_icon = $status->getIcon();
|
||||||
PhabricatorAuditCommitStatusConstants::getStatusColor($status);
|
|
||||||
$status_icon =
|
|
||||||
PhabricatorAuditCommitStatusConstants::getStatusIcon($status);
|
|
||||||
|
|
||||||
$author_phid = $commit->getAuthorPHID();
|
$author_phid = $commit->getAuthorPHID();
|
||||||
if ($author_phid) {
|
if ($author_phid) {
|
||||||
|
|
|
@ -114,10 +114,10 @@ final class DiffusionHistoryTableView extends DiffusionHistoryView {
|
||||||
'type' => $history->getFileType(),
|
'type' => $history->getFileType(),
|
||||||
));
|
));
|
||||||
|
|
||||||
$status = $commit->getAuditStatus();
|
$status = $commit->getAuditStatusObject();
|
||||||
$icon = PhabricatorAuditCommitStatusConstants::getStatusIcon($status);
|
$icon = $status->getIcon();
|
||||||
$color = PhabricatorAuditCommitStatusConstants::getStatusColor($status);
|
$color = $status->getColor();
|
||||||
$name = PhabricatorAuditCommitStatusConstants::getStatusName($status);
|
$name = $status->getName();
|
||||||
|
|
||||||
$audit_view = id(new PHUIIconView())
|
$audit_view = id(new PHUIIconView())
|
||||||
->setIcon($icon, $color)
|
->setIcon($icon, $color)
|
||||||
|
|
|
@ -82,10 +82,10 @@ final class PhabricatorRepositoryCommitPHIDType extends PhabricatorPHIDType {
|
||||||
$handle->setURI($commit->getURI());
|
$handle->setURI($commit->getURI());
|
||||||
$handle->setTimestamp($commit->getEpoch());
|
$handle->setTimestamp($commit->getEpoch());
|
||||||
|
|
||||||
$status = $commit->getAuditStatus();
|
$status = $commit->getAuditStatusObject();
|
||||||
$icon = PhabricatorAuditCommitStatusConstants::getStatusIcon($status);
|
$icon = $status->getIcon();
|
||||||
$color = PhabricatorAuditCommitStatusConstants::getStatusColor($status);
|
$color = $status->getColor();
|
||||||
$name = PhabricatorAuditCommitStatusConstants::getStatusName($status);
|
$name = $status->getName();
|
||||||
|
|
||||||
$handle
|
$handle
|
||||||
->setStateIcon($icon)
|
->setStateIcon($icon)
|
||||||
|
|
|
@ -530,6 +530,11 @@ final class PhabricatorRepositoryCommit
|
||||||
return $data->getCommitDetail('authorPHID');
|
return $data->getCommitDetail('authorPHID');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAuditStatusObject() {
|
||||||
|
$status = $this->getAuditStatus();
|
||||||
|
return PhabricatorAuditCommitStatusConstants::newForLegacyStatus($status);
|
||||||
|
}
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
public function getCapabilities() {
|
public function getCapabilities() {
|
||||||
|
|
Loading…
Reference in a new issue