Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LandoLinkEventListener: add new Lando URL functionality (bug 1943388) #45

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -26,6 +26,12 @@ public function getOptions() {
'string',
'')
->setDescription(pht('Full URL for the Lando UI server. '.
'Set to an empty string to disable the link on the Revision page.')),
$this->newOption(
'lando.url',
'string',
'')
->setDescription(pht('Full URL for the new Lando server. '.
'Set to an empty string to disable the link on the Revision page.'))
);
}
43 changes: 40 additions & 3 deletions moz-extensions/src/lando/events/LandoLinkEventListener.php
Original file line number Diff line number Diff line change
@@ -26,8 +26,10 @@ private function handleActionEvent($event) {
return;
}

$lando_uri = PhabricatorEnv::getEnvConfig('lando-ui.url');
if (!$lando_uri) {
$legacy_lando_uri = PhabricatorEnv::getEnvConfig('lando-ui.url');
$new_lando_uri = PhabricatorEnv::getEnvConfig('lando.url');

if (!$legacy_lando_uri && !$new_lando_uri) {
return;
}

@@ -36,7 +38,42 @@ private function handleActionEvent($event) {
return;
}

// View stack in Lando Action

// Get repository projects, and determine if it uses the new Lando.
// If a repository is associated with the "lando" project, it is treated
// as a repo that uses the modern Lando. Otherwise, it is treated as using
// the legacy Lando.
$repository_phid = $object->getRepositoryPHID();
$repository = id(new PhabricatorRepositoryQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->needProjectPHIDs(true)
->withPHIDs(array($repository_phid))
->executeOne();

$repository_project_phids = $repository->getProjectPHIDs();

if ($repository_project_phids) {
$projects = id(new PhabricatorProjectQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs($repository_project_phids)
->execute();

$lando_project = id(new PhabricatorProjectQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withNames(array("lando"))
->executeOne();

$uses_new_lando = in_array($lando_project, $projects);
} else {
$uses_new_lando = false;
}

if ($uses_new_lando) {
$lando_uri = $new_lando_uri;
} else {
$lando_uri = $legacy_lando_uri;
}

$lando_stack_uri = (string) id(new PhutilURI($lando_uri))
->setPath('/D' . $object->getID() . '/');