Path: blob/master/src/applications/diffusion/editor/DiffusionRepositoryEditEngine.php
12242 views
<?php12final class DiffusionRepositoryEditEngine3extends PhabricatorEditEngine {45const ENGINECONST = 'diffusion.repository';67private $versionControlSystem;89public function setVersionControlSystem($version_control_system) {10$this->versionControlSystem = $version_control_system;11return $this;12}1314public function getVersionControlSystem() {15return $this->versionControlSystem;16}1718public function isEngineConfigurable() {19return false;20}2122public function isDefaultQuickCreateEngine() {23return true;24}2526public function getQuickCreateOrderVector() {27return id(new PhutilSortVector())->addInt(300);28}2930public function getEngineName() {31return pht('Repositories');32}3334public function getSummaryHeader() {35return pht('Edit Repositories');36}3738public function getSummaryText() {39return pht('Creates and edits repositories.');40}4142public function getEngineApplicationClass() {43return 'PhabricatorDiffusionApplication';44}4546protected function newEditableObject() {47$viewer = $this->getViewer();48$repository = PhabricatorRepository::initializeNewRepository($viewer);4950$repository->setDetail('newly-initialized', true);5152$vcs = $this->getVersionControlSystem();53if ($vcs) {54$repository->setVersionControlSystem($vcs);55}5657// Pick a random open service to allocate this repository on, if any exist.58// If there are no services, we aren't in cluster mode and will allocate59// locally. If there are services but none permit allocations, we fail.6061// Eventually we can make this more flexible, but this rule is a reasonable62// starting point as we begin to deploy cluster services.6364$services = id(new AlmanacServiceQuery())65->setViewer(PhabricatorUser::getOmnipotentUser())66->withServiceTypes(67array(68AlmanacClusterRepositoryServiceType::SERVICETYPE,69))70->needProperties(true)71->execute();72if ($services) {73// Filter out services which do not permit new allocations.74foreach ($services as $key => $possible_service) {75if ($possible_service->getAlmanacPropertyValue('closed')) {76unset($services[$key]);77}78}7980if (!$services) {81throw new Exception(82pht(83'This install is configured in cluster mode, but all available '.84'repository cluster services are closed to new allocations. '.85'At least one service must be open to allow new allocations to '.86'take place.'));87}8889shuffle($services);90$service = head($services);9192$repository->setAlmanacServicePHID($service->getPHID());93}9495return $repository;96}9798protected function newObjectQuery() {99return new PhabricatorRepositoryQuery();100}101102protected function getObjectCreateTitleText($object) {103return pht('Create Repository');104}105106protected function getObjectCreateButtonText($object) {107return pht('Create Repository');108}109110protected function getObjectEditTitleText($object) {111return pht('Edit Repository: %s', $object->getName());112}113114protected function getObjectEditShortText($object) {115return $object->getDisplayName();116}117118protected function getObjectCreateShortText() {119return pht('Create Repository');120}121122protected function getObjectName() {123return pht('Repository');124}125126protected function getObjectViewURI($object) {127return $object->getPathURI('manage/');128}129130protected function getCreateNewObjectPolicy() {131return $this->getApplication()->getPolicy(132DiffusionCreateRepositoriesCapability::CAPABILITY);133}134135protected function newPages($object) {136$panels = DiffusionRepositoryManagementPanel::getAllPanels();137138$pages = array();139$uris = array();140foreach ($panels as $panel_key => $panel) {141$panel->setRepository($object);142143$uris[$panel_key] = $panel->getPanelURI();144145$page = $panel->newEditEnginePage();146if (!$page) {147continue;148}149$pages[] = $page;150}151152$basics_key = DiffusionRepositoryBasicsManagementPanel::PANELKEY;153$basics_uri = $uris[$basics_key];154155$more_pages = array(156id(new PhabricatorEditPage())157->setKey('encoding')158->setLabel(pht('Text Encoding'))159->setViewURI($basics_uri)160->setFieldKeys(161array(162'encoding',163)),164id(new PhabricatorEditPage())165->setKey('extensions')166->setLabel(pht('Extensions'))167->setIsDefault(true),168);169170foreach ($more_pages as $page) {171$pages[] = $page;172}173174return $pages;175}176177protected function willConfigureFields($object, array $fields) {178// Change the default field order so related fields are adjacent.179$after = array(180'policy.edit' => array('policy.push'),181);182183$result = array();184foreach ($fields as $key => $value) {185$result[$key] = $value;186187if (!isset($after[$key])) {188continue;189}190191foreach ($after[$key] as $next_key) {192if (!isset($fields[$next_key])) {193continue;194}195196unset($result[$next_key]);197$result[$next_key] = $fields[$next_key];198unset($fields[$next_key]);199}200}201202return $result;203}204205206protected function buildCustomEditFields($object) {207$viewer = $this->getViewer();208209$policies = id(new PhabricatorPolicyQuery())210->setViewer($viewer)211->setObject($object)212->execute();213214$fetch_value = $object->getFetchRules();215$track_value = $object->getTrackOnlyRules();216$permanent_value = $object->getPermanentRefRules();217218$automation_instructions = pht(219"Configure **Repository Automation** to allow this server to ".220"write to this repository.".221"\n\n".222"IMPORTANT: This feature is new, experimental, and not supported. ".223"Use it at your own risk.");224225$staging_instructions = pht(226"To make it easier to run integration tests and builds on code ".227"under review, you can configure a **Staging Area**. When `arc` ".228"creates a diff, it will push a copy of the changes to the ".229"configured staging area with a corresponding tag.".230"\n\n".231"IMPORTANT: This feature is new, experimental, and not supported. ".232"Use it at your own risk.");233234$subpath_instructions = pht(235'If you want to import only part of a repository, like `trunk/`, '.236'you can set a path in **Import Only**. The import process will ignore '.237'commits which do not affect this path.');238239$filesize_warning = null;240if ($object->isGit()) {241$git_binary = PhutilBinaryAnalyzer::getForBinary('git');242$git_version = $git_binary->getBinaryVersion();243$filesize_version = '1.8.4';244if (version_compare($git_version, $filesize_version, '<')) {245$filesize_warning = pht(246'(WARNING) {icon exclamation-triangle} The version of "git" ("%s") '.247'installed on this server does not support '.248'"--batch-check=<format>", a feature required to enforce filesize '.249'limits. Upgrade to "git" %s or newer to use this feature.',250$git_version,251$filesize_version);252}253}254255$track_instructions = pht(256'WARNING: The "Track Only" feature is deprecated. Use "Fetch Refs" '.257'and "Permanent Refs" instead. This feature will be removed in a '.258'future version of this software.');259260return array(261id(new PhabricatorSelectEditField())262->setKey('vcs')263->setLabel(pht('Version Control System'))264->setTransactionType(265PhabricatorRepositoryVCSTransaction::TRANSACTIONTYPE)266->setIsFormField(false)267->setIsCopyable(true)268->setOptions(PhabricatorRepositoryType::getAllRepositoryTypes())269->setDescription(pht('Underlying repository version control system.'))270->setConduitDescription(271pht(272'Choose which version control system to use when creating a '.273'repository.'))274->setConduitTypeDescription(pht('Version control system selection.'))275->setValue($object->getVersionControlSystem()),276id(new PhabricatorTextEditField())277->setKey('name')278->setLabel(pht('Name'))279->setIsRequired(true)280->setTransactionType(281PhabricatorRepositoryNameTransaction::TRANSACTIONTYPE)282->setDescription(pht('The repository name.'))283->setConduitDescription(pht('Rename the repository.'))284->setConduitTypeDescription(pht('New repository name.'))285->setValue($object->getName()),286id(new PhabricatorTextEditField())287->setKey('callsign')288->setLabel(pht('Callsign'))289->setTransactionType(290PhabricatorRepositoryCallsignTransaction::TRANSACTIONTYPE)291->setDescription(pht('The repository callsign.'))292->setConduitDescription(pht('Change the repository callsign.'))293->setConduitTypeDescription(pht('New repository callsign.'))294->setValue($object->getCallsign()),295id(new PhabricatorTextEditField())296->setKey('shortName')297->setLabel(pht('Short Name'))298->setTransactionType(299PhabricatorRepositorySlugTransaction::TRANSACTIONTYPE)300->setDescription(pht('Short, unique repository name.'))301->setConduitDescription(pht('Change the repository short name.'))302->setConduitTypeDescription(pht('New short name for the repository.'))303->setValue($object->getRepositorySlug()),304id(new PhabricatorRemarkupEditField())305->setKey('description')306->setLabel(pht('Description'))307->setTransactionType(308PhabricatorRepositoryDescriptionTransaction::TRANSACTIONTYPE)309->setDescription(pht('Repository description.'))310->setConduitDescription(pht('Change the repository description.'))311->setConduitTypeDescription(pht('New repository description.'))312->setValue($object->getDetail('description')),313id(new PhabricatorTextEditField())314->setKey('encoding')315->setLabel(pht('Text Encoding'))316->setIsCopyable(true)317->setTransactionType(318PhabricatorRepositoryEncodingTransaction::TRANSACTIONTYPE)319->setDescription(pht('Default text encoding.'))320->setConduitDescription(pht('Change the default text encoding.'))321->setConduitTypeDescription(pht('New text encoding.'))322->setValue($object->getDetail('encoding')),323id(new PhabricatorBoolEditField())324->setKey('allowDangerousChanges')325->setLabel(pht('Allow Dangerous Changes'))326->setIsCopyable(true)327->setIsFormField(false)328->setOptions(329pht('Prevent Dangerous Changes'),330pht('Allow Dangerous Changes'))331->setTransactionType(332PhabricatorRepositoryDangerousTransaction::TRANSACTIONTYPE)333->setDescription(pht('Permit dangerous changes to be made.'))334->setConduitDescription(pht('Allow or prevent dangerous changes.'))335->setConduitTypeDescription(pht('New protection setting.'))336->setValue($object->shouldAllowDangerousChanges()),337id(new PhabricatorBoolEditField())338->setKey('allowEnormousChanges')339->setLabel(pht('Allow Enormous Changes'))340->setIsCopyable(true)341->setIsFormField(false)342->setOptions(343pht('Prevent Enormous Changes'),344pht('Allow Enormous Changes'))345->setTransactionType(346PhabricatorRepositoryEnormousTransaction::TRANSACTIONTYPE)347->setDescription(pht('Permit enormous changes to be made.'))348->setConduitDescription(pht('Allow or prevent enormous changes.'))349->setConduitTypeDescription(pht('New protection setting.'))350->setValue($object->shouldAllowEnormousChanges()),351id(new PhabricatorSelectEditField())352->setKey('status')353->setLabel(pht('Status'))354->setTransactionType(355PhabricatorRepositoryActivateTransaction::TRANSACTIONTYPE)356->setIsFormField(false)357->setOptions(PhabricatorRepository::getStatusNameMap())358->setDescription(pht('Active or inactive status.'))359->setConduitDescription(pht('Active or deactivate the repository.'))360->setConduitTypeDescription(pht('New repository status.'))361->setValue($object->getStatus()),362id(new PhabricatorTextEditField())363->setKey('defaultBranch')364->setLabel(pht('Default Branch'))365->setTransactionType(366PhabricatorRepositoryDefaultBranchTransaction::TRANSACTIONTYPE)367->setIsCopyable(true)368->setDescription(pht('Default branch name.'))369->setConduitDescription(pht('Set the default branch name.'))370->setConduitTypeDescription(pht('New default branch name.'))371->setValue($object->getDetail('default-branch')),372id(new PhabricatorTextAreaEditField())373->setIsStringList(true)374->setKey('fetchRefs')375->setLabel(pht('Fetch Refs'))376->setTransactionType(377PhabricatorRepositoryFetchRefsTransaction::TRANSACTIONTYPE)378->setIsCopyable(true)379->setDescription(pht('Fetch only these refs.'))380->setConduitDescription(pht('Set the fetched refs.'))381->setConduitTypeDescription(pht('New fetched refs.'))382->setValue($fetch_value),383id(new PhabricatorTextAreaEditField())384->setIsStringList(true)385->setKey('permanentRefs')386->setLabel(pht('Permanent Refs'))387->setTransactionType(388PhabricatorRepositoryPermanentRefsTransaction::TRANSACTIONTYPE)389->setIsCopyable(true)390->setDescription(pht('Only these refs are considered permanent.'))391->setConduitDescription(pht('Set the permanent refs.'))392->setConduitTypeDescription(pht('New permanent ref rules.'))393->setValue($permanent_value),394id(new PhabricatorTextAreaEditField())395->setIsStringList(true)396->setKey('trackOnly')397->setLabel(pht('Track Only'))398->setTransactionType(399PhabricatorRepositoryTrackOnlyTransaction::TRANSACTIONTYPE)400->setIsCopyable(true)401->setControlInstructions($track_instructions)402->setDescription(pht('Track only these branches.'))403->setConduitDescription(pht('Set the tracked branches.'))404->setConduitTypeDescription(pht('New tracked branches.'))405->setValue($track_value),406id(new PhabricatorTextEditField())407->setKey('importOnly')408->setLabel(pht('Import Only'))409->setTransactionType(410PhabricatorRepositorySVNSubpathTransaction::TRANSACTIONTYPE)411->setIsCopyable(true)412->setDescription(pht('Subpath to selectively import.'))413->setConduitDescription(pht('Set the subpath to import.'))414->setConduitTypeDescription(pht('New subpath to import.'))415->setValue($object->getDetail('svn-subpath'))416->setControlInstructions($subpath_instructions),417id(new PhabricatorTextEditField())418->setKey('stagingAreaURI')419->setLabel(pht('Staging Area URI'))420->setTransactionType(421PhabricatorRepositoryStagingURITransaction::TRANSACTIONTYPE)422->setIsCopyable(true)423->setDescription(pht('Staging area URI.'))424->setConduitDescription(pht('Set the staging area URI.'))425->setConduitTypeDescription(pht('New staging area URI.'))426->setValue($object->getStagingURI())427->setControlInstructions($staging_instructions),428id(new PhabricatorDatasourceEditField())429->setKey('automationBlueprintPHIDs')430->setLabel(pht('Use Blueprints'))431->setTransactionType(432PhabricatorRepositoryBlueprintsTransaction::TRANSACTIONTYPE)433->setIsCopyable(true)434->setDatasource(new DrydockBlueprintDatasource())435->setDescription(pht('Automation blueprints.'))436->setConduitDescription(pht('Change automation blueprints.'))437->setConduitTypeDescription(pht('New blueprint PHIDs.'))438->setValue($object->getAutomationBlueprintPHIDs())439->setControlInstructions($automation_instructions),440id(new PhabricatorStringListEditField())441->setKey('symbolLanguages')442->setLabel(pht('Languages'))443->setTransactionType(444PhabricatorRepositorySymbolLanguagesTransaction::TRANSACTIONTYPE)445->setIsCopyable(true)446->setDescription(447pht('Languages which define symbols in this repository.'))448->setConduitDescription(449pht('Change symbol languages for this repository.'))450->setConduitTypeDescription(451pht('New symbol languages.'))452->setValue($object->getSymbolLanguages()),453id(new PhabricatorDatasourceEditField())454->setKey('symbolRepositoryPHIDs')455->setLabel(pht('Uses Symbols From'))456->setTransactionType(457PhabricatorRepositorySymbolSourcesTransaction::TRANSACTIONTYPE)458->setIsCopyable(true)459->setDatasource(new DiffusionRepositoryDatasource())460->setDescription(pht('Repositories to link symbols from.'))461->setConduitDescription(pht('Change symbol source repositories.'))462->setConduitTypeDescription(pht('New symbol repositories.'))463->setValue($object->getSymbolSources()),464id(new PhabricatorBoolEditField())465->setKey('publish')466->setLabel(pht('Publish/Notify'))467->setTransactionType(468PhabricatorRepositoryNotifyTransaction::TRANSACTIONTYPE)469->setIsCopyable(true)470->setOptions(471pht('Disable Notifications, Feed, and Herald'),472pht('Enable Notifications, Feed, and Herald'))473->setDescription(pht('Configure how changes are published.'))474->setConduitDescription(pht('Change publishing options.'))475->setConduitTypeDescription(pht('New notification setting.'))476->setValue(!$object->isPublishingDisabled()),477id(new PhabricatorPolicyEditField())478->setKey('policy.push')479->setLabel(pht('Push Policy'))480->setAliases(array('push'))481->setIsCopyable(true)482->setCapability(DiffusionPushCapability::CAPABILITY)483->setPolicies($policies)484->setTransactionType(485PhabricatorRepositoryPushPolicyTransaction::TRANSACTIONTYPE)486->setDescription(487pht('Controls who can push changes to the repository.'))488->setConduitDescription(489pht('Change the push policy of the repository.'))490->setConduitTypeDescription(pht('New policy PHID or constant.'))491->setValue($object->getPolicy(DiffusionPushCapability::CAPABILITY)),492id(new PhabricatorTextEditField())493->setKey('filesizeLimit')494->setLabel(pht('Filesize Limit'))495->setTransactionType(496PhabricatorRepositoryFilesizeLimitTransaction::TRANSACTIONTYPE)497->setDescription(pht('Maximum permitted file size.'))498->setConduitDescription(pht('Change the filesize limit.'))499->setConduitTypeDescription(pht('New repository filesize limit.'))500->setControlInstructions($filesize_warning)501->setValue($object->getFilesizeLimit()),502id(new PhabricatorTextEditField())503->setKey('copyTimeLimit')504->setLabel(pht('Clone/Fetch Timeout'))505->setTransactionType(506PhabricatorRepositoryCopyTimeLimitTransaction::TRANSACTIONTYPE)507->setDescription(508pht('Maximum permitted duration of internal clone/fetch.'))509->setConduitDescription(pht('Change the copy time limit.'))510->setConduitTypeDescription(pht('New repository copy time limit.'))511->setValue($object->getCopyTimeLimit()),512id(new PhabricatorTextEditField())513->setKey('touchLimit')514->setLabel(pht('Touched Paths Limit'))515->setTransactionType(516PhabricatorRepositoryTouchLimitTransaction::TRANSACTIONTYPE)517->setDescription(pht('Maximum permitted paths touched per commit.'))518->setConduitDescription(pht('Change the touch limit.'))519->setConduitTypeDescription(pht('New repository touch limit.'))520->setValue($object->getTouchLimit()),521);522}523524}525526527