2013-03-15 12:28:43 +01:00
|
|
|
<?php
|
|
|
|
|
2013-03-22 14:29:37 +01:00
|
|
|
final class ReleephProject extends ReleephDAO
|
|
|
|
implements PhabricatorPolicyInterface {
|
2013-03-15 12:28:43 +01:00
|
|
|
|
|
|
|
const DEFAULT_BRANCH_NAMESPACE = 'releeph-releases';
|
|
|
|
const SYSTEM_AGENT_USERNAME_PREFIX = 'releeph-agent-';
|
|
|
|
|
|
|
|
const COMMIT_AUTHOR_NONE = 'commit-author-none';
|
|
|
|
const COMMIT_AUTHOR_FROM_DIFF = 'commit-author-is-from-diff';
|
|
|
|
const COMMIT_AUTHOR_REQUESTOR = 'commit-author-is-requestor';
|
|
|
|
|
|
|
|
protected $phid;
|
|
|
|
protected $name;
|
|
|
|
|
|
|
|
// Specifying the place to pick from is a requirement for svn, though not
|
|
|
|
// for git. It's always useful though for reasoning about what revs have
|
|
|
|
// been picked and which haven't.
|
|
|
|
protected $trunkBranch;
|
|
|
|
|
|
|
|
protected $repositoryPHID;
|
|
|
|
protected $isActive;
|
|
|
|
protected $createdByUserPHID;
|
|
|
|
protected $arcanistProjectID;
|
|
|
|
|
|
|
|
protected $details = array();
|
|
|
|
|
2013-08-14 17:59:28 +02:00
|
|
|
private $repository = self::ATTACHABLE;
|
|
|
|
|
2013-03-15 12:28:43 +01:00
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'details' => self::SERIALIZATION_JSON,
|
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
2013-07-21 17:41:38 +02:00
|
|
|
return PhabricatorPHID::generateNewPHID(ReleephPHIDTypeProject::TYPECONST);
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getDetail($key, $default = null) {
|
|
|
|
return idx($this->details, $key, $default);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI($path = null) {
|
|
|
|
$components = array(
|
|
|
|
'/releeph/project',
|
|
|
|
$this->getID(),
|
|
|
|
$path
|
|
|
|
);
|
2013-05-22 16:42:30 +02:00
|
|
|
return implode('/', $components);
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setDetail($key, $value) {
|
|
|
|
$this->details[$key] = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function willSaveObject() {
|
|
|
|
// Do this first, to generate the PHID
|
|
|
|
parent::willSaveObject();
|
|
|
|
|
|
|
|
$banned_names = $this->getBannedNames();
|
|
|
|
if (in_array($this->name, $banned_names)) {
|
|
|
|
throw new Exception(sprintf(
|
|
|
|
"The name '%s' is in the list of banned project names!",
|
|
|
|
$this->name,
|
|
|
|
implode(', ', $banned_names)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->getDetail('releaseCounter')) {
|
|
|
|
$this->setDetail('releaseCounter', 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function loadArcanistProject() {
|
|
|
|
return $this->loadOneRelative(
|
|
|
|
new PhabricatorRepositoryArcanistProject(),
|
|
|
|
'id',
|
|
|
|
'getArcanistProjectID');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPushers() {
|
|
|
|
return $this->getDetail('pushers', array());
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:45:12 +02:00
|
|
|
public function isPusher(PhabricatorUser $user) {
|
|
|
|
// TODO Deprecate this once `isPusher` is out of the Facebook codebase.
|
|
|
|
return $this->isAuthoritative($user);
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
|
2013-04-18 18:45:12 +02:00
|
|
|
public function isAuthoritative(PhabricatorUser $user) {
|
|
|
|
return $this->isAuthoritativePHID($user->getPHID());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isAuthoritativePHID($phid) {
|
|
|
|
$pushers = $this->getPushers();
|
|
|
|
if (!$pushers) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return in_array($phid, $pushers);
|
|
|
|
}
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
|
2013-08-14 17:59:28 +02:00
|
|
|
public function attachRepository(PhabricatorRepository $repository) {
|
|
|
|
$this->repository = $repository;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRepository() {
|
|
|
|
return $this->assertAttached($this->repository);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Remove once everything uses ProjectQuery.
|
2013-03-15 12:28:43 +01:00
|
|
|
public function loadPhabricatorRepository() {
|
|
|
|
return $this->loadOneRelative(
|
|
|
|
new PhabricatorRepository(),
|
2013-08-14 17:59:28 +02:00
|
|
|
'phid',
|
|
|
|
'getRepositoryPHID');
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCurrentReleaseNumber() {
|
|
|
|
$current_release_numbers = array();
|
|
|
|
|
|
|
|
// From the project...
|
|
|
|
$current_release_numbers[] = $this->getDetail('releaseCounter', 0);
|
|
|
|
|
|
|
|
// From any branches...
|
|
|
|
$branches = id(new ReleephBranch())->loadAllWhere(
|
|
|
|
'releephProjectID = %d', $this->getID());
|
|
|
|
if ($branches) {
|
|
|
|
$release_numbers = array();
|
|
|
|
foreach ($branches as $branch) {
|
|
|
|
$current_release_numbers[] = $branch->getDetail('releaseNumber', 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return max($current_release_numbers);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getReleephFieldSelector() {
|
2013-08-14 17:58:54 +02:00
|
|
|
return new ReleephDefaultFieldSelector();
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper to setIsActive() that logs who deactivated a project
|
|
|
|
*/
|
|
|
|
public function deactivate(PhabricatorUser $actor) {
|
|
|
|
return $this
|
|
|
|
->setIsActive(0)
|
|
|
|
->setDetail('last_deactivated_user', $actor->getPHID())
|
|
|
|
->setDetail('last_deactivated_time', time());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide this from the public
|
|
|
|
private function setIsActive($v) {
|
|
|
|
return parent::setIsActive($v);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getBannedNames() {
|
|
|
|
return array(
|
|
|
|
'branch', // no one's tried this... yet!
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isTestFile($filename) {
|
|
|
|
$test_paths = $this->getDetail('testPaths', array());
|
|
|
|
|
|
|
|
foreach ($test_paths as $test_path) {
|
|
|
|
if (preg_match($test_path, $filename)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-22 14:29:37 +01:00
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
return PhabricatorPolicies::POLICY_USER;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|