Provide a real object ("PhabricatorRepositoryPushEvent") to represent an entire push transaction
Summary: Ref T4677. Currently, we record individual actions in a push as PhabricatorRepositoryPushLogs, but tie them together only loosely with a `transactionKey`. Provide a real PushEvent object, and move some of the denormalized fields to it. This primarily just gives us more robust infrastructure for building, e.g., email about pushes, for T4677, since we can act on real PHIDs rather than passing awkward identifiers around. Test Plan: - Performed migration. - Looked at database for consistency. - Browsed/queried push logs. - Pushed a bunch of stuff. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4677 Differential Revision: https://secure.phabricator.com/D8615
This commit is contained in:
@@ -30,6 +30,8 @@ final class DiffusionCommitHookEngine extends Phobject {
|
||||
private $gitCommits = array();
|
||||
|
||||
private $heraldViewerProjects;
|
||||
private $rejectCode = PhabricatorRepositoryPushLog::REJECT_BROKEN;
|
||||
private $rejectDetails;
|
||||
|
||||
|
||||
/* -( Config )------------------------------------------------------------- */
|
||||
@@ -62,14 +64,6 @@ final class DiffusionCommitHookEngine extends Phobject {
|
||||
return $remote_address;
|
||||
}
|
||||
|
||||
private function getTransactionKey() {
|
||||
if (!$this->transactionKey) {
|
||||
$entropy = Filesystem::readRandomBytes(64);
|
||||
$this->transactionKey = PhabricatorHash::digestForIndex($entropy);
|
||||
}
|
||||
return $this->transactionKey;
|
||||
}
|
||||
|
||||
public function setSubversionTransactionInfo($transaction, $repository) {
|
||||
$this->subversionTransaction = $transaction;
|
||||
$this->subversionRepository = $repository;
|
||||
@@ -137,10 +131,7 @@ final class DiffusionCommitHookEngine extends Phobject {
|
||||
} catch (DiffusionCommitHookRejectException $ex) {
|
||||
// If we're rejecting dangerous changes, flag everything that we've
|
||||
// seen as rejected so it's clear that none of it was accepted.
|
||||
foreach ($all_updates as $update) {
|
||||
$update->setRejectCode(
|
||||
PhabricatorRepositoryPushLog::REJECT_DANGEROUS);
|
||||
}
|
||||
$this->rejectCode = PhabricatorRepositoryPushLog::REJECT_DANGEROUS;
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
@@ -156,9 +147,7 @@ final class DiffusionCommitHookEngine extends Phobject {
|
||||
|
||||
// If we make it this far, we're accepting these changes. Mark all the
|
||||
// logs as accepted.
|
||||
foreach ($all_updates as $update) {
|
||||
$update->setRejectCode(PhabricatorRepositoryPushLog::REJECT_ACCEPT);
|
||||
}
|
||||
$this->rejectCode = PhabricatorRepositoryPushLog::REJECT_ACCEPT;
|
||||
} catch (Exception $ex) {
|
||||
// We'll throw this again in a minute, but we want to save all the logs
|
||||
// first.
|
||||
@@ -166,9 +155,18 @@ final class DiffusionCommitHookEngine extends Phobject {
|
||||
}
|
||||
|
||||
// Save all the logs no matter what the outcome was.
|
||||
foreach ($all_updates as $update) {
|
||||
$update->save();
|
||||
}
|
||||
$event = $this->newPushEvent();
|
||||
|
||||
$event->setRejectCode($this->rejectCode);
|
||||
$event->setRejectDetails($this->rejectDetails);
|
||||
|
||||
$event->openTransaction();
|
||||
$event->save();
|
||||
foreach ($all_updates as $update) {
|
||||
$update->setPushEventPHID($event->getPHID());
|
||||
$update->save();
|
||||
}
|
||||
$event->saveTransaction();
|
||||
|
||||
if ($caught) {
|
||||
throw $caught;
|
||||
@@ -296,10 +294,8 @@ final class DiffusionCommitHookEngine extends Phobject {
|
||||
}
|
||||
|
||||
if ($blocking_effect) {
|
||||
foreach ($all_updates as $update) {
|
||||
$update->setRejectCode(PhabricatorRepositoryPushLog::REJECT_HERALD);
|
||||
$update->setRejectDetails($blocking_effect->getRulePHID());
|
||||
}
|
||||
$this->rejectCode = PhabricatorRepositoryPushLog::REJECT_HERALD;
|
||||
$this->rejectDetails = $blocking_effect->getRulePHID();
|
||||
|
||||
$message = $blocking_effect->getTarget();
|
||||
if (!strlen($message)) {
|
||||
@@ -596,12 +592,8 @@ final class DiffusionCommitHookEngine extends Phobject {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mark everything as rejected by this hook.
|
||||
foreach ($updates as $update) {
|
||||
$update->setRejectCode(
|
||||
PhabricatorRepositoryPushLog::REJECT_EXTERNAL);
|
||||
$update->setRejectDetails(basename($hook));
|
||||
}
|
||||
$this->rejectCode = PhabricatorRepositoryPushLog::REJECT_EXTERNAL;
|
||||
$this->rejectDetails = basename($hook);
|
||||
|
||||
throw new DiffusionCommitHookRejectException(
|
||||
pht(
|
||||
@@ -983,24 +975,23 @@ final class DiffusionCommitHookEngine extends Phobject {
|
||||
|
||||
|
||||
private function newPushLog() {
|
||||
// NOTE: By default, we create these with REJECT_BROKEN as the reject
|
||||
// code. This indicates a broken hook, and covers the case where we
|
||||
// encounter some unexpected exception and consequently reject the changes.
|
||||
|
||||
// NOTE: We generate PHIDs up front so the Herald transcripts can pick them
|
||||
// up.
|
||||
$phid = id(new PhabricatorRepositoryPushLog())->generatePHID();
|
||||
|
||||
return PhabricatorRepositoryPushLog::initializeNewLog($this->getViewer())
|
||||
->setPHID($phid)
|
||||
->attachRepository($this->getRepository())
|
||||
->setRepositoryPHID($this->getRepository()->getPHID())
|
||||
->setEpoch(time())
|
||||
->setEpoch(time());
|
||||
}
|
||||
|
||||
private function newPushEvent() {
|
||||
$viewer = $this->getViewer();
|
||||
return PhabricatorRepositoryPushEvent::initializeNewEvent($viewer)
|
||||
->setRepositoryPHID($this->getRepository()->getPHID())
|
||||
->setRemoteAddress($this->getRemoteAddressForLog())
|
||||
->setRemoteProtocol($this->getRemoteProtocol())
|
||||
->setTransactionKey($this->getTransactionKey())
|
||||
->setRejectCode(PhabricatorRepositoryPushLog::REJECT_BROKEN)
|
||||
->setRejectDetails(null);
|
||||
->setEpoch(time());
|
||||
}
|
||||
|
||||
public function loadChangesetsForCommit($identifier) {
|
||||
|
||||
Reference in New Issue
Block a user