Differential D21449 Diff 51085 src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php
| Show All 12 Lines | final protected function parseCommit( | ||||
| PhabricatorRepository $repository, | PhabricatorRepository $repository, | ||||
| PhabricatorRepositoryCommit $commit) { | PhabricatorRepositoryCommit $commit) { | ||||
| if (!$this->shouldSkipImportStep()) { | if (!$this->shouldSkipImportStep()) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $ref = $commit->newCommitRef($viewer); | $ref = $commit->newCommitRef($viewer); | ||||
| $this->updateCommitData($ref); | $data = $this->loadCommitData($commit); | ||||
| $data->setCommitRef($ref); | |||||
| $this->updateCommitData($commit, $data); | |||||
| } | } | ||||
| if ($this->shouldQueueFollowupTasks()) { | if ($this->shouldQueueFollowupTasks()) { | ||||
| $this->queueTask( | $this->queueTask( | ||||
| $this->getFollowupTaskClass(), | $this->getFollowupTaskClass(), | ||||
| array( | array( | ||||
| 'commitID' => $commit->getID(), | 'commitID' => $commit->getID(), | ||||
| ), | ), | ||||
| array( | array( | ||||
| // We queue followup tasks at default priority so that the queue | // We queue followup tasks at default priority so that the queue | ||||
| // finishes work it has started before starting more work. If | // finishes work it has started before starting more work. If | ||||
| // followups are queued at the same priority level, we do all | // followups are queued at the same priority level, we do all | ||||
| // message parses first, then all change parses, etc. This makes | // message parses first, then all change parses, etc. This makes | ||||
| // progress uneven. See T11677 for discussion. | // progress uneven. See T11677 for discussion. | ||||
| 'priority' => PhabricatorWorker::PRIORITY_DEFAULT, | 'priority' => PhabricatorWorker::PRIORITY_DEFAULT, | ||||
| )); | )); | ||||
| } | } | ||||
| } | } | ||||
| final protected function updateCommitData(DiffusionCommitRef $ref) { | final protected function updateCommitData( | ||||
| $commit = $this->commit; | PhabricatorRepositoryCommit $commit, | ||||
| PhabricatorRepositoryCommitData $data) { | |||||
| $ref = $data->getCommitRef(); | |||||
| $viewer = $this->getViewer(); | |||||
| $author = $ref->getAuthor(); | $author = $ref->getAuthor(); | ||||
| $committer = $ref->getCommitter(); | $committer = $ref->getCommitter(); | ||||
| $has_committer = (bool)strlen($committer); | $has_committer = (bool)strlen($committer); | ||||
| $viewer = PhabricatorUser::getOmnipotentUser(); | |||||
| $identity_engine = id(new DiffusionRepositoryIdentityEngine()) | $identity_engine = id(new DiffusionRepositoryIdentityEngine()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->setSourcePHID($commit->getPHID()); | ->setSourcePHID($commit->getPHID()); | ||||
| // See T13538. It is possible to synthetically construct a Git commit with | // See T13538. It is possible to synthetically construct a Git commit with | ||||
| // no author and arrive here with NULL for the author value. | // no author and arrive here with NULL for the author value. | ||||
| // This is distinct from a commit with an empty author. Because both these | // This is distinct from a commit with an empty author. Because both these | ||||
| // cases are degenerate and we can't resolve NULL into an identity, cast | // cases are degenerate and we can't resolve NULL into an identity, cast | ||||
| // NULL to the empty string and merge the flows. | // NULL to the empty string and merge the flows. | ||||
| $author = phutil_string_cast($author); | $author = phutil_string_cast($author); | ||||
| $author_identity = $identity_engine->newResolvedIdentity($author); | $author_identity = $identity_engine->newResolvedIdentity($author); | ||||
| if ($has_committer) { | if ($has_committer) { | ||||
| $committer_identity = $identity_engine->newResolvedIdentity($committer); | $committer_identity = $identity_engine->newResolvedIdentity($committer); | ||||
| } else { | } else { | ||||
| $committer_identity = null; | $committer_identity = null; | ||||
| } | } | ||||
| $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( | |||||
| 'commitID = %d', | |||||
| $commit->getID()); | |||||
| if (!$data) { | |||||
| $data = new PhabricatorRepositoryCommitData(); | |||||
| } | |||||
| $data->setCommitID($commit->getID()); | |||||
| $data->setAuthorName(id(new PhutilUTF8StringTruncator()) | $data->setAuthorName(id(new PhutilUTF8StringTruncator()) | ||||
| ->setMaximumBytes(255) | ->setMaximumBytes(255) | ||||
| ->truncateString((string)$author)); | ->truncateString((string)$author)); | ||||
| $data->setCommitDetail('authorEpoch', $ref->getAuthorEpoch()); | $data->setCommitDetail('authorEpoch', $ref->getAuthorEpoch()); | ||||
| $data->setCommitDetail('authorName', $ref->getAuthorName()); | $data->setCommitDetail('authorName', $ref->getAuthorName()); | ||||
| $data->setCommitDetail('authorEmail', $ref->getAuthorEmail()); | $data->setCommitDetail('authorEmail', $ref->getAuthorEmail()); | ||||
| Show All 33 Lines | final protected function updateCommitData( | ||||
| if ($author_phid != $commit->getAuthorPHID()) { | if ($author_phid != $commit->getAuthorPHID()) { | ||||
| $commit->setAuthorPHID($author_phid); | $commit->setAuthorPHID($author_phid); | ||||
| } | } | ||||
| $commit->setAuthorIdentityPHID($author_identity->getPHID()); | $commit->setAuthorIdentityPHID($author_identity->getPHID()); | ||||
| $commit->setSummary($data->getSummary()); | $commit->setSummary($data->getSummary()); | ||||
| $commit->save(); | $commit->save(); | ||||
| $data->save(); | |||||
| // If we're publishing this commit, we're going to queue tasks to update | // If we're publishing this commit, we're going to queue tasks to update | ||||
| // referenced objects (like tasks and revisions). Otherwise, record some | // referenced objects (like tasks and revisions). Otherwise, record some | ||||
| // details about why we are not publishing it yet. | // details about why we are not publishing it yet. | ||||
| $publisher = $repository->newPublisher(); | $publisher = $repository->newPublisher(); | ||||
| if ($publisher->shouldPublishCommit($commit)) { | if ($publisher->shouldPublishCommit($commit)) { | ||||
| $actor = PhabricatorUser::getOmnipotentUser(); | $this->closeRevisions($viewer, $commit); | ||||
| $this->closeRevisions($actor, $ref, $commit, $data); | $this->closeTasks($viewer, $commit); | ||||
| $this->closeTasks($actor, $ref, $commit, $data); | |||||
| } else { | } else { | ||||
| $hold_reasons = $publisher->getCommitHoldReasons($commit); | $hold_reasons = $publisher->getCommitHoldReasons($commit); | ||||
| $data->setCommitDetail('holdReasons', $hold_reasons); | |||||
| } | |||||
| $data->setCommitDetail('holdReasons', $hold_reasons); | |||||
| $data->save(); | $data->save(); | ||||
| } | |||||
| $commit->writeImportStatusFlag( | $commit->writeImportStatusFlag( | ||||
| PhabricatorRepositoryCommit::IMPORTED_MESSAGE); | PhabricatorRepositoryCommit::IMPORTED_MESSAGE); | ||||
| } | } | ||||
| private function closeRevisions( | private function closeRevisions( | ||||
| PhabricatorUser $actor, | PhabricatorUser $actor, | ||||
| DiffusionCommitRef $ref, | PhabricatorRepositoryCommit $commit) { | ||||
| PhabricatorRepositoryCommit $commit, | |||||
| PhabricatorRepositoryCommitData $data) { | |||||
| $differential = 'PhabricatorDifferentialApplication'; | $differential = 'PhabricatorDifferentialApplication'; | ||||
| if (!PhabricatorApplication::isClassInstalled($differential)) { | if (!PhabricatorApplication::isClassInstalled($differential)) { | ||||
| return; | return; | ||||
| } | } | ||||
| $repository = $commit->getRepository(); | $repository = $commit->getRepository(); | ||||
| $data = $commit->getCommitData(); | |||||
| $ref = $data->getCommitRef(); | |||||
| $field_query = id(new DiffusionLowLevelCommitFieldsQuery()) | $field_query = id(new DiffusionLowLevelCommitFieldsQuery()) | ||||
| ->setRepository($repository) | ->setRepository($repository) | ||||
| ->withCommitRef($ref); | ->withCommitRef($ref); | ||||
| $field_values = $field_query->execute(); | $field_values = $field_query->execute(); | ||||
| $revision_id = idx($field_values, 'revisionID'); | $revision_id = idx($field_values, 'revisionID'); | ||||
| Show All 26 Lines | private function closeRevisions( | ||||
| $properties = array( | $properties = array( | ||||
| 'revisionMatchData' => $match_data, | 'revisionMatchData' => $match_data, | ||||
| ); | ); | ||||
| $this->queueObjectUpdate($commit, $revision, $properties); | $this->queueObjectUpdate($commit, $revision, $properties); | ||||
| } | } | ||||
| private function closeTasks( | private function closeTasks( | ||||
| PhabricatorUser $actor, | PhabricatorUser $actor, | ||||
| DiffusionCommitRef $ref, | PhabricatorRepositoryCommit $commit) { | ||||
| PhabricatorRepositoryCommit $commit, | |||||
| PhabricatorRepositoryCommitData $data) { | |||||
| $maniphest = 'PhabricatorManiphestApplication'; | $maniphest = 'PhabricatorManiphestApplication'; | ||||
| if (!PhabricatorApplication::isClassInstalled($maniphest)) { | if (!PhabricatorApplication::isClassInstalled($maniphest)) { | ||||
| return; | return; | ||||
| } | } | ||||
| $data = $commit->getCommitData(); | |||||
| $prefixes = ManiphestTaskStatus::getStatusPrefixMap(); | $prefixes = ManiphestTaskStatus::getStatusPrefixMap(); | ||||
| $suffixes = ManiphestTaskStatus::getStatusSuffixMap(); | $suffixes = ManiphestTaskStatus::getStatusSuffixMap(); | ||||
| $message = $data->getCommitMessage(); | $message = $data->getCommitMessage(); | ||||
| $matches = id(new ManiphestCustomFieldStatusParser()) | $matches = id(new ManiphestCustomFieldStatusParser()) | ||||
| ->parseCorpus($message); | ->parseCorpus($message); | ||||
| $task_map = array(); | $task_map = array(); | ||||
| ▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines | |||||