mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Differential - change "closed by commit" comment to real transaction
Summary: Implements a new transaction - still TYPE_ACTION - but using a new DifferentialAction::ACTION_COMMIT_CLOSE. Augment rendering as necessary to display this new transaction. Saves enough information so T3686 is possible but stops short of implementing a popup to display this information. Fixes T5875. Ref T3686. One small display oddity - this new transaction now renders at the top of the transaction group whereas when it was a comment it was on the bottom. I think this is basically okay but if not how fix? (Playing with the "strength" of these actions will mess up the email too?) Test Plan: made a diff X that fixed task Y. committed. checked diff X, task Y, and the commit pages for proper transactions and all looked good. Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T3686, T5875 Differential Revision: https://secure.phabricator.com/D10485
This commit is contained in:
parent
09fb5667cc
commit
e8985fc9e7
3 changed files with 180 additions and 114 deletions
|
@ -22,83 +22,83 @@ final class DifferentialAction {
|
||||||
|
|
||||||
public static function getBasicStoryText($action, $author_name) {
|
public static function getBasicStoryText($action, $author_name) {
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case DifferentialAction::ACTION_COMMENT:
|
case DifferentialAction::ACTION_COMMENT:
|
||||||
$title = pht('%s commented on this revision.',
|
$title = pht('%s commented on this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_ACCEPT:
|
case DifferentialAction::ACTION_ACCEPT:
|
||||||
$title = pht('%s accepted this revision.',
|
$title = pht('%s accepted this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_REJECT:
|
case DifferentialAction::ACTION_REJECT:
|
||||||
$title = pht('%s requested changes to this revision.',
|
$title = pht('%s requested changes to this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_RETHINK:
|
case DifferentialAction::ACTION_RETHINK:
|
||||||
$title = pht('%s planned changes to this revision.',
|
$title = pht('%s planned changes to this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_ABANDON:
|
case DifferentialAction::ACTION_ABANDON:
|
||||||
$title = pht('%s abandoned this revision.',
|
$title = pht('%s abandoned this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_CLOSE:
|
case DifferentialAction::ACTION_CLOSE:
|
||||||
$title = pht('%s closed this revision.',
|
$title = pht('%s closed this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_REQUEST:
|
case DifferentialAction::ACTION_REQUEST:
|
||||||
$title = pht('%s requested a review of this revision.',
|
$title = pht('%s requested a review of this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_RECLAIM:
|
case DifferentialAction::ACTION_RECLAIM:
|
||||||
$title = pht('%s reclaimed this revision.',
|
$title = pht('%s reclaimed this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_UPDATE:
|
case DifferentialAction::ACTION_UPDATE:
|
||||||
$title = pht('%s updated this revision.',
|
$title = pht('%s updated this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_RESIGN:
|
case DifferentialAction::ACTION_RESIGN:
|
||||||
$title = pht('%s resigned from this revision.',
|
$title = pht('%s resigned from this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_SUMMARIZE:
|
case DifferentialAction::ACTION_SUMMARIZE:
|
||||||
$title = pht('%s summarized this revision.',
|
$title = pht('%s summarized this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_TESTPLAN:
|
case DifferentialAction::ACTION_TESTPLAN:
|
||||||
$title = pht('%s explained the test plan for this revision.',
|
$title = pht('%s explained the test plan for this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_CREATE:
|
case DifferentialAction::ACTION_CREATE:
|
||||||
$title = pht('%s created this revision.',
|
$title = pht('%s created this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_ADDREVIEWERS:
|
case DifferentialAction::ACTION_ADDREVIEWERS:
|
||||||
$title = pht('%s added reviewers to this revision.',
|
$title = pht('%s added reviewers to this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_ADDCCS:
|
case DifferentialAction::ACTION_ADDCCS:
|
||||||
$title = pht('%s added CCs to this revision.',
|
$title = pht('%s added CCs to this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_CLAIM:
|
case DifferentialAction::ACTION_CLAIM:
|
||||||
$title = pht('%s commandeered this revision.',
|
$title = pht('%s commandeered this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialAction::ACTION_REOPEN:
|
case DifferentialAction::ACTION_REOPEN:
|
||||||
$title = pht('%s reopened this revision.',
|
$title = pht('%s reopened this revision.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
break;
|
||||||
case DifferentialTransaction::TYPE_INLINE:
|
case DifferentialTransaction::TYPE_INLINE:
|
||||||
$title = pht(
|
$title = pht(
|
||||||
'%s added an inline comment.',
|
'%s added an inline comment.',
|
||||||
$author_name);
|
$author_name);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$title = pht('Ghosts happened to this revision.');
|
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
|
$title = pht('Ghosts happened to this revision.');
|
||||||
|
break;
|
||||||
|
}
|
||||||
return $title;
|
return $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,18 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction {
|
||||||
$new = $this->getNewValue();
|
$new = $this->getNewValue();
|
||||||
|
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
|
case self::TYPE_ACTION:
|
||||||
|
if ($new == DifferentialAction::ACTION_CLOSE &&
|
||||||
|
$this->getMetadataValue('isCommitClose')) {
|
||||||
|
$phids[] = $this->getMetadataValue('commitPHID');
|
||||||
|
if ($this->getMetadataValue('committerPHID')) {
|
||||||
|
$phids[] = $this->getMetadataValue('committerPHID');
|
||||||
|
}
|
||||||
|
if ($this->getMetadataValue('authorPHID')) {
|
||||||
|
$phids[] = $this->getMetadataValue('authorPHID');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case self::TYPE_UPDATE:
|
case self::TYPE_UPDATE:
|
||||||
if ($new) {
|
if ($new) {
|
||||||
$phids[] = $new;
|
$phids[] = $new;
|
||||||
|
@ -216,7 +228,11 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction {
|
||||||
'%s added inline comments.',
|
'%s added inline comments.',
|
||||||
$author_handle);
|
$author_handle);
|
||||||
case self::TYPE_UPDATE:
|
case self::TYPE_UPDATE:
|
||||||
if ($new) {
|
if ($this->getMetadataValue('isCommitUpdate')) {
|
||||||
|
return pht(
|
||||||
|
'This revision was automatically updated to reflect the '.
|
||||||
|
'committed changes.');
|
||||||
|
} else if ($new) {
|
||||||
// TODO: Migrate to PHIDs and use handles here?
|
// TODO: Migrate to PHIDs and use handles here?
|
||||||
if (phid_get_type($new) == DifferentialDiffPHIDType::TYPECONST) {
|
if (phid_get_type($new) == DifferentialDiffPHIDType::TYPECONST) {
|
||||||
return pht(
|
return pht(
|
||||||
|
@ -234,7 +250,45 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction {
|
||||||
$author_handle);
|
$author_handle);
|
||||||
}
|
}
|
||||||
case self::TYPE_ACTION:
|
case self::TYPE_ACTION:
|
||||||
return DifferentialAction::getBasicStoryText($new, $author_handle);
|
switch ($new) {
|
||||||
|
case DifferentialAction::ACTION_CLOSE:
|
||||||
|
if (!$this->getMetadataValue('isCommitClose')) {
|
||||||
|
return DifferentialAction::getBasicStoryText(
|
||||||
|
$new,
|
||||||
|
$author_handle);
|
||||||
|
}
|
||||||
|
$commit_name = $this->renderHandleLink(
|
||||||
|
$this->getMetadataValue('commitPHID'));
|
||||||
|
$committer_phid = $this->getMetadataValue('committerPHID');
|
||||||
|
$author_phid = $this->getMetadataValue('authorPHID');
|
||||||
|
if ($this->getHandleIfExists($committer_phid)) {
|
||||||
|
$committer_name = $this->renderHandleLink($committer_phid);
|
||||||
|
} else {
|
||||||
|
$committer_name = $this->getMetadataValue('committerName');
|
||||||
|
}
|
||||||
|
if ($this->getHandleIfExists($author_phid)) {
|
||||||
|
$author_name = $this->renderHandleLink($author_phid);
|
||||||
|
} else {
|
||||||
|
$author_name = $this->getMetadataValue('authorName');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($committer_name && ($committer_name != $author_name)) {
|
||||||
|
return pht(
|
||||||
|
'Closed by commit %s (authored by %s, committed by %s).',
|
||||||
|
$commit_name,
|
||||||
|
$author_name,
|
||||||
|
$committer_name);
|
||||||
|
} else {
|
||||||
|
return pht(
|
||||||
|
'Closed by commit %s (authored by %s).',
|
||||||
|
$commit_name,
|
||||||
|
$author_name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return DifferentialAction::getBasicStoryText($new, $author_handle);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case self::TYPE_STATUS:
|
case self::TYPE_STATUS:
|
||||||
switch ($this->getNewValue()) {
|
switch ($this->getNewValue()) {
|
||||||
case ArcanistDifferentialRevisionStatus::ACCEPTED:
|
case ArcanistDifferentialRevisionStatus::ACCEPTED:
|
||||||
|
@ -296,10 +350,44 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction {
|
||||||
$author_link,
|
$author_link,
|
||||||
$object_link);
|
$object_link);
|
||||||
case DifferentialAction::ACTION_CLOSE:
|
case DifferentialAction::ACTION_CLOSE:
|
||||||
return pht(
|
if (!$this->getMetadataValue('isCommitClose')) {
|
||||||
'%s closed %s.',
|
return pht(
|
||||||
$author_link,
|
'%s closed %s.',
|
||||||
$object_link);
|
$author_link,
|
||||||
|
$object_link);
|
||||||
|
} else {
|
||||||
|
$commit_name = $this->renderHandleLink(
|
||||||
|
$this->getMetadataValue('commitPHID'));
|
||||||
|
$committer_phid = $this->getMetadataValue('committerPHID');
|
||||||
|
$author_phid = $this->getMetadataValue('authorPHID');
|
||||||
|
if ($this->getHandleIfExists($committer_phid)) {
|
||||||
|
$committer_name = $this->renderHandleLink($committer_phid);
|
||||||
|
} else {
|
||||||
|
$committer_name = $this->getMetadataValue('committerName');
|
||||||
|
}
|
||||||
|
if ($this->getHandleIfExists($author_phid)) {
|
||||||
|
$author_name = $this->renderHandleLink($author_phid);
|
||||||
|
} else {
|
||||||
|
$author_name = $this->getMetadataValue('authorName');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($committer_name && ($committer_name != $author_name)) {
|
||||||
|
return pht(
|
||||||
|
'%s closed %s by commit %s (authored by %s).',
|
||||||
|
$author_link,
|
||||||
|
$object_link,
|
||||||
|
$commit_name,
|
||||||
|
$author_name);
|
||||||
|
} else {
|
||||||
|
return pht(
|
||||||
|
'%s closed %s by commit %s.',
|
||||||
|
$author_link,
|
||||||
|
$object_link,
|
||||||
|
$commit_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case DifferentialAction::ACTION_REQUEST:
|
case DifferentialAction::ACTION_REQUEST:
|
||||||
return pht(
|
return pht(
|
||||||
'%s requested review of %s.',
|
'%s requested review of %s.',
|
||||||
|
|
|
@ -140,31 +140,29 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
||||||
$should_autoclose;
|
$should_autoclose;
|
||||||
|
|
||||||
if ($should_close) {
|
if ($should_close) {
|
||||||
$commit_name = $repository->formatCommitName(
|
$commit_close_xaction = id(new DifferentialTransaction())
|
||||||
$commit->getCommitIdentifier());
|
->setTransactionType(DifferentialTransaction::TYPE_ACTION)
|
||||||
|
->setNewValue(DifferentialAction::ACTION_CLOSE)
|
||||||
|
->setMetadataValue('isCommitClose', true);
|
||||||
|
|
||||||
$committer_name = $this->loadUserName(
|
$commit_close_xaction->setMetadataValue(
|
||||||
$committer_phid,
|
'commitPHID',
|
||||||
$data->getCommitDetail('committer'),
|
$commit->getPHID());
|
||||||
$actor);
|
$commit_close_xaction->setMetadataValue(
|
||||||
|
'committerPHID',
|
||||||
$author_name = $this->loadUserName(
|
$committer_phid);
|
||||||
$author_phid,
|
$commit_close_xaction->setMetadataValue(
|
||||||
$data->getAuthorName(),
|
'committerName',
|
||||||
$actor);
|
$data->getCommitDetail('committer'));
|
||||||
|
$commit_close_xaction->setMetadataValue(
|
||||||
if ($committer_name && ($committer_name != $author_name)) {
|
'authorPHID',
|
||||||
$revision_update_comment = pht(
|
$author_phid);
|
||||||
'Closed by commit %s (authored by %s, committed by %s).',
|
$commit_close_xaction->setMetadataValue(
|
||||||
$commit_name,
|
'authorName',
|
||||||
$author_name,
|
$data->getAuthorName());
|
||||||
$committer_name);
|
$commit_close_xaction->setMetadataValue(
|
||||||
} else {
|
'commitHashes',
|
||||||
$revision_update_comment = pht(
|
$hashes);
|
||||||
'Closed by commit %s (authored by %s).',
|
|
||||||
$commit_name,
|
|
||||||
$author_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$diff = $this->generateFinalDiff($revision, $acting_as_phid);
|
$diff = $this->generateFinalDiff($revision, $acting_as_phid);
|
||||||
|
|
||||||
|
@ -181,22 +179,12 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
||||||
}
|
}
|
||||||
|
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
|
|
||||||
$xactions[] = id(new DifferentialTransaction())
|
|
||||||
->setTransactionType(DifferentialTransaction::TYPE_ACTION)
|
|
||||||
->setNewValue(DifferentialAction::ACTION_CLOSE);
|
|
||||||
|
|
||||||
$xactions[] = id(new DifferentialTransaction())
|
$xactions[] = id(new DifferentialTransaction())
|
||||||
->setTransactionType(DifferentialTransaction::TYPE_UPDATE)
|
->setTransactionType(DifferentialTransaction::TYPE_UPDATE)
|
||||||
->setIgnoreOnNoEffect(true)
|
->setIgnoreOnNoEffect(true)
|
||||||
->setNewValue($diff->getPHID());
|
->setNewValue($diff->getPHID())
|
||||||
|
->setMetadataValue('isCommitUpdate', true);
|
||||||
$xactions[] = id(new DifferentialTransaction())
|
$xactions[] = $commit_close_xaction;
|
||||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
||||||
->setIgnoreOnNoEffect(true)
|
|
||||||
->attachComment(
|
|
||||||
id(new DifferentialTransactionComment())
|
|
||||||
->setContent($revision_update_comment));
|
|
||||||
|
|
||||||
$content_source = PhabricatorContentSource::newForSource(
|
$content_source = PhabricatorContentSource::newForSource(
|
||||||
PhabricatorContentSource::SOURCE_DAEMON,
|
PhabricatorContentSource::SOURCE_DAEMON,
|
||||||
|
@ -237,18 +225,6 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
||||||
PhabricatorRepositoryCommit::IMPORTED_MESSAGE);
|
PhabricatorRepositoryCommit::IMPORTED_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadUserName($user_phid, $default, PhabricatorUser $actor) {
|
|
||||||
if (!$user_phid) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
$handle = id(new PhabricatorHandleQuery())
|
|
||||||
->setViewer($actor)
|
|
||||||
->withPHIDs(array($user_phid))
|
|
||||||
->executeOne();
|
|
||||||
|
|
||||||
return '@'.$handle->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function generateFinalDiff(
|
private function generateFinalDiff(
|
||||||
DifferentialRevision $revision,
|
DifferentialRevision $revision,
|
||||||
$actor_phid) {
|
$actor_phid) {
|
||||||
|
@ -521,6 +497,8 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
||||||
->setActingAsPHID($acting_as)
|
->setActingAsPHID($acting_as)
|
||||||
->setContinueOnNoEffect(true)
|
->setContinueOnNoEffect(true)
|
||||||
->setContinueOnMissingFields(true)
|
->setContinueOnMissingFields(true)
|
||||||
|
->setUnmentionablePHIDMap(
|
||||||
|
array($commit->getPHID() => $commit->getPHID()))
|
||||||
->setContentSource($content_source);
|
->setContentSource($content_source);
|
||||||
|
|
||||||
$editor->applyTransactions($task, $xactions);
|
$editor->applyTransactions($task, $xactions);
|
||||||
|
|
Loading…
Reference in a new issue