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 25 commits into from
Jan 18, 2023
Merged
Changes from 1 commit
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fully support Psalm 5 behaviour
asked by orklah, see
#9112 (comment)
alies-dev committed Jan 18, 2023
commit d5e5dc0683eb5e305a1b0e789e634d7f3707909c
2 changes: 1 addition & 1 deletion src/Psalm/Config.php
Original file line number Diff line number Diff line change
@@ -548,7 +548,7 @@ class Config
* @var string
* @deprecated Please use {@see self::$shepherd_endpoint} instead. Property will be removed in Psalm 6.
*/
public $shepherd_host = 'https://shepherd.dev/hooks/psalm/';
public $shepherd_host = 'shepherd.dev';

/**
* @var string
72 changes: 46 additions & 26 deletions src/Psalm/Internal/Cli/Psalm.php
Original file line number Diff line number Diff line change
@@ -306,32 +306,7 @@ public static function run(array $argv): void
? $options['find-references-to']
: null;

$is_shepherd_enabled = (bool) ($options['shepherd'] ?? getenv('PSALM_SHEPHERD'));
if ($is_shepherd_enabled) {
$plugins[] = Path::canonicalize(__DIR__ . '/../../Plugin/Shepherd.php');

$custom_shepherd_host = ($options['shepherd'] ?? getenv('PSALM_SHEPHERD')) ?: getenv('PSALM_SHEPHERD_HOST');

$is_valid_custom_shepherd_endpoint = is_string($custom_shepherd_host) && strlen($custom_shepherd_host) > 2;
if ($is_valid_custom_shepherd_endpoint) {
if (parse_url($custom_shepherd_host, PHP_URL_SCHEME) === null) {
$custom_shepherd_host = 'https://' . $custom_shepherd_host;
}

$config->shepherd_host = $custom_shepherd_host;
$config->shepherd_endpoint = $custom_shepherd_host;

if (is_string(getenv('PSALM_SHEPHERD_HOST'))) {
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,
);
}
}
}
self::configureShepherd($options, $plugins);

if (isset($options['clear-cache'])) {
self::clearCache($config);
@@ -1170,6 +1145,51 @@ 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');

$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;
}

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

return;
}

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

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

$config->shepherd_endpoint = $custom_shepherd_host . '/hooks/psalm';
$config->shepherd_host = $custom_shepherd_host;
}
}

private static function generateStubs(
array $options,
Providers $providers,
2 changes: 1 addition & 1 deletion src/Psalm/Plugin/Shepherd.php
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ public static function afterAnalysis(
$payload = json_encode($data, JSON_THROW_ON_ERROR);

// Prepare new cURL resource
$ch = curl_init($codebase->config->shepherd_endpoint);
$ch = curl_init($base_address . '/hooks/psalm');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);