Skip to content

Commit

Permalink
Better handle the legacy URL to warn users
Browse files Browse the repository at this point in the history
  • Loading branch information
tgalopin committed May 25, 2020
1 parent a44b6a4 commit 14e606f
Show file tree
Hide file tree
Showing 34 changed files with 109 additions and 78 deletions.
3 changes: 2 additions & 1 deletion Cli/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down Expand Up @@ -51,6 +51,7 @@ public function getApi()
if (\array_key_exists('api_endpoint', $config)) {
$config['base_url'] = $config['api_endpoint'];
}

$this->api = new Api($config);

if ($this->logFile) {
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/AnalysisCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
12 changes: 11 additions & 1 deletion Cli/Command/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -12,11 +12,13 @@
namespace SensioLabs\Insight\Cli\Command;

use SensioLabs\Insight\Cli\Helper\DescriptorHelper;
use SensioLabs\Insight\Sdk\Api;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class AnalyzeCommand extends Command implements NeedConfigurationInterface
{
Expand All @@ -37,7 +39,15 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$projectUuid = $input->getArgument('project-uuid');

/** @var Api $api */
$api = $this->getApplication()->getApi();

if (false !== strpos($api->getBaseUrl(), '.sensiolabs.com')) {
$io = new SymfonyStyle($input, $output);
$io->warning('You are using the legacy URL of SymfonyInsight which may stop working in the future. You should reconfigure this tool by running the "configure" command and use "https://insight.symfony.com" as endpoint.');
}

$analysis = $api->analyze($projectUuid, $input->getOption('reference'), $input->getOption('branch'));

$chars = ['-', '\\', '|', '/'];
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/ConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/NeedConfigurationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/ProjectsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Descriptor/AbstractDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Descriptor/JsonDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Descriptor/TextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Descriptor/XmlDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
41 changes: 25 additions & 16 deletions Cli/Helper/ConfigurationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;

class ConfigurationHelper extends Helper
{
private $apiEndpoint;

public function __construct($apiEndpoint)
public function __construct(string $apiEndpoint)
{
$this->apiEndpoint = $apiEndpoint;
}
Expand All @@ -24,12 +25,24 @@ public function updateConfigurationManually(InputInterface $input, OutputInterfa

$userUuid = $input->getOption('user-uuid') ?: $configuration->getUserUuid();
$apiToken = $input->getOption('api-token') ?: $configuration->getApiToken();
$apiEndpoint = $input->getOption('api-endpoint') ?: $configuration->getApiEndpoint();

// Avoid saving again a legacy URL
$defaultEndpoint = $configuration->getApiEndpoint();
if (false !== strpos($defaultEndpoint, '.sensiolabs.com')) {
$defaultEndpoint = null;
}

$apiEndpoint = $input->getOption('api-endpoint') ?: $defaultEndpoint;

$configuration->setUserUuid($this->askValue($input, $output, 'User Uuid', $userUuid));
$configuration->setApiToken($this->askValue($input, $output, 'Api Token', $apiToken));
$configuration->setApiEndpoint($this->askValue($input, $output, 'Api Endpoint', $apiEndpoint ?: $this->apiEndpoint));

if (false !== strpos($configuration->getApiEndpoint(), '.sensiolabs.com')) {
$io = new SymfonyStyle($input, $output);
$io->warning('You are using the legacy URL of SymfonyInsight which may stop working in the future. You should reconfigure this tool by running the "configure" command and use "https://insight.symfony.com" as endpoint.');
}

$this->saveConfiguration($input, $output, $configuration);
}

Expand All @@ -43,7 +56,7 @@ public function getConfiguration(InputInterface $input, OutputInterface $output)
$this->resolveValue($input, $output, $configuration, 'Api Endpoint', $this->apiEndpoint);

if (!$configuration->equals($previousConfiguration)) {
$this->saveConfiguration($input, $output, $configuration, $previousConfiguration);
$this->saveConfiguration($input, $output, $configuration);
}

return $configuration;
Expand Down Expand Up @@ -78,7 +91,6 @@ private function resolveValue(InputInterface $input, OutputInterface $output, Co
private function getValue(InputInterface $input, $varName)
{
$envVarName = sprintf('INSIGHT_%s', str_replace(' ', '_', strtoupper($varName)));

if ($value = getenv($envVarName)) {
return $value;
}
Expand All @@ -90,7 +102,7 @@ private function getValue(InputInterface $input, $varName)

private function askValue(InputInterface $input, OutputInterface $output, $varname, $default = null)
{
$validator = function ($v) use ($varname) {
$validator = static function ($v) use ($varname) {
if (!$v) {
throw new \InvalidArgumentException(sprintf('Your must provide a %s!', $varname));
}
Expand All @@ -99,18 +111,17 @@ private function askValue(InputInterface $input, OutputInterface $output, $varna
};

if (!$input->isInteractive()) {
return \call_user_func($validator, $default);
return $validator($default);
}

if ($default) {
$question = new Question(sprintf('What is your %s? [%s] ', $varname, $default));
} else {
$question = new Question(sprintf('What is your %s? ', $varname));
}
$question = new Question(
$default ? sprintf('What is your %s? [%s] ', $varname, $default) : sprintf('What is your %s? ', $varname),
$default
);

$dialog = $this->getHelperSet()->get('question');
$question->setValidator($validator);

return $dialog->ask($input, $output, $question, $validator, false, $default);
return $this->getHelperSet()->get('question')->ask($input, $output, $question);
}

private function saveConfiguration(InputInterface $input, OutputInterface $output, Configuration $configuration)
Expand All @@ -123,9 +134,7 @@ private function saveConfiguration(InputInterface $input, OutputInterface $outpu

$question = new ConfirmationQuestion('Do you want to save this new configuration? [Y/n] ');

$dialog = $this->getHelperSet()->get('question');

if ($dialog->ask($input, $output, $question)) {
if ($this->getHelperSet()->get('question')->ask($input, $output, $question)) {
$configuration->save();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Cli/Helper/DescriptorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Helper/FailConditionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ embed SensioLabsInsight reports into your build workflow, following these steps:
*It is assumed you already have your project up and building in Jenkins and SensioLabsInsight SDK installed*

1. Retrieve your `SensioLabsInsight API Token`, `User UUID` and `Project UUID`
on your [account page](https://insight.sensiolabs.com/account)
on your [account page](https://insight.symfony.com/account)
2. Install the Jenkins `PMD plugin`:
[How to install a jenkins plugin](https://wiki.jenkins-ci.org/display/JENKINS/Plugins#Plugins-Howtoinstallplugins)
3. Optionally you can also install the `EnvInject Plugin`
Expand Down
Loading

0 comments on commit 14e606f

Please sign in to comment.