mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 10:12:41 +01:00
Modernize "Author" and "Committer" rendering for commits
Summary: Ref T13552. Give "Commit" objects a more modern, identity-aware way to render author and committer information. This uses handles in a more modern way and gives us a single read callsite for raw author and committer names. Test Plan: - Grepped for callers to the old methods, found none. (There are a lot of "renderAuthor()" callers in transactions, but this call takes no parameters.) - Viewed some commits, saw sensible lists of authors and committers. Maniphest Tasks: T13552 Differential Revision: https://secure.phabricator.com/D21405
This commit is contained in:
parent
81e4e5b7f9
commit
7fd6bf26a9
3 changed files with 98 additions and 76 deletions
|
@ -90,11 +90,6 @@ final class PhabricatorAuditListView extends AphrontView {
|
||||||
foreach ($commit->getAudits() as $audit) {
|
foreach ($commit->getAudits() as $audit) {
|
||||||
$phids[] = $audit->getAuditorPHID();
|
$phids[] = $audit->getAuditorPHID();
|
||||||
}
|
}
|
||||||
|
|
||||||
$author_phid = $commit->getAuthorPHID();
|
|
||||||
if ($author_phid) {
|
|
||||||
$phids[] = $author_phid;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$handles = $viewer->loadHandles($phids);
|
$handles = $viewer->loadHandles($phids);
|
||||||
|
@ -126,21 +121,18 @@ final class PhabricatorAuditListView extends AphrontView {
|
||||||
$status_color = $status->getColor();
|
$status_color = $status->getColor();
|
||||||
$status_icon = $status->getIcon();
|
$status_icon = $status->getIcon();
|
||||||
|
|
||||||
$author_phid = $commit->getAuthorPHID();
|
|
||||||
if ($author_phid) {
|
|
||||||
$author_name = $handles[$author_phid]->renderLink();
|
|
||||||
} else {
|
|
||||||
$author_name = $commit->getCommitData()->getAuthorName();
|
|
||||||
}
|
|
||||||
|
|
||||||
$item = id(new PHUIObjectItemView())
|
$item = id(new PHUIObjectItemView())
|
||||||
->setObjectName($commit_name)
|
->setObjectName($commit_name)
|
||||||
->setHeader($commit_desc)
|
->setHeader($commit_desc)
|
||||||
->setHref($commit_link)
|
->setHref($commit_link)
|
||||||
->setDisabled($commit->isUnreachable())
|
->setDisabled($commit->isUnreachable())
|
||||||
->addByline(pht('Author: %s', $author_name))
|
|
||||||
->addIcon('none', $committed);
|
->addIcon('none', $committed);
|
||||||
|
|
||||||
|
$author_name = $commit->newCommitAuthorView($viewer);
|
||||||
|
if ($author_name) {
|
||||||
|
$item->addByline(pht('Author: %s', $author_name));
|
||||||
|
}
|
||||||
|
|
||||||
if ($show_drafts) {
|
if ($show_drafts) {
|
||||||
if ($commit->getHasDraft($viewer)) {
|
if ($commit->getHasDraft($viewer)) {
|
||||||
$item->addAttribute($draft_icon);
|
$item->addAttribute($draft_icon);
|
||||||
|
|
|
@ -625,32 +625,49 @@ final class DiffusionCommitController extends DiffusionController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$author_epoch = $data->getCommitDetail('authorEpoch');
|
$provenance_list = new PHUIStatusListView();
|
||||||
|
|
||||||
$committed_info = id(new PHUIStatusItemView())
|
$author_view = $commit->newCommitAuthorView($viewer);
|
||||||
->setNote(phabricator_datetime($commit->getEpoch(), $viewer))
|
if ($author_view) {
|
||||||
->setTarget($commit->renderAnyCommitter($viewer, $handles));
|
$author_date = $data->getCommitDetail('authorEpoch');
|
||||||
|
$author_date = phabricator_datetime($author_date, $viewer);
|
||||||
|
|
||||||
$committed_list = new PHUIStatusListView();
|
$provenance_list->addItem(
|
||||||
$committed_list->addItem($committed_info);
|
id(new PHUIStatusItemView())
|
||||||
$view->addProperty(
|
->setTarget($author_view)
|
||||||
pht('Committed'),
|
->setNote(pht('Authored on %s', $author_date)));
|
||||||
$committed_list);
|
}
|
||||||
|
|
||||||
|
if (!$commit->isAuthorSameAsCommitter()) {
|
||||||
|
$committer_view = $commit->newCommitCommitterView($viewer);
|
||||||
|
if ($committer_view) {
|
||||||
|
$committer_date = $commit->getEpoch();
|
||||||
|
$committer_date = phabricator_datetime($committer_date, $viewer);
|
||||||
|
|
||||||
|
$provenance_list->addItem(
|
||||||
|
id(new PHUIStatusItemView())
|
||||||
|
->setTarget($committer_view)
|
||||||
|
->setNote(pht('Committed on %s', $committer_date)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($push_logs) {
|
if ($push_logs) {
|
||||||
$pushed_list = new PHUIStatusListView();
|
$pushed_list = new PHUIStatusListView();
|
||||||
|
|
||||||
foreach ($push_logs as $push_log) {
|
foreach ($push_logs as $push_log) {
|
||||||
$pushed_item = id(new PHUIStatusItemView())
|
$pusher_date = $push_log->getEpoch();
|
||||||
->setTarget($handles[$push_log->getPusherPHID()]->renderLink())
|
$pusher_date = phabricator_datetime($pusher_date, $viewer);
|
||||||
->setNote(phabricator_datetime($push_log->getEpoch(), $viewer));
|
|
||||||
$pushed_list->addItem($pushed_item);
|
$pusher_view = $handles[$push_log->getPusherPHID()]->renderLink();
|
||||||
|
|
||||||
|
$provenance_list->addItem(
|
||||||
|
id(new PHUIStatusItemView())
|
||||||
|
->setTarget($pusher_view)
|
||||||
|
->setNote(pht('Pushed on %s', $pusher_date)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$view->addProperty(
|
$view->addProperty(pht('Provenance'), $provenance_list);
|
||||||
pht('Pushed'),
|
|
||||||
$pushed_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
$reviewer_phid = $data->getCommitDetail('reviewerPHID');
|
$reviewer_phid = $data->getCommitDetail('reviewerPHID');
|
||||||
if ($reviewer_phid) {
|
if ($reviewer_phid) {
|
||||||
|
|
|
@ -377,52 +377,6 @@ final class PhabricatorRepositoryCommit
|
||||||
return $repository->formatCommitName($identifier, $local = true);
|
return $repository->formatCommitName($identifier, $local = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Make a strong effort to find a way to render this commit's committer.
|
|
||||||
* This currently attempts to use @{PhabricatorRepositoryIdentity}, and
|
|
||||||
* falls back to examining the commit detail information. After we force
|
|
||||||
* the migration to using identities, update this method to remove the
|
|
||||||
* fallback. See T12164 for details.
|
|
||||||
*/
|
|
||||||
public function renderAnyCommitter(PhabricatorUser $viewer, $handles) {
|
|
||||||
$committer = $this->renderCommitter($viewer, $handles);
|
|
||||||
if ($committer) {
|
|
||||||
return $committer;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->renderAuthor($viewer, $handles);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function renderCommitter(PhabricatorUser $viewer, $handles) {
|
|
||||||
$committer_phid = $this->getCommitterDisplayPHID();
|
|
||||||
if ($committer_phid) {
|
|
||||||
return $handles[$committer_phid]->renderLink();
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $this->getCommitData();
|
|
||||||
$committer_name = $data->getCommitDetail('committer');
|
|
||||||
if (strlen($committer_name)) {
|
|
||||||
return DiffusionView::renderName($committer_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function renderAuthor(PhabricatorUser $viewer, $handles) {
|
|
||||||
$author_phid = $this->getAuthorDisplayPHID();
|
|
||||||
if ($author_phid) {
|
|
||||||
return $handles[$author_phid]->renderLink();
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $this->getCommitData();
|
|
||||||
$author_name = $data->getAuthorName();
|
|
||||||
if (strlen($author_name)) {
|
|
||||||
return DiffusionView::renderName($author_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function loadIdentities(PhabricatorUser $viewer) {
|
public function loadIdentities(PhabricatorUser $viewer) {
|
||||||
if ($this->authorIdentity !== self::ATTACHABLE) {
|
if ($this->authorIdentity !== self::ATTACHABLE) {
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -511,6 +465,65 @@ final class PhabricatorRepositoryCommit
|
||||||
return (bool)$this->isPartiallyImported(self::IMPORTED_CLOSEABLE);
|
return (bool)$this->isPartiallyImported(self::IMPORTED_CLOSEABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newCommitAuthorView(PhabricatorUser $viewer) {
|
||||||
|
$author_phid = $this->getAuthorDisplayPHID();
|
||||||
|
if ($author_phid) {
|
||||||
|
$handles = $viewer->loadHandles(array($author_phid));
|
||||||
|
return $handles[$author_phid]->renderLink();
|
||||||
|
}
|
||||||
|
|
||||||
|
$author = $this->getRawAuthorStringForDisplay();
|
||||||
|
if (strlen($author)) {
|
||||||
|
return DiffusionView::renderName($author);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function newCommitCommitterView(PhabricatorUser $viewer) {
|
||||||
|
$committer_phid = $this->getCommitterDisplayPHID();
|
||||||
|
if ($committer_phid) {
|
||||||
|
$handles = $viewer->loadHandles(array($committer_phid));
|
||||||
|
return $handles[$committer_phid]->renderLink();
|
||||||
|
}
|
||||||
|
|
||||||
|
$committer = $this->getRawCommitterStringForDisplay();
|
||||||
|
if (strlen($committer)) {
|
||||||
|
return DiffusionView::renderName($committer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isAuthorSameAsCommitter() {
|
||||||
|
$author_phid = $this->getAuthorDisplayPHID();
|
||||||
|
$committer_phid = $this->getCommitterDisplayPHID();
|
||||||
|
|
||||||
|
if ($author_phid && $committer_phid) {
|
||||||
|
return ($author_phid === $committer_phid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($author_phid || $committer_phid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$author = $this->getRawAuthorStringForDisplay();
|
||||||
|
$committer = $this->getRawCommitterStringForDisplay();
|
||||||
|
|
||||||
|
return ($author === $committer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getRawAuthorStringForDisplay() {
|
||||||
|
$data = $this->getCommitData();
|
||||||
|
return $data->getAuthorName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getRawCommitterStringForDisplay() {
|
||||||
|
$data = $this->getCommitData();
|
||||||
|
return $data->getCommitDetail('committer');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
public function getCapabilities() {
|
public function getCapabilities() {
|
||||||
|
|
Loading…
Reference in a new issue