1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +01:00

Default "Land Revision" dialog to land into the default branch for the repository

Summary:
Ref T9952. Default the branch target in the dialog to be whatever branch is the default branch for the repository.

This will be correct for repositories like ours (which land everything into `master`) and correct most of the time for repositories which have some other "primary" branch (maybe `development`).

It won't be great if there are multiple open lines of development in a repository (for example, some changes go to `newdesignpro` and some changes go to `legacy-1.2`). I'll do work in T3462 next to improve those cases so we can pick a better default.

Test Plan:
  - Saw dialog default to "master".
  - Changed repo default branch, saw it default to "notmaster" instead.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9952

Differential Revision: https://secure.phabricator.com/D14734
This commit is contained in:
epriestley 2015-12-10 14:04:18 -08:00
parent 856bdaf77e
commit f60548d081

View file

@ -30,26 +30,28 @@ final class DifferentialRevisionOperationController
$diff = $revision->getActiveDiff();
$repository = $revision->getRepository();
$ref_types = array(
PhabricatorRepositoryRefCursor::TYPE_BRANCH,
);
$default_ref = $this->loadDefaultRef($repository);
if ($default_ref) {
$v_ref = array($default_ref->getPHID());
} else {
$v_ref = array();
}
$e_ref = true;
$errors = array();
if ($request->isFormPost()) {
$ref_phid = head($request->getArr('refPHIDs'));
$v_ref = $request->getArr('refPHIDs');
$ref_phid = head($v_ref);
if (!strlen($ref_phid)) {
$e_ref = pht('Required');
$errors[] = pht(
'You must select a branch to land this revision onto.');
} else {
$ref = id(new PhabricatorRepositoryRefCursorQuery())
->setViewer($viewer)
$ref = $this->newRefQuery($repository)
->withPHIDs(array($ref_phid))
->withRepositoryPHIDs(array($repository->getPHID()))
->withRefTypes($ref_types)
->executeOne();
if (!$ref) {
$e_ref = pht('Invalid');
@ -85,7 +87,7 @@ final class DifferentialRevisionOperationController
->setParameters(
array(
'repositoryPHIDs' => array($repository->getPHID()),
'refTypes' => $ref_types,
'refTypes' => $this->getTargetableRefTypes(),
));
$form = id(new AphrontFormView())
@ -100,6 +102,7 @@ final class DifferentialRevisionOperationController
->setName('refPHIDs')
->setLimit(1)
->setError($e_ref)
->setValue($v_ref)
->setDatasource($ref_datasource))
->appendRemarkupInstructions(
pht(
@ -115,4 +118,35 @@ final class DifferentialRevisionOperationController
->addSubmitButton(pht('Mutate Repository Unpredictably'));
}
private function newRefQuery(PhabricatorRepository $repository) {
$viewer = $this->getViewer();
return id(new PhabricatorRepositoryRefCursorQuery())
->setViewer($viewer)
->withRepositoryPHIDs(array($repository->getPHID()))
->withRefTypes($this->getTargetableRefTypes());
}
private function getTargetableRefTypes() {
return array(
PhabricatorRepositoryRefCursor::TYPE_BRANCH,
);
}
private function loadDefaultRef(PhabricatorRepository $repository) {
$default_name = $this->getDefaultRefName($repository);
if (!strlen($default_name)) {
return null;
}
return $this->newRefQuery($repository)
->withRefNames(array($default_name))
->executeOne();
}
private function getDefaultRefName(PhabricatorRepository $repository) {
return $repository->getDefaultBranch();
}
}