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

Allow to specify custom shepherd endpoint #9133

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5c2d06e
Allow to specify a custom shepherd endpoint (instead of domain)
alies-dev Jan 14, 2023
ce00951
Use safer type operations with cli $options array
alies-dev Jan 14, 2023
f8e210f
Update baseline (add DeprecatedProperty)
alies-dev Jan 14, 2023
b95f428
Follow redirects when submitting shepherd reports
alies-dev Jan 14, 2023
9ee3598
Properly process HTTP response codes from shepherd servers
alies-dev Jan 14, 2023
c494b58
Fix coding style issues
alies-dev Jan 14, 2023
9f81a5a
Update cli help text
alies-dev Jan 14, 2023
077cd5d
Return getCurlErrorMessage() method as it can be used outside
alies-dev Jan 14, 2023
9271946
Fully support Psalm 5 behaviour
alies-dev Jan 16, 2023
76c1e41
Add suppressions for using a deprecated property
alies-dev Jan 16, 2023
924c6da
Fix coding style issues
alies-dev Jan 17, 2023
a3786a7
Merge branch 'master' into allow-to-specify-custom-shepherd-endpoint
lptn Jan 17, 2023
7e157cf
Allow to specify a custom shepherd endpoint (instead of domain)
alies-dev Jan 14, 2023
30ab11b
Use safer type operations with cli $options array
alies-dev Jan 14, 2023
9cba360
Update baseline (add DeprecatedProperty)
alies-dev Jan 14, 2023
09517d3
Follow redirects when submitting shepherd reports
alies-dev Jan 14, 2023
c95b071
Properly process HTTP response codes from shepherd servers
alies-dev Jan 14, 2023
587ac6e
Fix coding style issues
alies-dev Jan 14, 2023
8e57158
Update cli help text
alies-dev Jan 14, 2023
291484d
Return getCurlErrorMessage() method as it can be used outside
alies-dev Jan 14, 2023
d5e5dc0
Fully support Psalm 5 behaviour
alies-dev Jan 16, 2023
363a0b6
Add suppressions for using a deprecated property
alies-dev Jan 16, 2023
aac6ead
Fix coding style issues
alies-dev Jan 17, 2023
cc30cf9
Merge remote-tracking branch 'origin/allow-to-specify-custom-shepherd…
alies-dev Jan 18, 2023
2161e97
Cleanup baseline
alies-dev Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@8b9cd5fb333866c1e84ca9564394816a7ff5ae6f">
<files psalm-version="dev-master@6bcd3bffe3385bc33643a694c32af515395bf437">
<file src="examples/TemplateChecker.php">
<PossiblyUndefinedIntArrayOffset>
<code>$comment_block-&gt;tags['variablesfrom'][0]</code>
Expand Down Expand Up @@ -483,6 +483,11 @@
<code>$type_tokens[$i - 1]</code>
</PossiblyInvalidArrayOffset>
</file>
<file src="src/Psalm/Plugin/Shepherd.php">
<DeprecatedProperty>
<code>$codebase-&gt;config-&gt;shepherd_host</code>
</DeprecatedProperty>
</file>
<file src="src/Psalm/Storage/ClassConstantStorage.php">
<MutableDependency>
<code>CustomMetadataTrait</code>
Expand Down
11 changes: 10 additions & 1 deletion src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,18 @@ class Config
*/
public $include_php_versions_in_error_baseline = false;

/** @var string */
/**
* @var string
* @deprecated Please use {@see self::$shepherd_endpoint} instead. Property will be removed in Psalm 6.
*/
public $shepherd_host = 'shepherd.dev';

/**
* @var string
* @internal
*/
public $shepherd_endpoint = 'https://shepherd.dev/hooks/psalm/';

/**
* @var array<string, string>
*/
Expand Down
90 changes: 63 additions & 27 deletions src/Psalm/Internal/Cli/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@
use function json_encode;
use function max;
use function microtime;
use function parse_url;
use function preg_match;
use function preg_replace;
use function realpath;
use function setlocale;
use function str_repeat;
use function str_replace;
use function strlen;
use function strpos;
use function substr;
use function version_compare;
Expand All @@ -77,6 +80,7 @@
use const LC_CTYPE;
use const PHP_EOL;
use const PHP_OS;
use const PHP_URL_SCHEME;
use const PHP_VERSION;
use const STDERR;

Expand Down Expand Up @@ -195,10 +199,9 @@ public static function run(array $argv): void
if (array_key_exists('h', $options)) {
echo self::getHelpText();
/*
--shepherd[=host]
Send data to Shepherd, Psalm's GitHub integration tool.
`host` is the location of the Shepherd server. It defaults to shepherd.dev
More information is available at https://psalm.dev/shepherd
--shepherd[=endpoint]
Send analysis statistics to Shepherd server.
`endpoint` is the URL to the Shepherd server. It defaults to shepherd.dev
*/

exit;
Expand Down Expand Up @@ -279,13 +282,16 @@ public static function run(array $argv): void
chdir($current_dir);
}

/** @var list<string> $plugins List of paths to plugin files */
$plugins = [];

if (isset($options['plugin'])) {
$plugins = $options['plugin'];
$plugins_from_options = $options['plugin'];

if (!is_array($plugins)) {
$plugins = [$plugins];
if (is_array($plugins_from_options)) {
$plugins = $plugins_from_options;
} elseif (is_string($plugins_from_options)) {
$plugins = [$plugins_from_options];
}
}

Expand All @@ -301,24 +307,7 @@ public static function run(array $argv): void
? $options['find-references-to']
: null;

if (isset($options['shepherd']) || getenv('PSALM_SHEPHERD')) {
if (isset($options['shepherd'])) {
if (is_string($options['shepherd'])) {
$config->shepherd_host = $options['shepherd'];
}
} elseif (getenv('PSALM_SHEPHERD')) {
if (false !== ($shepherd_host = getenv('PSALM_SHEPHERD_HOST'))) {
$config->shepherd_host = $shepherd_host;
}
}
$shepherd_plugin = Path::canonicalize(__DIR__ . '/../../Plugin/Shepherd.php');

if (!file_exists($shepherd_plugin)) {
die('Could not find Shepherd plugin location ' . $shepherd_plugin . PHP_EOL);
}

$plugins[] = $shepherd_plugin;
}
self::configureShepherd($config, $options, $plugins);

if (isset($options['clear-cache'])) {
self::clearCache($config);
Expand Down Expand Up @@ -1157,6 +1146,53 @@ private static function configureProjectAnalyzer(
}
}

private static function configureShepherd(Config $config, array $options, array &$plugins): void
{
if (is_string(getenv('PSALM_SHEPHERD_HOST'))) { // remove this block in Psalm 6
fwrite(
STDERR,
'PSALM_SHEPHERD_HOST env variable is deprecated and will be removed in Psalm 6.'
.' Please use "--shepherd" cli option or PSALM_SHEPHERD env variable'
.' to specify a custom Shepherd host/endpoint.'
. PHP_EOL,
);
}

$is_shepherd_enabled = (bool) ($options['shepherd'] ?? getenv('PSALM_SHEPHERD'));
if (! $is_shepherd_enabled) {
return;
}

$plugins[] = Path::canonicalize(__DIR__ . '/../../Plugin/Shepherd.php');

/** @psalm-suppress MixedAssignment */
$custom_shepherd_endpoint = ($options['shepherd'] ?? getenv('PSALM_SHEPHERD'));
if (is_string($custom_shepherd_endpoint) && strlen($custom_shepherd_endpoint) > 2) {
if (parse_url($custom_shepherd_endpoint, PHP_URL_SCHEME) === null) {
$custom_shepherd_endpoint = 'https://' . $custom_shepherd_endpoint;
}

/** @psalm-suppress DeprecatedProperty */
$config->shepherd_host = str_replace('/hooks/psalm', '', $custom_shepherd_endpoint);
$config->shepherd_endpoint = $custom_shepherd_endpoint;

return;
}

// Legacy part, will be removed in Psalm 6
$custom_shepherd_host = getenv('PSALM_SHEPHERD_HOST');

if (is_string($custom_shepherd_host)) {
if (parse_url($custom_shepherd_host, PHP_URL_SCHEME) === null) {
$custom_shepherd_host = 'https://' . $custom_shepherd_host;
}

/** @psalm-suppress DeprecatedProperty */
$config->shepherd_host = $custom_shepherd_host;
$config->shepherd_endpoint = $custom_shepherd_host . '/hooks/psalm';
}
}

private static function generateStubs(
array $options,
Providers $providers,
Expand Down Expand Up @@ -1329,8 +1365,8 @@ private static function getHelpText(): string
--generate-stubs=PATH
Generate stubs for the project and dump the file in the given path

--shepherd[=host]
Send data to Shepherd, Psalm’s GitHub integration tool.
--shepherd[=endpoint]
Send analysis statistics to Shepherd (shepherd.dev) or your server.

--alter
Run Psalter
Expand Down