Skip to content

Commit

Permalink
Allow installing the jean85/pretty-package-versions package at versio…
Browse files Browse the repository at this point in the history
…n 2.x (backport of #1170) (#1171)
  • Loading branch information
Jean85 authored Feb 1, 2021
1 parent ef958b7 commit df65ac7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Allow jean85/pretty-package-versions 2.0 (#1171, backport of #1170 from 3.x)

### 2.5.1 (2020-12-11)

- Fix regression introduced in #1129 (#1143)
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ cs-fix:
phpstan:
vendor/bin/phpstan analyse

test: cs-fix phpstan
psalm:
vendor/bin/psalm

test: cs-fix phpstan psalm
vendor/bin/phpunit --verbose

setup-git:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"ext-mbstring": "*",
"guzzlehttp/promises": "^1.3",
"guzzlehttp/psr7": "^1.7",
"jean85/pretty-package-versions": "^1.2",
"jean85/pretty-package-versions": "^1.5|^2.0.1",
"php-http/async-client-implementation": "^1.0",
"php-http/client-common": "^1.5|^2.0",
"php-http/discovery": "^1.6.1",
Expand Down
27 changes: 25 additions & 2 deletions src/Integration/ModulesIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Sentry\Integration;

use Composer\InstalledVersions;
use Jean85\PrettyVersions;
use PackageVersions\Versions;
use Sentry\Event;
Expand Down Expand Up @@ -63,11 +64,33 @@ public static function applyToEvent(self $self, Event $event): void
private function processEvent(Event $event): void
{
if (empty(self::$loadedModules)) {
foreach (Versions::VERSIONS as $package => $rawVersion) {
self::$loadedModules[$package] = PrettyVersions::getVersion($package)->getPrettyVersion();
foreach (self::getInstalledPackages() as $package) {
try {
self::$loadedModules[$package] = PrettyVersions::getVersion($package)->getPrettyVersion();
} catch (\Throwable $exception) {
continue;
}
}
}

$event->setModules(self::$loadedModules);
}

/**
* @return string[]
*/
private static function getInstalledPackages(): array
{
if (class_exists(InstalledVersions::class)) {
return InstalledVersions::getInstalledPackages();
}

if (class_exists(Versions::class)) {
// BC layer for Composer 1, using a transient dependency
return array_keys(Versions::VERSIONS);
}

// this should not happen
return ['sentry/sentry'];
}
}

0 comments on commit df65ac7

Please sign in to comment.