Differential D21450 Diff 51086 src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php
| Show First 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | final protected function updateCommitData( | ||||
| $commit->setAuthorIdentityPHID($author_identity->getPHID()); | $commit->setAuthorIdentityPHID($author_identity->getPHID()); | ||||
| $commit->setSummary($data->getSummary()); | $commit->setSummary($data->getSummary()); | ||||
| $commit->save(); | $commit->save(); | ||||
| $data->save(); | $data->save(); | ||||
| // If we're publishing this commit, we're going to queue tasks to update | |||||
| // referenced objects (like tasks and revisions). Otherwise, record some | |||||
| // details about why we are not publishing it yet. | |||||
| $publisher = $repository->newPublisher(); | |||||
| if ($publisher->shouldPublishCommit($commit)) { | |||||
| $this->closeRevisions($viewer, $commit); | |||||
| $this->closeTasks($viewer, $commit); | |||||
| } else { | |||||
| $hold_reasons = $publisher->getCommitHoldReasons($commit); | |||||
| $data->setCommitDetail('holdReasons', $hold_reasons); | |||||
| $data->save(); | |||||
| } | |||||
| $commit->writeImportStatusFlag( | $commit->writeImportStatusFlag( | ||||
| PhabricatorRepositoryCommit::IMPORTED_MESSAGE); | PhabricatorRepositoryCommit::IMPORTED_MESSAGE); | ||||
| } | } | ||||
| private function closeRevisions( | |||||
| PhabricatorUser $actor, | |||||
| PhabricatorRepositoryCommit $commit) { | |||||
| $differential = 'PhabricatorDifferentialApplication'; | |||||
| if (!PhabricatorApplication::isClassInstalled($differential)) { | |||||
| return; | |||||
| } | |||||
| $repository = $commit->getRepository(); | |||||
| $data = $commit->getCommitData(); | |||||
| $ref = $data->getCommitRef(); | |||||
| $field_query = id(new DiffusionLowLevelCommitFieldsQuery()) | |||||
| ->setRepository($repository) | |||||
| ->withCommitRef($ref); | |||||
| $field_values = $field_query->execute(); | |||||
| $revision_id = idx($field_values, 'revisionID'); | |||||
| if (!$revision_id) { | |||||
| return; | |||||
| } | |||||
| $revision = id(new DifferentialRevisionQuery()) | |||||
| ->setViewer($actor) | |||||
| ->withIDs(array($revision_id)) | |||||
| ->executeOne(); | |||||
| if (!$revision) { | |||||
| return; | |||||
| } | |||||
| // NOTE: This is very old code from when revisions had a single reviewer. | |||||
| // It still powers the "Reviewer (Deprecated)" field in Herald, but should | |||||
| // be removed. | |||||
| if (!empty($field_values['reviewedByPHIDs'])) { | |||||
| $data->setCommitDetail( | |||||
| 'reviewerPHID', | |||||
| head($field_values['reviewedByPHIDs'])); | |||||
| } | |||||
| $match_data = $field_query->getRevisionMatchData(); | |||||
| $data->setCommitDetail('differential.revisionID', $revision_id); | |||||
| $data->setCommitDetail('revisionMatchData', $match_data); | |||||
| $properties = array( | |||||
| 'revisionMatchData' => $match_data, | |||||
| ); | |||||
| $this->queueObjectUpdate($commit, $revision, $properties); | |||||
| } | |||||
| private function closeTasks( | |||||
| PhabricatorUser $actor, | |||||
| PhabricatorRepositoryCommit $commit) { | |||||
| $maniphest = 'PhabricatorManiphestApplication'; | |||||
| if (!PhabricatorApplication::isClassInstalled($maniphest)) { | |||||
| return; | |||||
| } | |||||
| $data = $commit->getCommitData(); | |||||
| $prefixes = ManiphestTaskStatus::getStatusPrefixMap(); | |||||
| $suffixes = ManiphestTaskStatus::getStatusSuffixMap(); | |||||
| $message = $data->getCommitMessage(); | |||||
| $matches = id(new ManiphestCustomFieldStatusParser()) | |||||
| ->parseCorpus($message); | |||||
| $task_map = array(); | |||||
| foreach ($matches as $match) { | |||||
| $prefix = phutil_utf8_strtolower($match['prefix']); | |||||
| $suffix = phutil_utf8_strtolower($match['suffix']); | |||||
| $status = idx($suffixes, $suffix); | |||||
| if (!$status) { | |||||
| $status = idx($prefixes, $prefix); | |||||
| } | |||||
| foreach ($match['monograms'] as $task_monogram) { | |||||
| $task_id = (int)trim($task_monogram, 'tT'); | |||||
| $task_map[$task_id] = $status; | |||||
| } | |||||
| } | |||||
| if (!$task_map) { | |||||
| return; | |||||
| } | |||||
| $tasks = id(new ManiphestTaskQuery()) | |||||
| ->setViewer($actor) | |||||
| ->withIDs(array_keys($task_map)) | |||||
| ->execute(); | |||||
| foreach ($tasks as $task_id => $task) { | |||||
| $status = $task_map[$task_id]; | |||||
| $properties = array( | |||||
| 'status' => $status, | |||||
| ); | |||||
| $this->queueObjectUpdate($commit, $task, $properties); | |||||
| } | |||||
| } | |||||
| private function queueObjectUpdate( | |||||
| PhabricatorRepositoryCommit $commit, | |||||
| $object, | |||||
| array $properties) { | |||||
| $this->queueTask( | |||||
| 'DiffusionUpdateObjectAfterCommitWorker', | |||||
| array( | |||||
| 'commitPHID' => $commit->getPHID(), | |||||
| 'objectPHID' => $object->getPHID(), | |||||
| 'properties' => $properties, | |||||
| ), | |||||
| array( | |||||
| 'priority' => PhabricatorWorker::PRIORITY_DEFAULT, | |||||
| )); | |||||
| } | |||||
| } | } | ||||