public CurrentBuild ( ) : false | DNDeployment | ||
return | false | DNDeployment |
public function CurrentBuild()
{
// The DeployHistory function is far too slow to use for this
/** @var DNDeployment $deploy */
$deploy = DNDeployment::get()->filter(['EnvironmentID' => $this->ID, 'State' => DNDeployment::STATE_COMPLETED])->sort('LastEdited DESC')->first();
if (!$deploy || !$deploy->SHA) {
return false;
}
$repo = $this->Project()->getRepository();
if (!$repo) {
return $deploy;
}
try {
$commit = $this->getCommit($deploy->SHA);
if ($commit) {
$deploy->Message = Convert::raw2xml($this->getCommitMessage($commit));
$deploy->Committer = Convert::raw2xml($commit->getCommitterName());
$deploy->CommitDate = $commit->getCommitterDate()->Format('d/m/Y g:ia');
$deploy->Author = Convert::raw2xml($commit->getAuthorName());
$deploy->AuthorDate = $commit->getAuthorDate()->Format('d/m/Y g:ia');
}
// We can't find this SHA, so we ignore adding a commit message to the deployment
} catch (Exception $ex) {
}
return $deploy;
}
/** * @param \SS_HTTPRequest $request * @return \SS_HTTPResponse */ public function redeploy(\SS_HTTPRequest $request) { $currentBuild = $this->environment->CurrentBuild(); if (!$currentBuild || !$currentBuild->exists()) { return $this->redirect(Controller::join_links($this->environment->Link(\EnvironmentOverview::ACTION_OVERVIEW), 'deployment', 'new')); } $strategy = $this->environment->Backend()->planDeploy($this->environment, ['sha' => $currentBuild->SHA, 'ref_type' => \GitDispatcher::REF_TYPE_PREVIOUS, 'ref_name' => $currentBuild->RefName]); $deployment = $strategy->createDeployment(); return $this->redirect($deployment->Link()); }