Source of file DNCommit.php
Size: 3,840 Bytes - Last Modified: 2021-12-23T10:29:15+00:00
/var/www/docs.ssmods.com/process/src/code/model/DNCommit.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 | <?php class DNCommit extends ViewableData { /** * * @var Gitonomy\Git\Commit */ protected $commit = null; protected $name = null; protected $references = null; protected $ownerBranchName = null; private static $casting = array( 'Name' => 'Text', 'SubjectMessage' => 'Text', 'Message' => 'Text', 'BodyMessage' => 'Text', 'Fullname' => 'Text', 'Filename' => 'Text', 'References' => 'Text', 'ownerBranchName' => 'Text' ); /** * * @param Gitonomy\Git\Commit $commit * @param DNProject $project * @param DNData $data */ public function __construct(Gitonomy\Git\Commit $commit, DNProject $project, DNData $data, $ownerBranchName = null) { $this->commit = $commit; $this->buildname = $commit->getHash(); $this->project = $project; $this->data = $data; $this->ownerBranchName = $ownerBranchName; } /** * Return the hash of the commit, used to name this commit. * @return string */ public function Name() { if($this->name == null) { $this->name = $this->commit->getFixedShortHash(8); } return htmlentities($this->name); } /** * Return the first line of the commit message. * @return string */ public function SubjectMessage() { if($this->subjectMessage == null) { $this->subjectMessage = $this->commit->getSubjectMessage(); } return htmlentities($this->subjectMessage); } public function BodyMessage() { if($this->bodyMessage == null) { $this->bodyMessage = $this->commit->getBodyMessage(); } return htmlentities($this->bodyMessage); } /** * * @return ArrayList */ public function References() { if($this->references !== null ) { return $this->references; } $this->references = new ArrayList(); // Add tags foreach($this->commit->resolveReferences() as $reference) { if($reference instanceof \Gitonomy\Git\Reference\Tag) { $this->references->push(new ArrayData(array( 'Name' => $reference->getName(), 'Type' => 'Tag', ))); } } return $this->references; } /** * * @return string */ public function FullName() { return htmlentities($this->commit->getHash()); } /** * * @return string */ public function Filename() { return htmlentities($this->commit->getHash()); } /** * * @return ArrayList */ public function CurrentlyDeployedTo() { $environments = $this->project->Environments(); $envList = new ArrayList(); foreach($environments as $environment) { $deployments = DNDeployment::get() ->filter('Status', 'Finished') ->filter('EnvironmentID', $environment->ID) ->sort('LastEdited DESC'); if(!$deployments->count()) { continue; } $latest = $deployments->first(); if($latest->SHA === $this->commit->getHash()) { $envList->push($environment); } } return $envList; } /** * * @param string $environmentName * @return boolean True if this release has ever been deployed to the given environment */ public function EverDeployedTo($environmentName) { $environments = $this->project->Environments()->filter('Name', $environmentName); if(!$environments->count()) { return false; } $environment = $environments->first(); $deployments = DNDeployment::get() ->filter('Status', 'Finished') ->filter('EnvironmentID', $environment->ID); if($deployments->count()) { return true; } return false; } /** * * @return SS_Datetime */ public function Created() { $created = $this->commit->getCommitterDate(); // gitonomy sets the time to UTC, so now we set the timezone to // whatever PHP is set to (date.timezone). This will change in the future if each // deploynaut user has their own timezone $created->setTimezone(new DateTimeZone(date_default_timezone_get())); $d = new SS_Datetime(); $d->setValue($created->format('Y-m-d H:i:s')); return $d; } } |