public parse ( |
||
$commitMessage | ||
return |
/** * @param WP_REST_Request $request * @return WP_REST_Response|WP_Error */ public function getCommits(WP_REST_Request $request) { $gitLogPaginator = new GitLogPaginator($this->gitRepository); $query = urldecode(stripslashes($request['query'])); $rules = QueryLanguageUtils::createRulesFromQueries([$query]); $gitLogQuery = !empty($rules) ? QueryLanguageUtils::createGitLogQueryFromRule($rules[0]) : ''; $gitLogPaginator->setQuery($gitLogQuery); $gitLogPaginator->setCommitsPerPage(25); $page = intval($request['page']); $commits = $gitLogPaginator->getPage($page); if (empty($commits)) { return new WP_Error('notice', 'No more commits to show.', ['status' => 404]); } $initialCommitHash = $this->getInitialCommitHash(); $isChildOfInitialCommit = $this->gitRepository->wasCreatedAfter($commits[0]->getHash(), $initialCommitHash); $isFirstCommit = $page === 0; $result = []; foreach ($commits as $commit) { $isChildOfInitialCommit = $isChildOfInitialCommit && $this->gitRepository->wasCreatedAfter($commit->getHash(), $initialCommitHash); $canUndoCommit = $isChildOfInitialCommit && !$commit->isMerge(); $canRollbackToThisCommit = !$isFirstCommit && ($isChildOfInitialCommit || $commit->getHash() === $initialCommitHash); $changeInfo = $this->commitMessageParser->parse($commit->getMessage()); $isEnabled = $isChildOfInitialCommit || $commit->getHash() === $initialCommitHash; $skipVpdbFiles = $changeInfo->getChangeInfoList()[0] instanceof TrackedChangeInfo; $fileChanges = $this->getFileChanges($commit, $skipVpdbFiles); $environment = $changeInfo instanceof ChangeInfoEnvelope ? $changeInfo->getEnvironment() : '?'; $changeInfoList = $changeInfo instanceof ChangeInfoEnvelope ? $changeInfo->getChangeInfoList() : []; $result[] = ["hash" => $commit->getHash(), "date" => $commit->getDate()->format('c'), "message" => $changeInfo->getChangeDescription(), "parentHashes" => $commit->getParentHashes(), "canUndo" => $canUndoCommit, "canRollback" => $canRollbackToThisCommit, "isEnabled" => $isEnabled, "isInitial" => $commit->getHash() === $initialCommitHash, "isMerge" => $commit->isMerge(), "environment" => $environment, "changes" => array_values(array_filter(array_merge($this->convertChangeInfoList($changeInfoList), $fileChanges))), "author" => ["name" => $commit->getAuthorName(), "email" => $commit->getAuthorEmail(), "avatar" => get_avatar_url($commit->getAuthorEmail())]]; $isFirstCommit = false; } return new WP_REST_Response(['pages' => $gitLogPaginator->getPrettySteps($page), 'commits' => $result]); }
private function checkReferencesForRevertedCommit(Commit $revertedCommit) { $changeInfo = $this->commitMessageParser->parse($revertedCommit->getMessage()); if ($changeInfo instanceof UntrackedChangeInfo) { return true; } foreach ($changeInfo->getChangeInfoList() as $subChangeInfo) { if ($subChangeInfo instanceof EntityChangeInfo && !$this->checkEntityReferences($subChangeInfo->getScope(), $subChangeInfo->getId(), $subChangeInfo->getParentId())) { return false; } } return true; }
/** * @param Commit $commit * @return ChangeInfoEnvelope|UntrackedChangeInfo */ protected function getChangeInfo($commit) { $commitMessageParser = new CommitMessageParser($this->dbSchema, $this->actionsInfoProvider); return $commitMessageParser->parse($commit->getMessage()); }