@@ -30,6 +30,8 @@ final class DiffusionCommitHookEngine extends Phobject {
30
30
private $ gitCommits = array ();
31
31
32
32
private $ heraldViewerProjects ;
33
+ private $ rejectCode = PhabricatorRepositoryPushLog::REJECT_BROKEN ;
34
+ private $ rejectDetails ;
33
35
34
36
35
37
/* -( Config )------------------------------------------------------------- */
@@ -62,14 +64,6 @@ private function getRemoteAddressForLog() {
62
64
return $ remote_address ;
63
65
}
64
66
65
- private function getTransactionKey () {
66
- if (!$ this ->transactionKey ) {
67
- $ entropy = Filesystem::readRandomBytes (64 );
68
- $ this ->transactionKey = PhabricatorHash::digestForIndex ($ entropy );
69
- }
70
- return $ this ->transactionKey ;
71
- }
72
-
73
67
public function setSubversionTransactionInfo ($ transaction , $ repository ) {
74
68
$ this ->subversionTransaction = $ transaction ;
75
69
$ this ->subversionRepository = $ repository ;
@@ -137,10 +131,7 @@ public function execute() {
137
131
} catch (DiffusionCommitHookRejectException $ ex ) {
138
132
// If we're rejecting dangerous changes, flag everything that we've
139
133
// seen as rejected so it's clear that none of it was accepted.
140
- foreach ($ all_updates as $ update ) {
141
- $ update ->setRejectCode (
142
- PhabricatorRepositoryPushLog::REJECT_DANGEROUS );
143
- }
134
+ $ this ->rejectCode = PhabricatorRepositoryPushLog::REJECT_DANGEROUS ;
144
135
throw $ ex ;
145
136
}
146
137
@@ -156,19 +147,26 @@ public function execute() {
156
147
157
148
// If we make it this far, we're accepting these changes. Mark all the
158
149
// logs as accepted.
159
- foreach ($ all_updates as $ update ) {
160
- $ update ->setRejectCode (PhabricatorRepositoryPushLog::REJECT_ACCEPT );
161
- }
150
+ $ this ->rejectCode = PhabricatorRepositoryPushLog::REJECT_ACCEPT ;
162
151
} catch (Exception $ ex ) {
163
152
// We'll throw this again in a minute, but we want to save all the logs
164
153
// first.
165
154
$ caught = $ ex ;
166
155
}
167
156
168
157
// Save all the logs no matter what the outcome was.
169
- foreach ($ all_updates as $ update ) {
170
- $ update ->save ();
171
- }
158
+ $ event = $ this ->newPushEvent ();
159
+
160
+ $ event ->setRejectCode ($ this ->rejectCode );
161
+ $ event ->setRejectDetails ($ this ->rejectDetails );
162
+
163
+ $ event ->openTransaction ();
164
+ $ event ->save ();
165
+ foreach ($ all_updates as $ update ) {
166
+ $ update ->setPushEventPHID ($ event ->getPHID ());
167
+ $ update ->save ();
168
+ }
169
+ $ event ->saveTransaction ();
172
170
173
171
if ($ caught ) {
174
172
throw $ caught ;
@@ -296,10 +294,8 @@ private function applyHeraldRules(
296
294
}
297
295
298
296
if ($ blocking_effect ) {
299
- foreach ($ all_updates as $ update ) {
300
- $ update ->setRejectCode (PhabricatorRepositoryPushLog::REJECT_HERALD );
301
- $ update ->setRejectDetails ($ blocking_effect ->getRulePHID ());
302
- }
297
+ $ this ->rejectCode = PhabricatorRepositoryPushLog::REJECT_HERALD ;
298
+ $ this ->rejectDetails = $ blocking_effect ->getRulePHID ();
303
299
304
300
$ message = $ blocking_effect ->getTarget ();
305
301
if (!strlen ($ message )) {
@@ -596,12 +592,8 @@ private function applyCustomHooks(array $updates) {
596
592
continue ;
597
593
}
598
594
599
- // Mark everything as rejected by this hook.
600
- foreach ($ updates as $ update ) {
601
- $ update ->setRejectCode (
602
- PhabricatorRepositoryPushLog::REJECT_EXTERNAL );
603
- $ update ->setRejectDetails (basename ($ hook ));
604
- }
595
+ $ this ->rejectCode = PhabricatorRepositoryPushLog::REJECT_EXTERNAL ;
596
+ $ this ->rejectDetails = basename ($ hook );
605
597
606
598
throw new DiffusionCommitHookRejectException (
607
599
pht (
@@ -983,24 +975,23 @@ private function findSubversionContentUpdates(array $ref_updates) {
983
975
984
976
985
977
private function newPushLog () {
986
- // NOTE: By default, we create these with REJECT_BROKEN as the reject
987
- // code. This indicates a broken hook, and covers the case where we
988
- // encounter some unexpected exception and consequently reject the changes.
989
-
990
978
// NOTE: We generate PHIDs up front so the Herald transcripts can pick them
991
979
// up.
992
980
$ phid = id (new PhabricatorRepositoryPushLog ())->generatePHID ();
993
981
994
982
return PhabricatorRepositoryPushLog::initializeNewLog ($ this ->getViewer ())
995
983
->setPHID ($ phid )
996
- ->attachRepository ($ this ->getRepository ())
997
984
->setRepositoryPHID ($ this ->getRepository ()->getPHID ())
998
- ->setEpoch (time ())
985
+ ->setEpoch (time ());
986
+ }
987
+
988
+ private function newPushEvent () {
989
+ $ viewer = $ this ->getViewer ();
990
+ return PhabricatorRepositoryPushEvent::initializeNewEvent ($ viewer )
991
+ ->setRepositoryPHID ($ this ->getRepository ()->getPHID ())
999
992
->setRemoteAddress ($ this ->getRemoteAddressForLog ())
1000
993
->setRemoteProtocol ($ this ->getRemoteProtocol ())
1001
- ->setTransactionKey ($ this ->getTransactionKey ())
1002
- ->setRejectCode (PhabricatorRepositoryPushLog::REJECT_BROKEN )
1003
- ->setRejectDetails (null );
994
+ ->setEpoch (time ());
1004
995
}
1005
996
1006
997
public function loadChangesetsForCommit ($ identifier ) {
0 commit comments