1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-22 19:49:02 +01:00

Use repository identities, not denormalized strings, to identify authors for "Revision closed by commit X" stories

Summary:
Ref T12164. Ref T13276. Currently, the parsing pipeline copies the author and committer names and PHIDs into the transcaction record as metadata. They are then rendered directly from the metadata.

This makes planned changes to the parsing pipeline (to prevent races when multiple commits matching a single revision are pushed simultaneously) more difficult, and generally won't work with repository identities.

Instead, load the commit and use its identities.

Test Plan: Loaded a revision, saw the same story rendering for a "Closed by commit" story.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13276, T12164

Differential Revision: https://secure.phabricator.com/D20418
This commit is contained in:
epriestley 2019-04-14 10:46:20 -07:00
parent 9532bfbb32
commit 5b6d6c4fb3
3 changed files with 30 additions and 53 deletions

View file

@ -83,49 +83,41 @@ final class DifferentialRevisionCloseTransaction
}
public function getTitle() {
if (!$this->getMetadataValue('isCommitClose')) {
$commit_phid = $this->getMetadataValue('commitPHID');
if ($commit_phid) {
$commit = id(new DiffusionCommitQuery())
->setViewer($this->getViewer())
->withPHIDs(array($commit_phid))
->needIdentities(true)
->executeOne();
} else {
$commit = null;
}
if (!$commit) {
return pht(
'%s closed this revision.',
$this->renderAuthor());
}
$commit_phid = $this->getMetadataValue('commitPHID');
$committer_phid = $this->getMetadataValue('committerPHID');
$author_phid = $this->getMetadataValue('authorPHID');
$author_phid = $commit->getAuthorDisplayPHID();
$committer_phid = $commit->getCommitterDisplayPHID();
if ($committer_phid) {
$committer_name = $this->renderHandle($committer_phid);
} else {
$committer_name = $this->getMetadataValue('committerName');
}
if ($author_phid) {
$author_name = $this->renderHandle($author_phid);
} else {
$author_name = $this->getMetadatavalue('authorName');
}
$same_phid =
strlen($committer_phid) &&
strlen($author_phid) &&
($committer_phid == $author_phid);
$same_name =
!strlen($committer_phid) &&
!strlen($author_phid) &&
($committer_name == $author_name);
if ($same_name || $same_phid) {
if (!$author_phid) {
return pht(
'Closed by commit %s.',
$this->renderHandle($commit_phid));
} else if (!$committer_phid || ($committer_phid === $author_phid)) {
return pht(
'Closed by commit %s (authored by %s).',
$this->renderHandle($commit_phid),
$author_name);
$this->renderHandle($author_phid));
} else {
return pht(
'Closed by commit %s (authored by %s, committed by %s).',
$this->renderHandle($commit_phid),
$author_name,
$committer_name);
$this->renderHandle($author_phid),
$this->renderHandle($committer_phid));
}
}

View file

@ -241,7 +241,6 @@ final class PhabricatorRepositoryManagementUnpublishWorkflow
if ($xactions) {
foreach ($xactions as $xaction) {
$metadata = $xaction->getMetadata();
if (idx($metadata, 'isCommitClose')) {
if (idx($metadata, 'commitPHID') === $src->getPHID()) {
echo tsprintf(
"%s\n",
@ -253,7 +252,6 @@ final class PhabricatorRepositoryManagementUnpublishWorkflow
}
}
}
}
if (!$is_dry_run) {
id(new PhabricatorEdgeEditor())

View file

@ -244,24 +244,11 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
$commit_close_xaction = id(new DifferentialTransaction())
->setTransactionType($type_close)
->setNewValue(true)
->setMetadataValue('isCommitClose', true);
->setNewValue(true);
$commit_close_xaction->setMetadataValue(
'commitPHID',
$commit->getPHID());
$commit_close_xaction->setMetadataValue(
'committerPHID',
$committer_phid);
$commit_close_xaction->setMetadataValue(
'committerName',
$data->getCommitDetail('committer'));
$commit_close_xaction->setMetadataValue(
'authorPHID',
$author_phid);
$commit_close_xaction->setMetadataValue(
'authorName',
$data->getAuthorName());
if ($low_level_query) {
$commit_close_xaction->setMetadataValue(