diff --git a/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php b/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php index cbb7d657af..62f2731064 100644 --- a/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php @@ -200,15 +200,27 @@ abstract class DifferentialFreeformFieldSpecification $message = $this->renderValueForCommitMessage($is_edit = false); - $commits = self::findRevertedCommits($message); - $user = id(new PhabricatorUser())->loadOneWhere( 'phid = %s', $data->getCommitDetail('authorPHID')); if (!$user) { + // TODO: Maybe after grey users, we should find a way to proceed even + // if we don't know who the author is. return; } + $commit_names = self::findRevertedCommits($message); + if ($commit_names) { + $reverts = id(new DiffusionCommitQuery()) + ->setViewer($user) + ->withIdentifiers($commit_names) + ->withDefaultRepository($repository) + ->execute(); + foreach ($reverts as $revert) { + // TODO: Do interesting things here. + } + } + $tasks_statuses = $this->findMentionedTasks($message); if (!$tasks_statuses) { return; diff --git a/src/applications/diffusion/query/DiffusionCommitQuery.php b/src/applications/diffusion/query/DiffusionCommitQuery.php index 789aeb1f59..c9f757aee8 100644 --- a/src/applications/diffusion/query/DiffusionCommitQuery.php +++ b/src/applications/diffusion/query/DiffusionCommitQuery.php @@ -5,6 +5,7 @@ final class DiffusionCommitQuery private $identifiers; private $phids; + private $defaultRepository; /** * Load commits by partial or full identifiers, e.g. "rXab82393", "rX1234", @@ -17,6 +18,20 @@ final class DiffusionCommitQuery return $this; } + /** + * If a default repository is provided, ambiguous commit identifiers will + * be assumed to belong to the default repository. + * + * For example, "r123" appearing in a commit message in repository X is + * likely to be unambiguously "rX123". Normally the reference would be + * considered ambiguous, but if you provide a default repository it will + * be correctly resolved. + */ + public function withDefaultRepository(PhabricatorRepository $repository) { + $this->defaultRepository = $repository; + return $this; + } + public function withPHIDs(array $phids) { $this->phids = $phids; return $this; @@ -75,6 +90,12 @@ final class DiffusionCommitQuery $repo = nonempty($matches[1], null); $identifier = nonempty($matches[2], null); + if ($repo === null) { + if ($this->defaultRepository) { + $repo = $this->defaultRepository->getCallsign(); + } + } + if ($repo === null) { if (strlen($identifier) < $min_unqualified) { continue;