Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/storage/PhabricatorRepository.php
Show All 40 Lines | final class PhabricatorRepository extends PhabricatorRepositoryDAO | ||||
const BECAUSE_REPOSITORY_IMPORTING = 'auto/importing'; | const BECAUSE_REPOSITORY_IMPORTING = 'auto/importing'; | ||||
const BECAUSE_AUTOCLOSE_DISABLED = 'auto/disabled'; | const BECAUSE_AUTOCLOSE_DISABLED = 'auto/disabled'; | ||||
const BECAUSE_NOT_ON_AUTOCLOSE_BRANCH = 'auto/nobranch'; | const BECAUSE_NOT_ON_AUTOCLOSE_BRANCH = 'auto/nobranch'; | ||||
const BECAUSE_BRANCH_UNTRACKED = 'auto/notrack'; | const BECAUSE_BRANCH_UNTRACKED = 'auto/notrack'; | ||||
const BECAUSE_BRANCH_NOT_AUTOCLOSE = 'auto/noclose'; | const BECAUSE_BRANCH_NOT_AUTOCLOSE = 'auto/noclose'; | ||||
const BECAUSE_AUTOCLOSE_FORCED = 'auto/forced'; | const BECAUSE_AUTOCLOSE_FORCED = 'auto/forced'; | ||||
const STATUS_ACTIVE = 'active'; | |||||
const STATUS_INACTIVE = 'inactive'; | |||||
protected $name; | protected $name; | ||||
protected $callsign; | protected $callsign; | ||||
protected $repositorySlug; | protected $repositorySlug; | ||||
protected $uuid; | protected $uuid; | ||||
protected $viewPolicy; | protected $viewPolicy; | ||||
protected $editPolicy; | protected $editPolicy; | ||||
protected $pushPolicy; | protected $pushPolicy; | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | protected function getConfiguration() { | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function generatePHID() { | public function generatePHID() { | ||||
return PhabricatorPHID::generateNewPHID( | return PhabricatorPHID::generateNewPHID( | ||||
PhabricatorRepositoryRepositoryPHIDType::TYPECONST); | PhabricatorRepositoryRepositoryPHIDType::TYPECONST); | ||||
} | } | ||||
public static function getStatusMap() { | |||||
return array( | |||||
self::STATUS_ACTIVE => array( | |||||
'name' => pht('Active'), | |||||
'isTracked' => 1, | |||||
), | |||||
self::STATUS_INACTIVE => array( | |||||
'name' => pht('Inactive'), | |||||
'isTracked' => 0, | |||||
), | |||||
); | |||||
} | |||||
public static function getStatusNameMap() { | |||||
return ipull(self::getStatusMap(), 'name'); | |||||
} | |||||
public function getStatus() { | |||||
if ($this->isTracked()) { | |||||
return self::STATUS_ACTIVE; | |||||
} else { | |||||
return self::STATUS_INACTIVE; | |||||
} | |||||
} | |||||
public function toDictionary() { | public function toDictionary() { | ||||
return array( | return array( | ||||
'id' => $this->getID(), | 'id' => $this->getID(), | ||||
'name' => $this->getName(), | 'name' => $this->getName(), | ||||
'phid' => $this->getPHID(), | 'phid' => $this->getPHID(), | ||||
'callsign' => $this->getCallsign(), | 'callsign' => $this->getCallsign(), | ||||
'monogram' => $this->getMonogram(), | 'monogram' => $this->getMonogram(), | ||||
'vcs' => $this->getVersionControlSystem(), | 'vcs' => $this->getVersionControlSystem(), | ||||
'uri' => PhabricatorEnv::getProductionURI($this->getURI()), | 'uri' => PhabricatorEnv::getProductionURI($this->getURI()), | ||||
'remoteURI' => (string)$this->getRemoteURI(), | 'remoteURI' => (string)$this->getRemoteURI(), | ||||
'description' => $this->getDetail('description'), | 'description' => $this->getDetail('description'), | ||||
'isActive' => $this->isTracked(), | 'isActive' => $this->isTracked(), | ||||
'isHosted' => $this->isHosted(), | 'isHosted' => $this->isHosted(), | ||||
'isImporting' => $this->isImporting(), | 'isImporting' => $this->isImporting(), | ||||
'encoding' => $this->getDetail('encoding'), | 'encoding' => $this->getDefaultTextEncoding(), | ||||
'staging' => array( | 'staging' => array( | ||||
'supported' => $this->supportsStaging(), | 'supported' => $this->supportsStaging(), | ||||
'prefix' => 'phabricator', | 'prefix' => 'phabricator', | ||||
'uri' => $this->getStagingURI(), | 'uri' => $this->getStagingURI(), | ||||
), | ), | ||||
); | ); | ||||
} | } | ||||
public function getDefaultTextEncoding() { | |||||
return $this->getDetail('encoding', 'UTF-8'); | |||||
} | |||||
public function getMonogram() { | public function getMonogram() { | ||||
$callsign = $this->getCallsign(); | $callsign = $this->getCallsign(); | ||||
if (strlen($callsign)) { | if (strlen($callsign)) { | ||||
return "r{$callsign}"; | return "r{$callsign}"; | ||||
} | } | ||||
$id = $this->getID(); | $id = $this->getID(); | ||||
return "R{$id}"; | return "R{$id}"; | ||||
▲ Show 20 Lines • Show All 823 Lines • ▼ Show 20 Lines | switch ($this->getVersionControlSystem()) { | ||||
PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL, | PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL, | ||||
$uri); | $uri); | ||||
default: | default: | ||||
throw new Exception(pht('Unrecognized version control system.')); | throw new Exception(pht('Unrecognized version control system.')); | ||||
} | } | ||||
} | } | ||||
public function isTracked() { | public function isTracked() { | ||||
return $this->getDetail('tracking-enabled', false); | $status = $this->getDetail('tracking-enabled'); | ||||
$map = self::getStatusMap(); | |||||
$spec = idx($map, $status); | |||||
if (!$spec) { | |||||
if ($status) { | |||||
$status = self::STATUS_ACTIVE; | |||||
} else { | |||||
$status = self::STATUS_INACTIVE; | |||||
} | |||||
$spec = idx($map, $status); | |||||
} | |||||
return (bool)idx($spec, 'isTracked', false); | |||||
} | } | ||||
public function getDefaultBranch() { | public function getDefaultBranch() { | ||||
$default = $this->getDetail('default-branch'); | $default = $this->getDetail('default-branch'); | ||||
if (strlen($default)) { | if (strlen($default)) { | ||||
return $default; | return $default; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,757 Lines • Show Last 20 Lines |