@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge the "Herald" and "Owners" daemon workers into a single "Publish" worker

Summary:
Depends on D20466. Ref T13277. Currently:

- The "Owners" worker writes ownership relationships (e.g., commit X affects package Y, because it touches a path in package Y) -- these are just edges.
- It also triggers audits.
- Then it queues a "Herald" worker.
- This formally publishes the commit and triggers Herald.

These aren't really separate steps and can happen more easily in one shot. Merge them.

Test Plan:
- Ran `bin/repository reparse --publish` to republish various commits, got sensible behavior.
- Grepped for "IMPORTED_OWNERS", "IMPORTED_HERALD", "--herald", "--owners", and "--force-local" flags.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13277

Differential Revision: https://secure.phabricator.com/D20467

+197 -291
+2 -4
src/__phutil_library_map__.php
··· 4337 4337 'PhabricatorRepositoryCommit' => 'applications/repository/storage/PhabricatorRepositoryCommit.php', 4338 4338 'PhabricatorRepositoryCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php', 4339 4339 'PhabricatorRepositoryCommitData' => 'applications/repository/storage/PhabricatorRepositoryCommitData.php', 4340 - 'PhabricatorRepositoryCommitHeraldWorker' => 'applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php', 4341 4340 'PhabricatorRepositoryCommitHint' => 'applications/repository/storage/PhabricatorRepositoryCommitHint.php', 4342 4341 'PhabricatorRepositoryCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php', 4343 - 'PhabricatorRepositoryCommitOwnersWorker' => 'applications/repository/worker/PhabricatorRepositoryCommitOwnersWorker.php', 4344 4342 'PhabricatorRepositoryCommitPHIDType' => 'applications/repository/phid/PhabricatorRepositoryCommitPHIDType.php', 4345 4343 'PhabricatorRepositoryCommitParserWorker' => 'applications/repository/worker/PhabricatorRepositoryCommitParserWorker.php', 4344 + 'PhabricatorRepositoryCommitPublishWorker' => 'applications/repository/worker/PhabricatorRepositoryCommitPublishWorker.php', 4346 4345 'PhabricatorRepositoryCommitRef' => 'applications/repository/engine/PhabricatorRepositoryCommitRef.php', 4347 4346 'PhabricatorRepositoryCommitTestCase' => 'applications/repository/storage/__tests__/PhabricatorRepositoryCommitTestCase.php', 4348 4347 'PhabricatorRepositoryConfigOptions' => 'applications/repository/config/PhabricatorRepositoryConfigOptions.php', ··· 10606 10605 ), 10607 10606 'PhabricatorRepositoryCommitChangeParserWorker' => 'PhabricatorRepositoryCommitParserWorker', 10608 10607 'PhabricatorRepositoryCommitData' => 'PhabricatorRepositoryDAO', 10609 - 'PhabricatorRepositoryCommitHeraldWorker' => 'PhabricatorRepositoryCommitParserWorker', 10610 10608 'PhabricatorRepositoryCommitHint' => array( 10611 10609 'PhabricatorRepositoryDAO', 10612 10610 'PhabricatorPolicyInterface', 10613 10611 ), 10614 10612 'PhabricatorRepositoryCommitMessageParserWorker' => 'PhabricatorRepositoryCommitParserWorker', 10615 - 'PhabricatorRepositoryCommitOwnersWorker' => 'PhabricatorRepositoryCommitParserWorker', 10616 10613 'PhabricatorRepositoryCommitPHIDType' => 'PhabricatorPHIDType', 10617 10614 'PhabricatorRepositoryCommitParserWorker' => 'PhabricatorWorker', 10615 + 'PhabricatorRepositoryCommitPublishWorker' => 'PhabricatorRepositoryCommitParserWorker', 10618 10616 'PhabricatorRepositoryCommitRef' => 'Phobject', 10619 10617 'PhabricatorRepositoryCommitTestCase' => 'PhabricatorTestCase', 10620 10618 'PhabricatorRepositoryConfigOptions' => 'PhabricatorApplicationConfigOptions',
+1 -1
src/applications/audit/editor/PhabricatorAuditEditor.php
··· 184 184 foreach ($xactions as $xaction) { 185 185 switch ($xaction->getTransactionType()) { 186 186 case PhabricatorAuditTransaction::TYPE_COMMIT: 187 - $import_status_flag = PhabricatorRepositoryCommit::IMPORTED_HERALD; 187 + $import_status_flag = PhabricatorRepositoryCommit::IMPORTED_PUBLISH; 188 188 break; 189 189 } 190 190 }
+2 -5
src/applications/repository/management/PhabricatorRepositoryManagementImportingWorkflow.php
··· 67 67 if (!($status & PhabricatorRepositoryCommit::IMPORTED_CHANGE)) { 68 68 $need[] = pht('Change'); 69 69 } 70 - if (!($status & PhabricatorRepositoryCommit::IMPORTED_OWNERS)) { 71 - $need[] = pht('Owners'); 72 - } 73 - if (!($status & PhabricatorRepositoryCommit::IMPORTED_HERALD)) { 74 - $need[] = pht('Herald'); 70 + if (!($status & PhabricatorRepositoryCommit::IMPORTED_PUBLISH)) { 71 + $need[] = pht('Publish'); 75 72 } 76 73 77 74 $console->writeOut(' %s', implode(', ', $need));
+29 -90
src/applications/repository/management/PhabricatorRepositoryManagementReparseWorkflow.php
··· 12 12 '**reparse** __what__ __which_parts__ [--trace] [--force]'."\n\n". 13 13 'Rerun the Diffusion parser on specific commits and repositories. '. 14 14 'Mostly useful for debugging changes to Diffusion.'."\n\n". 15 - 'e.g. enqueue reparse owners in the TEST repo for all commits:'."\n". 16 - 'repository reparse --all TEST --owners'."\n\n". 17 15 'e.g. do same but exclude before yesterday (local time):'."\n". 18 - 'repository reparse --all TEST --owners --min-date yesterday'."\n". 19 - 'repository reparse --all TEST --owners --min-date "today -1 day".'. 16 + 'repository reparse --all TEST --change --min-date yesterday'."\n". 17 + 'repository reparse --all TEST --change --min-date "today -1 day".'. 20 18 "\n\n". 21 19 'e.g. do same but exclude before 03/31/2013 (local time):'."\n". 22 - 'repository reparse --all TEST --owners --min-date "03/31/2013"')) 20 + 'repository reparse --all TEST --change --min-date "03/31/2013"')) 23 21 ->setArguments( 24 22 array( 25 23 array( ··· 30 28 'name' => 'all', 31 29 'param' => 'repository', 32 30 'help' => pht( 33 - 'Reparse all commits in the specified repository. This mode '. 34 - 'queues parsers into the task queue; you must run taskmasters '. 35 - 'to actually do the parses. Use with __%s__ to run '. 36 - 'the tasks locally instead of with taskmasters.', 37 - '--force-local'), 31 + 'Reparse all commits in the specified repository.'), 38 32 ), 39 33 array( 40 34 'name' => 'min-date', ··· 57 51 ), 58 52 array( 59 53 'name' => 'change', 60 - 'help' => pht('Reparse changes.'), 54 + 'help' => pht('Reparse source changes.'), 61 55 ), 62 56 array( 63 - 'name' => 'herald', 57 + 'name' => 'publish', 64 58 'help' => pht( 65 - 'Reevaluate Herald rules (may send huge amounts of email!)'), 66 - ), 67 - array( 68 - 'name' => 'owners', 69 - 'help' => pht( 70 - 'Reevaluate related commits for owners packages (may delete '. 71 - 'existing relationship entries between your package and some '. 72 - 'old commits!)'), 59 + 'Publish changes: send email, publish Feed stories, run '. 60 + 'Herald rules, etc.'), 73 61 ), 74 62 array( 75 63 'name' => 'force', ··· 77 65 'help' => pht('Act noninteractively, without prompting.'), 78 66 ), 79 67 array( 80 - 'name' => 'force-local', 68 + 'name' => 'background', 81 69 'help' => pht( 82 - 'Only used with __%s__, use this to run the tasks locally '. 83 - 'instead of deferring them to taskmaster daemons.', 84 - '--all'), 70 + 'Queue tasks for the daemons instead of running them in the '. 71 + 'foreground.'), 85 72 ), 86 73 array( 87 74 'name' => 'importing', 88 - 'help' => pht( 89 - 'Reparse all steps which have not yet completed.'), 75 + 'help' => pht('Reparse all steps which have not yet completed.'), 90 76 ), 91 77 )); 92 78 ··· 98 84 $all_from_repo = $args->getArg('all'); 99 85 $reparse_message = $args->getArg('message'); 100 86 $reparse_change = $args->getArg('change'); 101 - $reparse_herald = $args->getArg('herald'); 102 - $reparse_owners = $args->getArg('owners'); 87 + $reparse_publish = $args->getArg('publish'); 103 88 $reparse_what = $args->getArg('revision'); 104 89 $force = $args->getArg('force'); 105 - $force_local = $args->getArg('force-local'); 90 + $background = $args->getArg('background'); 106 91 $min_date = $args->getArg('min-date'); 107 92 $importing = $args->getArg('importing'); 108 93 ··· 122 107 $commits)); 123 108 } 124 109 125 - $any_step = ($reparse_message || 126 - $reparse_change || 127 - $reparse_herald || 128 - $reparse_owners); 110 + $any_step = ($reparse_message || $reparse_change || $reparse_publish); 129 111 130 112 if ($any_step && $importing) { 131 113 throw new PhutilArgumentUsageException( 132 114 pht( 133 - 'Choosing steps with %s conflicts with flags which select '. 134 - 'specific steps.', 135 - '--importing')); 115 + 'Choosing steps with "--importing" conflicts with flags which '. 116 + 'select specific steps.')); 136 117 } else if ($any_step) { 137 118 // OK. 138 119 } else if ($importing) { ··· 140 121 } else if (!$any_step && !$importing) { 141 122 throw new PhutilArgumentUsageException( 142 123 pht( 143 - 'Specify which steps to reparse with %s, or %s, %s, %s, or %s.', 144 - '--importing', 145 - '--message', 146 - '--change', 147 - '--herald', 148 - '--owners')); 124 + 'Specify which steps to reparse with "--message", "--change", '. 125 + 'and/or "--publish"; or "--importing" to run all missing steps.')); 149 126 } 150 127 151 128 $min_timestamp = false; ··· 155 132 if (!$all_from_repo) { 156 133 throw new PhutilArgumentUsageException( 157 134 pht( 158 - "You must use --all if you specify --min-date\n". 159 - "e.g.\n". 160 - " repository reparse --all TEST --owners --min-date yesterday")); 135 + 'You must use "--all" if you specify "--min-date".')); 161 136 } 162 137 163 138 // previous to PHP 5.1.0 you would compare with -1, instead of false ··· 170 145 } 171 146 } 172 147 173 - if ($reparse_owners && !$force) { 174 - $console->writeOut( 175 - "%s\n", 176 - pht( 177 - 'You are about to recreate the relationship entries between the '. 178 - 'commits and the packages they touch. This might delete some '. 179 - 'existing relationship entries for some old commits.')); 180 - 181 - if (!phutil_console_confirm(pht('Are you ready to continue?'))) { 182 - throw new PhutilArgumentUsageException(pht('Cancelled.')); 183 - } 184 - } 185 - 186 148 $commits = array(); 187 149 if ($all_from_repo) { 188 150 $repository = id(new PhabricatorRepositoryQuery()) ··· 219 181 $commits = $this->loadNamedCommits($reparse_what); 220 182 } 221 183 222 - if ($all_from_repo && !$force_local) { 223 - $console->writeOut("%s\n", pht( 224 - "**NOTE**: This script will queue tasks to reparse the data. Once the ". 225 - "tasks have been queued, you need to run Taskmaster daemons to ". 226 - "execute them.\n\n%s", 227 - pht( 228 - 'QUEUEING TASKS (%s Commit(s)):', 229 - phutil_count($commits)))); 184 + if (!$background) { 185 + PhabricatorWorker::setRunAllTasksInProcess(true); 230 186 } 231 187 232 188 $progress = new PhutilConsoleProgressBar(); ··· 241 197 // Find the first missing import step and queue that up. 242 198 $reparse_message = false; 243 199 $reparse_change = false; 244 - $reparse_owners = false; 245 - $reparse_herald = false; 200 + $reparse_publish = false; 246 201 if (!($status & PhabricatorRepositoryCommit::IMPORTED_MESSAGE)) { 247 202 $reparse_message = true; 248 203 } else if (!($status & PhabricatorRepositoryCommit::IMPORTED_CHANGE)) { 249 204 $reparse_change = true; 250 - } else if (!($status & PhabricatorRepositoryCommit::IMPORTED_OWNERS)) { 251 - $reparse_owners = true; 252 - } else if (!($status & PhabricatorRepositoryCommit::IMPORTED_HERALD)) { 253 - $reparse_herald = true; 205 + } else if (!($status & PhabricatorRepositoryCommit::IMPORTED_PUBLISH)) { 206 + $reparse_publish = true; 254 207 } else { 255 208 continue; 256 209 } ··· 285 238 break; 286 239 } 287 240 288 - if ($reparse_herald) { 289 - $classes[] = 'PhabricatorRepositoryCommitHeraldWorker'; 290 - } 291 - 292 - if ($reparse_owners) { 293 - $classes[] = 'PhabricatorRepositoryCommitOwnersWorker'; 241 + if ($reparse_publish) { 242 + $classes[] = 'PhabricatorRepositoryCommitPublishWorker'; 294 243 } 295 244 296 245 // NOTE: With "--importing", we queue the first unparsed step and let ··· 298 247 // all the requested steps explicitly. 299 248 300 249 $spec = array( 301 - 'commitID' => $commit->getID(), 302 - 'only' => !$importing, 250 + 'commitID' => $commit->getID(), 251 + 'only' => !$importing, 303 252 ); 304 - 305 - if ($all_from_repo && !$force_local) { 306 - $background = true; 307 - } else { 308 - $background = false; 309 - } 310 - 311 - if (!$background) { 312 - PhabricatorWorker::setRunAllTasksInProcess(true); 313 - } 314 253 315 254 foreach ($classes as $class) { 316 255 PhabricatorWorker::scheduleTask(
+2 -5
src/applications/repository/storage/PhabricatorRepository.php
··· 1003 1003 $done = 0; 1004 1004 $total = 0; 1005 1005 foreach ($progress as $row) { 1006 - $total += $row['N'] * 4; 1006 + $total += $row['N'] * 3; 1007 1007 $status = $row['importStatus']; 1008 1008 if ($status & PhabricatorRepositoryCommit::IMPORTED_MESSAGE) { 1009 1009 $done += $row['N']; ··· 1011 1011 if ($status & PhabricatorRepositoryCommit::IMPORTED_CHANGE) { 1012 1012 $done += $row['N']; 1013 1013 } 1014 - if ($status & PhabricatorRepositoryCommit::IMPORTED_OWNERS) { 1015 - $done += $row['N']; 1016 - } 1017 - if ($status & PhabricatorRepositoryCommit::IMPORTED_HERALD) { 1014 + if ($status & PhabricatorRepositoryCommit::IMPORTED_PUBLISH) { 1018 1015 $done += $row['N']; 1019 1016 } 1020 1017 }
+2 -3
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 33 33 34 34 const IMPORTED_MESSAGE = 1; 35 35 const IMPORTED_CHANGE = 2; 36 - const IMPORTED_OWNERS = 4; 37 - const IMPORTED_HERALD = 8; 38 - const IMPORTED_ALL = 15; 36 + const IMPORTED_PUBLISH = 8; 37 + const IMPORTED_ALL = 11; 39 38 40 39 const IMPORTED_CLOSEABLE = 1024; 41 40 const IMPORTED_UNREACHABLE = 2048;
-146
src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
··· 1 - <?php 2 - 3 - final class PhabricatorRepositoryCommitHeraldWorker 4 - extends PhabricatorRepositoryCommitParserWorker { 5 - 6 - protected function getImportStepFlag() { 7 - return PhabricatorRepositoryCommit::IMPORTED_HERALD; 8 - } 9 - 10 - public function getRequiredLeaseTime() { 11 - // Herald rules may take a long time to process. 12 - return phutil_units('4 hours in seconds'); 13 - } 14 - 15 - protected function parseCommit( 16 - PhabricatorRepository $repository, 17 - PhabricatorRepositoryCommit $commit) { 18 - $viewer = PhabricatorUser::getOmnipotentUser(); 19 - 20 - if ($this->shouldSkipImportStep()) { 21 - // This worker has no followup tasks, so we can just bail out 22 - // right away without queueing anything. 23 - return; 24 - } 25 - 26 - // Reload the commit to pull commit data and audit requests. 27 - $commit = id(new DiffusionCommitQuery()) 28 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 29 - ->withIDs(array($commit->getID())) 30 - ->needCommitData(true) 31 - ->needAuditRequests(true) 32 - ->executeOne(); 33 - $data = $commit->getCommitData(); 34 - 35 - if (!$data) { 36 - throw new PhabricatorWorkerPermanentFailureException( 37 - pht( 38 - 'Unable to load commit data. The data for this task is invalid '. 39 - 'or no longer exists.')); 40 - } 41 - 42 - $commit->attachRepository($repository); 43 - 44 - $content_source = $this->newContentSource(); 45 - 46 - $committer_phid = $data->getCommitDetail('committerPHID'); 47 - $author_phid = $data->getCommitDetail('authorPHID'); 48 - $acting_as_phid = nonempty( 49 - $committer_phid, 50 - $author_phid, 51 - id(new PhabricatorDiffusionApplication())->getPHID()); 52 - 53 - $editor = id(new PhabricatorAuditEditor()) 54 - ->setActor($viewer) 55 - ->setActingAsPHID($acting_as_phid) 56 - ->setContinueOnMissingFields(true) 57 - ->setContinueOnNoEffect(true) 58 - ->setContentSource($content_source); 59 - 60 - $xactions = array(); 61 - $xactions[] = id(new PhabricatorAuditTransaction()) 62 - ->setTransactionType(PhabricatorAuditTransaction::TYPE_COMMIT) 63 - ->setDateCreated($commit->getEpoch()) 64 - ->setNewValue(array( 65 - 'description' => $data->getCommitMessage(), 66 - 'summary' => $data->getSummary(), 67 - 'authorName' => $data->getAuthorName(), 68 - 'authorPHID' => $commit->getAuthorPHID(), 69 - 'committerName' => $data->getCommitDetail('committer'), 70 - 'committerPHID' => $data->getCommitDetail('committerPHID'), 71 - )); 72 - 73 - try { 74 - $raw_patch = $this->loadRawPatchText($repository, $commit); 75 - } catch (Exception $ex) { 76 - $raw_patch = pht('Unable to generate patch: %s', $ex->getMessage()); 77 - } 78 - $editor->setRawPatch($raw_patch); 79 - 80 - return $editor->applyTransactions($commit, $xactions); 81 - } 82 - 83 - private function loadRawPatchText( 84 - PhabricatorRepository $repository, 85 - PhabricatorRepositoryCommit $commit) { 86 - $viewer = PhabricatorUser::getOmnipotentUser(); 87 - 88 - $identifier = $commit->getCommitIdentifier(); 89 - 90 - $drequest = DiffusionRequest::newFromDictionary( 91 - array( 92 - 'user' => $viewer, 93 - 'repository' => $repository, 94 - )); 95 - 96 - $time_key = 'metamta.diffusion.time-limit'; 97 - $byte_key = 'metamta.diffusion.byte-limit'; 98 - $time_limit = PhabricatorEnv::getEnvConfig($time_key); 99 - $byte_limit = PhabricatorEnv::getEnvConfig($byte_key); 100 - 101 - $diff_info = DiffusionQuery::callConduitWithDiffusionRequest( 102 - $viewer, 103 - $drequest, 104 - 'diffusion.rawdiffquery', 105 - array( 106 - 'commit' => $identifier, 107 - 'linesOfContext' => 3, 108 - 'timeout' => $time_limit, 109 - 'byteLimit' => $byte_limit, 110 - )); 111 - 112 - if ($diff_info['tooSlow']) { 113 - throw new Exception( 114 - pht( 115 - 'Patch generation took longer than configured limit ("%s") of '. 116 - '%s second(s).', 117 - $time_key, 118 - new PhutilNumber($time_limit))); 119 - } 120 - 121 - if ($diff_info['tooHuge']) { 122 - $pretty_limit = phutil_format_bytes($byte_limit); 123 - throw new Exception( 124 - pht( 125 - 'Patch size exceeds configured byte size limit ("%s") of %s.', 126 - $byte_key, 127 - $pretty_limit)); 128 - } 129 - 130 - $file_phid = $diff_info['filePHID']; 131 - $file = id(new PhabricatorFileQuery()) 132 - ->setViewer($viewer) 133 - ->withPHIDs(array($file_phid)) 134 - ->executeOne(); 135 - if (!$file) { 136 - throw new Exception( 137 - pht( 138 - 'Failed to load file ("%s") returned by "%s".', 139 - $file_phid, 140 - 'diffusion.rawdiffquery')); 141 - } 142 - 143 - return $file->loadFileData(); 144 - } 145 - 146 - }
+158 -36
src/applications/repository/worker/PhabricatorRepositoryCommitOwnersWorker.php src/applications/repository/worker/PhabricatorRepositoryCommitPublishWorker.php
··· 1 1 <?php 2 2 3 - final class PhabricatorRepositoryCommitOwnersWorker 3 + final class PhabricatorRepositoryCommitPublishWorker 4 4 extends PhabricatorRepositoryCommitParserWorker { 5 5 6 6 protected function getImportStepFlag() { 7 - return PhabricatorRepositoryCommit::IMPORTED_OWNERS; 7 + return PhabricatorRepositoryCommit::IMPORTED_PUBLISH; 8 + } 9 + 10 + public function getRequiredLeaseTime() { 11 + // Herald rules may take a long time to process. 12 + return phutil_units('4 hours in seconds'); 8 13 } 9 14 10 15 protected function parseCommit( ··· 12 17 PhabricatorRepositoryCommit $commit) { 13 18 14 19 if (!$this->shouldSkipImportStep()) { 15 - $this->triggerOwnerAudits($repository, $commit); 20 + $this->publishCommit($repository, $commit); 16 21 $commit->writeImportStatusFlag($this->getImportStepFlag()); 17 22 } 18 23 19 - if ($this->shouldQueueFollowupTasks()) { 20 - $this->queueTask( 21 - 'PhabricatorRepositoryCommitHeraldWorker', 22 - array( 23 - 'commitID' => $commit->getID(), 24 - )); 25 - } 24 + // This is the last task in the sequence, so we don't need to queue any 25 + // followup workers. 26 26 } 27 27 28 - private function triggerOwnerAudits( 28 + private function publishCommit( 29 29 PhabricatorRepository $repository, 30 30 PhabricatorRepositoryCommit $commit) { 31 31 $viewer = PhabricatorUser::getOmnipotentUser(); ··· 35 35 return; 36 36 } 37 37 38 + $commit_phid = $commit->getPHID(); 39 + 40 + // Reload the commit to get the commit data, identities, and any 41 + // outstanding audit requests. 42 + $commit = id(new DiffusionCommitQuery()) 43 + ->setViewer($viewer) 44 + ->withPHIDs(array($commit_phid)) 45 + ->needCommitData(true) 46 + ->needIdentities(true) 47 + ->needAuditRequests(true) 48 + ->executeOne(); 49 + if (!$commit) { 50 + throw new PhabricatorWorkerPermanentFailureException( 51 + pht( 52 + 'Failed to reload commit "%s".', 53 + $commit_phid)); 54 + } 55 + 56 + $xactions = array( 57 + $this->newAuditTransactions($commit), 58 + $this->newPublishTransactions($commit), 59 + ); 60 + $xactions = array_mergev($xactions); 61 + 62 + $acting_phid = $this->getPublishAsPHID($commit); 63 + $content_source = $this->newContentSource(); 64 + 65 + $editor = $commit->getApplicationTransactionEditor() 66 + ->setActor($viewer) 67 + ->setActingAsPHID($acting_phid) 68 + ->setContinueOnNoEffect(true) 69 + ->setContinueOnMissingFields(true) 70 + ->setContentSource($content_source); 71 + 72 + try { 73 + $raw_patch = $this->loadRawPatchText($repository, $commit); 74 + } catch (Exception $ex) { 75 + $raw_patch = pht('Unable to generate patch: %s', $ex->getMessage()); 76 + } 77 + $editor->setRawPatch($raw_patch); 78 + 79 + $editor->applyTransactions($commit, $xactions); 80 + } 81 + 82 + private function getPublishAsPHID(PhabricatorRepositoryCommit $commit) { 83 + if ($commit->hasCommitterIdentity()) { 84 + return $commit->getCommitterIdentity()->getIdentityDisplayPHID(); 85 + } 86 + 87 + if ($commit->hasAuthorIdentity()) { 88 + return $commit->getAuthorIdentity()->getIdentityDisplayPHID(); 89 + } 90 + 91 + return id(new PhabricatorDiffusionApplication())->getPHID(); 92 + } 93 + 94 + private function newPublishTransactions(PhabricatorRepositoryCommit $commit) { 95 + $data = $commit->getCommitData(); 96 + 97 + $xactions = array(); 98 + 99 + $xactions[] = $commit->getApplicationTransactionTemplate() 100 + ->setTransactionType(PhabricatorAuditTransaction::TYPE_COMMIT) 101 + ->setDateCreated($commit->getEpoch()) 102 + ->setNewValue( 103 + array( 104 + 'description' => $data->getCommitMessage(), 105 + 'summary' => $data->getSummary(), 106 + 'authorName' => $data->getAuthorName(), 107 + 'authorPHID' => $commit->getAuthorPHID(), 108 + 'committerName' => $data->getCommitDetail('committer'), 109 + 'committerPHID' => $data->getCommitDetail('committerPHID'), 110 + )); 111 + 112 + return $xactions; 113 + } 114 + 115 + private function newAuditTransactions(PhabricatorRepositoryCommit $commit) { 116 + $viewer = PhabricatorUser::getOmnipotentUser(); 117 + 118 + $repository = $commit->getRepository(); 119 + 38 120 $affected_paths = PhabricatorOwnerPathQuery::loadAffectedPaths( 39 121 $repository, 40 122 $commit, ··· 47 129 $commit->writeOwnersEdges(mpull($affected_packages, 'getPHID')); 48 130 49 131 if (!$affected_packages) { 50 - return; 51 - } 52 - 53 - $commit = id(new DiffusionCommitQuery()) 54 - ->setViewer($viewer) 55 - ->withPHIDs(array($commit->getPHID())) 56 - ->needCommitData(true) 57 - ->needAuditRequests(true) 58 - ->executeOne(); 59 - if (!$commit) { 60 - return; 132 + return array(); 61 133 } 62 134 63 135 $data = $commit->getCommitData(); ··· 99 171 100 172 // If none of the packages are triggering audits, we're all done. 101 173 if (!$auditor_phids) { 102 - return; 174 + return array(); 103 175 } 104 176 105 177 $audit_type = DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE; 106 178 107 - $owners_phid = id(new PhabricatorOwnersApplication()) 108 - ->getPHID(); 109 - 110 - $content_source = $this->newContentSource(); 111 - 112 179 $xactions = array(); 113 180 $xactions[] = $commit->getApplicationTransactionTemplate() 114 181 ->setTransactionType($audit_type) ··· 117 184 '+' => array_fuse($auditor_phids), 118 185 )); 119 186 120 - $editor = $commit->getApplicationTransactionEditor() 121 - ->setActor($viewer) 122 - ->setActingAsPHID($owners_phid) 123 - ->setContinueOnNoEffect(true) 124 - ->setContinueOnMissingFields(true) 125 - ->setContentSource($content_source); 126 - 127 - $editor->applyTransactions($commit, $xactions); 187 + return $xactions; 128 188 } 129 189 130 190 private function shouldTriggerAudit( ··· 253 313 return false; 254 314 } 255 315 316 + private function loadRawPatchText( 317 + PhabricatorRepository $repository, 318 + PhabricatorRepositoryCommit $commit) { 319 + $viewer = PhabricatorUser::getOmnipotentUser(); 320 + 321 + $identifier = $commit->getCommitIdentifier(); 322 + 323 + $drequest = DiffusionRequest::newFromDictionary( 324 + array( 325 + 'user' => $viewer, 326 + 'repository' => $repository, 327 + )); 328 + 329 + $time_key = 'metamta.diffusion.time-limit'; 330 + $byte_key = 'metamta.diffusion.byte-limit'; 331 + $time_limit = PhabricatorEnv::getEnvConfig($time_key); 332 + $byte_limit = PhabricatorEnv::getEnvConfig($byte_key); 333 + 334 + $diff_info = DiffusionQuery::callConduitWithDiffusionRequest( 335 + $viewer, 336 + $drequest, 337 + 'diffusion.rawdiffquery', 338 + array( 339 + 'commit' => $identifier, 340 + 'linesOfContext' => 3, 341 + 'timeout' => $time_limit, 342 + 'byteLimit' => $byte_limit, 343 + )); 344 + 345 + if ($diff_info['tooSlow']) { 346 + throw new Exception( 347 + pht( 348 + 'Patch generation took longer than configured limit ("%s") of '. 349 + '%s second(s).', 350 + $time_key, 351 + new PhutilNumber($time_limit))); 352 + } 353 + 354 + if ($diff_info['tooHuge']) { 355 + $pretty_limit = phutil_format_bytes($byte_limit); 356 + throw new Exception( 357 + pht( 358 + 'Patch size exceeds configured byte size limit ("%s") of %s.', 359 + $byte_key, 360 + $pretty_limit)); 361 + } 362 + 363 + $file_phid = $diff_info['filePHID']; 364 + $file = id(new PhabricatorFileQuery()) 365 + ->setViewer($viewer) 366 + ->withPHIDs(array($file_phid)) 367 + ->executeOne(); 368 + if (!$file) { 369 + throw new Exception( 370 + pht( 371 + 'Failed to load file ("%s") returned by "%s".', 372 + $file_phid, 373 + 'diffusion.rawdiffquery')); 374 + } 375 + 376 + return $file->loadFileData(); 377 + } 256 378 }
+1 -1
src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php
··· 102 102 $commit = $this->commit; 103 103 if ($this->shouldQueueFollowupTasks()) { 104 104 $this->queueTask( 105 - 'PhabricatorRepositoryCommitOwnersWorker', 105 + 'PhabricatorRepositoryCommitPublishWorker', 106 106 array( 107 107 'commitID' => $commit->getID(), 108 108 ));