Add a basic push log for recording repository push events
Summary:
Ref T4195. This log serves two purposes:
- It's a log, so you can see what happened. Particularly, in Git/Hg, there is no other way to tell:
- Who //pushed// a change (vs committed / authored)?
- When was a change pushed?
- What was the old value of some tag/branch before someone destroyed it?
- We can hand these objects off to Herald to implement pre-commit rules.
This is a very basic implementation, but gets some data written and has a basic UI for it.
Test Plan: {F87339}
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4195
Differential Revision: https://secure.phabricator.com/D7705
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @task git Git Hooks
|
||||
* @task hg Mercurial Hooks
|
||||
* @task svn Subversion Hooks
|
||||
*/
|
||||
final class DiffusionCommitHookEngine extends Phobject {
|
||||
|
||||
private $viewer;
|
||||
@@ -77,6 +82,48 @@ final class DiffusionCommitHookEngine extends Phobject {
|
||||
|
||||
// TODO: Now, do content checks.
|
||||
|
||||
// TODO: Generalize this; just getting some data in the database for now.
|
||||
$transaction_key = PhabricatorHash::digestForIndex(
|
||||
Filesystem::readRandomBytes(64));
|
||||
|
||||
$logs = array();
|
||||
foreach ($updates as $update) {
|
||||
$log = PhabricatorRepositoryPushLog::initializeNewLog($this->getViewer())
|
||||
->setRepositoryPHID($this->getRepository()->getPHID())
|
||||
->setEpoch(time())
|
||||
->setRemoteAddress(null) // TODO: Populate this where possible.
|
||||
->setRemoteProtocol(null) // TODO: Populate this where possible.
|
||||
->setTransactionKey($transaction_key)
|
||||
->setRefType($update['type'])
|
||||
->setRefNameHash(PhabricatorHash::digestForIndex($update['ref']))
|
||||
->setRefNameRaw($update['ref'])
|
||||
->setRefNameEncoding(phutil_is_utf8($update['ref']) ? 'utf8' : null)
|
||||
->setRefOld($update['old'])
|
||||
->setRefNew($update['new'])
|
||||
->setMergeBase(idx($update, 'merge-base'))
|
||||
->setRejectCode(PhabricatorRepositoryPushLog::REJECT_ACCEPT)
|
||||
->setRejectDetails(null);
|
||||
|
||||
$flags = 0;
|
||||
if ($update['operation'] == 'create') {
|
||||
$flags = $flags | PhabricatorRepositoryPushLog::CHANGEFLAG_ADD;
|
||||
} else if ($update['operation'] == 'delete') {
|
||||
$flags = $flags | PhabricatorRepositoryPushLog::CHANGEFLAG_DELETE;
|
||||
} else {
|
||||
// TODO: This isn't correct; these might be APPEND or REWRITE, and
|
||||
// if they're REWRITE they might be DANGEROUS. Fix this when this
|
||||
// gets generalized.
|
||||
$flags = $flags | PhabricatorRepositoryPushLog::CHANGEFLAG_APPEND;
|
||||
}
|
||||
|
||||
$log->setChangeFlags($flags);
|
||||
$logs[] = $log;
|
||||
}
|
||||
|
||||
foreach ($logs as $log) {
|
||||
$log->save();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user