本文整理汇总了PHP中PhabricatorRepository::initializeNewRepository方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorRepository::initializeNewRepository方法的具体用法?PHP PhabricatorRepository::initializeNewRepository怎么用?PHP PhabricatorRepository::initializeNewRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhabricatorRepository
的用法示例。
在下文中一共展示了PhabricatorRepository::initializeNewRepository方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildBareRepository
protected function buildBareRepository($callsign)
{
$existing_repository = id(new PhabricatorRepositoryQuery())->withCallsigns(array($callsign))->setViewer(PhabricatorUser::getOmnipotentUser())->executeOne();
if ($existing_repository) {
$existing_repository->delete();
}
$data_dir = dirname(__FILE__) . '/data/';
$types = array('svn' => PhabricatorRepositoryType::REPOSITORY_TYPE_SVN, 'hg' => PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL, 'git' => PhabricatorRepositoryType::REPOSITORY_TYPE_GIT);
$hits = array();
foreach ($types as $type => $const) {
$path = $data_dir . $callsign . '.' . $type . '.tgz';
if (Filesystem::pathExists($path)) {
$hits[$const] = $path;
}
}
if (!$hits) {
throw new Exception("No test data for callsign '{$callsign}'. Expected an archive " . "like '{$callsign}.git.tgz' in '{$data_dir}'.");
}
if (count($hits) > 1) {
throw new Exception("Expected exactly one archive matching callsign '{$callsign}', " . "found too many: " . implode(', ', $hits));
}
$path = head($hits);
$vcs_type = head_key($hits);
$dir = PhutilDirectoryFixture::newFromArchive($path);
$local = new TempFile('.ignore');
$user = $this->generateNewTestUser();
$repo = PhabricatorRepository::initializeNewRepository($user)->setCallsign($callsign)->setName(pht('Test Repo "%s"', $callsign))->setVersionControlSystem($vcs_type)->setDetail('local-path', dirname($local) . '/' . $callsign)->setDetail('remote-uri', 'file://' . $dir->getPath() . '/');
$this->didConstructRepository($repo);
$repo->save();
$repo->makeEphemeral();
// Keep the disk resources around until we exit.
$this->dirs[] = $dir;
$this->dirs[] = $local;
return $repo;
}
示例2: newEditableObject
protected function newEditableObject()
{
$viewer = $this->getViewer();
$repository = PhabricatorRepository::initializeNewRepository($viewer);
$repository->setDetail('newly-initialized', true);
$vcs = $this->getVersionControlSystem();
if ($vcs) {
$repository->setVersionControlSystem($vcs);
}
// Pick a random open service to allocate this repository on, if any exist.
// If there are no services, we aren't in cluster mode and will allocate
// locally. If there are services but none permit allocations, we fail.
// Eventually we can make this more flexible, but this rule is a reasonable
// starting point as we begin to deploy cluster services.
$services = id(new AlmanacServiceQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withServiceTypes(array(AlmanacClusterRepositoryServiceType::SERVICETYPE))->needProperties(true)->execute();
if ($services) {
// Filter out services which do not permit new allocations.
foreach ($services as $key => $possible_service) {
if ($possible_service->getAlmanacPropertyValue('closed')) {
unset($services[$key]);
}
}
if (!$services) {
throw new Exception(pht('This install is configured in cluster mode, but all available ' . 'repository cluster services are closed to new allocations. ' . 'At least one service must be open to allow new allocations to ' . 'take place.'));
}
shuffle($services);
$service = head($services);
$repository->setAlmanacServicePHID($service->getPHID());
}
return $repository;
}
示例3: testURIGeneration
public function testURIGeneration()
{
$actor = PhabricatorUser::getOmnipotentUser();
$repository = PhabricatorRepository::initializeNewRepository($actor)->setCallsign('A')->makeEphemeral();
$map = array('/diffusion/A/browse/branch/path.ext;abc$1' => array('action' => 'browse', 'branch' => 'branch', 'path' => 'path.ext', 'commit' => 'abc', 'line' => '1'), '/diffusion/A/browse/a%252Fb/path.ext' => array('action' => 'browse', 'branch' => 'a/b', 'path' => 'path.ext'), '/diffusion/A/browse/%2B/%20%21' => array('action' => 'browse', 'path' => '+/ !'), '/diffusion/A/browse/money/%24%24100$2' => array('action' => 'browse', 'path' => 'money/$100', 'line' => '2'), '/diffusion/A/browse/path/to/file.ext?view=things' => array('action' => 'browse', 'path' => 'path/to/file.ext', 'params' => array('view' => 'things')), '/diffusion/A/repository/master/' => array('action' => 'branch', 'branch' => 'master'), 'path/to/file.ext;abc' => array('action' => 'rendering-ref', 'path' => 'path/to/file.ext', 'commit' => 'abc'), '/diffusion/A/browse/branch/path.ext$3-5%2C7-12%2C14' => array('action' => 'browse', 'branch' => 'branch', 'path' => 'path.ext', 'line' => '3-5,7-12,14'));
foreach ($map as $expect => $input) {
$actual = $repository->generateURI($input);
$this->assertEqual($expect, (string) $actual);
}
}
示例4: testURIGeneration
public function testURIGeneration()
{
$svn = PhabricatorRepositoryType::REPOSITORY_TYPE_SVN;
$git = PhabricatorRepositoryType::REPOSITORY_TYPE_GIT;
$hg = PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL;
$user = $this->generateNewTestUser();
$http_secret = id(new PassphraseSecret())->setSecretData('quack')->save();
$http_credential = PassphraseCredential::initializeNewCredential($user)->setCredentialType(PassphrasePasswordCredentialType::CREDENTIAL_TYPE)->setProvidesType(PassphrasePasswordCredentialType::PROVIDES_TYPE)->setUsername('duck')->setSecretID($http_secret->getID())->save();
$repo = PhabricatorRepository::initializeNewRepository($user)->setVersionControlSystem($svn)->setName(pht('Test Repo'))->setCallsign('TESTREPO')->setCredentialPHID($http_credential->getPHID())->save();
// Test HTTP URIs.
$repo->setDetail('remote-uri', 'http://example.com/');
$repo->setVersionControlSystem($svn);
$this->assertEqual('http://example.com/', $repo->getRemoteURI());
$this->assertEqual('http://example.com/', $repo->getPublicCloneURI());
$this->assertEqual('http://example.com/', $repo->getRemoteURIEnvelope()->openEnvelope());
$repo->setVersionControlSystem($git);
$this->assertEqual('http://example.com/', $repo->getRemoteURI());
$this->assertEqual('http://example.com/', $repo->getPublicCloneURI());
$this->assertEqual('http://duck:quack@example.com/', $repo->getRemoteURIEnvelope()->openEnvelope());
$repo->setVersionControlSystem($hg);
$this->assertEqual('http://example.com/', $repo->getRemoteURI());
$this->assertEqual('http://example.com/', $repo->getPublicCloneURI());
$this->assertEqual('http://duck:quack@example.com/', $repo->getRemoteURIEnvelope()->openEnvelope());
// Test SSH URIs.
$repo->setDetail('remote-uri', 'ssh://example.com/');
$repo->setVersionControlSystem($svn);
$this->assertEqual('ssh://example.com/', $repo->getRemoteURI());
$this->assertEqual('ssh://example.com/', $repo->getPublicCloneURI());
$this->assertEqual('ssh://example.com/', $repo->getRemoteURIEnvelope()->openEnvelope());
$repo->setVersionControlSystem($git);
$this->assertEqual('ssh://example.com/', $repo->getRemoteURI());
$this->assertEqual('ssh://example.com/', $repo->getPublicCloneURI());
$this->assertEqual('ssh://example.com/', $repo->getRemoteURIEnvelope()->openEnvelope());
$repo->setVersionControlSystem($hg);
$this->assertEqual('ssh://example.com/', $repo->getRemoteURI());
$this->assertEqual('ssh://example.com/', $repo->getPublicCloneURI());
$this->assertEqual('ssh://example.com/', $repo->getRemoteURIEnvelope()->openEnvelope());
// Test Git URIs.
$repo->setDetail('remote-uri', 'git@example.com:path.git');
$repo->setVersionControlSystem($git);
$this->assertEqual('git@example.com:path.git', $repo->getRemoteURI());
$this->assertEqual('git@example.com:path.git', $repo->getPublicCloneURI());
$this->assertEqual('git@example.com:path.git', $repo->getRemoteURIEnvelope()->openEnvelope());
// Test SVN "Import Only" paths.
$repo->setDetail('remote-uri', 'http://example.com/');
$repo->setVersionControlSystem($svn);
$repo->setDetail('svn-subpath', 'projects/example/');
$this->assertEqual('http://example.com/', $repo->getRemoteURI());
$this->assertEqual('http://example.com/projects/example/', $repo->getPublicCloneURI());
$this->assertEqual('http://example.com/', $repo->getRemoteURIEnvelope()->openEnvelope());
}
示例5: getManagementPanelIcon
public function getManagementPanelIcon()
{
$viewer = $this->getViewer();
$repository = $this->getRepository();
$can_view = PhabricatorPolicyCapability::CAN_VIEW;
$can_edit = PhabricatorPolicyCapability::CAN_EDIT;
$can_push = DiffusionPushCapability::CAPABILITY;
$actual_values = array('spacePHID' => $repository->getSpacePHID(), 'view' => $repository->getPolicy($can_view), 'edit' => $repository->getPolicy($can_edit), 'push' => $repository->getPolicy($can_push));
$default = PhabricatorRepository::initializeNewRepository($viewer);
$default_values = array('spacePHID' => $default->getSpacePHID(), 'view' => $default->getPolicy($can_view), 'edit' => $default->getPolicy($can_edit), 'push' => $default->getPolicy($can_push));
if ($actual_values === $default_values) {
return 'fa-lock grey';
} else {
return 'fa-lock';
}
}
示例6: execute
protected function execute(ConduitAPIRequest $request)
{
$application = id(new PhabricatorApplicationQuery())->setViewer($request->getUser())->withClasses(array('PhabricatorDiffusionApplication'))->executeOne();
PhabricatorPolicyFilter::requireCapability($request->getUser(), $application, DiffusionCreateRepositoriesCapability::CAPABILITY);
// TODO: This has some duplication with (and lacks some of the validation
// of) the web workflow; refactor things so they can share more code as this
// stabilizes. Specifically, this should move to transactions since they
// work properly now.
$repository = PhabricatorRepository::initializeNewRepository($request->getUser());
$repository->setName($request->getValue('name'));
$callsign = $request->getValue('callsign');
if (!preg_match('/^[A-Z]+\\z/', $callsign)) {
throw new ConduitException('ERR-BAD-CALLSIGN');
}
$repository->setCallsign($callsign);
$local_path = PhabricatorEnv::getEnvConfig('repository.default-local-path');
$local_path = rtrim($local_path, '/');
$local_path = $local_path . '/' . $callsign . '/';
$vcs = $request->getValue('vcs');
$map = array('git' => PhabricatorRepositoryType::REPOSITORY_TYPE_GIT, 'hg' => PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL, 'svn' => PhabricatorRepositoryType::REPOSITORY_TYPE_SVN);
if (empty($map[$vcs])) {
throw new ConduitException('ERR-UNKNOWN-REPOSITORY-VCS');
}
$repository->setVersionControlSystem($map[$vcs]);
$repository->setCredentialPHID($request->getValue('credentialPHID'));
$remote_uri = $request->getValue('uri');
PhabricatorRepository::assertValidRemoteURI($remote_uri);
$details = array('encoding' => $request->getValue('encoding'), 'description' => $request->getValue('description'), 'tracking-enabled' => (bool) $request->getValue('tracking', true), 'remote-uri' => $remote_uri, 'local-path' => $local_path, 'branch-filter' => array_fill_keys($request->getValue('branchFilter', array()), true), 'close-commits-filter' => array_fill_keys($request->getValue('closeCommitsFilter', array()), true), 'pull-frequency' => $request->getValue('pullFrequency'), 'default-branch' => $request->getValue('defaultBranch'), 'herald-disabled' => !$request->getValue('heraldEnabled', true), 'svn-subpath' => $request->getValue('svnSubpath'), 'disable-autoclose' => !$request->getValue('autocloseEnabled', true));
foreach ($details as $key => $value) {
$repository->setDetail($key, $value);
}
try {
$repository->save();
} catch (AphrontDuplicateKeyQueryException $ex) {
throw new ConduitException('ERR-DUPLICATE');
}
return $repository->toDictionary();
}
示例7: validatePolicyPage
public function validatePolicyPage(PHUIFormPageView $page)
{
$form = $page->getForm();
$viewer = $this->getRequest()->getUser();
$c_view = $page->getControl('viewPolicy');
$c_edit = $page->getControl('editPolicy');
$c_push = $page->getControl('pushPolicy');
$v_view = $c_view->getValue();
$v_edit = $c_edit->getValue();
$v_push = $c_push->getValue();
if ($this->getRepository()) {
$repository = $this->getRepository();
} else {
$repository = PhabricatorRepository::initializeNewRepository($viewer);
}
$proxy = clone $repository;
$proxy->setViewPolicy($v_view);
$proxy->setEditPolicy($v_edit);
$can_view = PhabricatorPolicyFilter::hasCapability($viewer, $proxy, PhabricatorPolicyCapability::CAN_VIEW);
$can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $proxy, PhabricatorPolicyCapability::CAN_EDIT);
if (!$can_view) {
$c_view->setError(pht('Invalid'));
$page->addPageError(pht('You can not use the selected policy, because you would be unable ' . 'to see the repository.'));
}
if (!$can_edit) {
$c_edit->setError(pht('Invalid'));
$page->addPageError(pht('You can not use the selected edit policy, because you would be ' . 'unable to edit the repository.'));
}
return $c_view->isValid() && $c_edit->isValid();
}