From e6fb407bd57ad2a4a97378d86b6a5e4b87af5424 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Mon, 21 Dec 2020 00:11:16 +0100 Subject: [PATCH] Support mysterious versions --- .../SilverStripeRemoteRepository.php | 2 +- tests/SilverStripeRemoteRepositoryTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/RemoteRepository/SilverStripeRemoteRepository.php b/src/RemoteRepository/SilverStripeRemoteRepository.php index c253e69..c6e36e6 100644 --- a/src/RemoteRepository/SilverStripeRemoteRepository.php +++ b/src/RemoteRepository/SilverStripeRemoteRepository.php @@ -26,7 +26,7 @@ public function getFileUrl($projectVersion, $relativePath, $line) } if (isset($packageConfig['versionmap'])) { $versionMaps = Config::getConfig()['versionmaps']; - $projectVersion = $versionMaps[$packageConfig['versionmap']][(string) $projectVersion]; + $projectVersion = $versionMaps[$packageConfig['versionmap']][(string) $projectVersion] ?? $projectVersion; } $url = $rootPath . '/blob/' . $this->buildProjectPath($projectVersion, $pathParts[2]); diff --git a/tests/SilverStripeRemoteRepositoryTest.php b/tests/SilverStripeRemoteRepositoryTest.php index 35e05d1..c7a23d8 100644 --- a/tests/SilverStripeRemoteRepositoryTest.php +++ b/tests/SilverStripeRemoteRepositoryTest.php @@ -48,5 +48,30 @@ public function testGetRepoUrl() . 'silverstripe-graphql/blob/master/src/Extensions/IntrospectionProvider.php#L0', $url ); + + $url = $remoteRepo->getFileUrl( + '3', + 'silverstripe/graphql/src/Extensions/IntrospectionProvider.php', + 0 + ); + + $this->assertSame( + 'https://github.com/silverstripe/' + . 'silverstripe-graphql/blob/3/src/Extensions/IntrospectionProvider.php#L0', + $url + ); + + // A mysterious version did pop out, oh snap + $url = $remoteRepo->getFileUrl( + 'foobar', + 'silverstripe/graphql/src/Extensions/IntrospectionProvider.php', + 0 + ); + + $this->assertSame( + 'https://github.com/silverstripe/' + . 'silverstripe-graphql/blob/foobar/src/Extensions/IntrospectionProvider.php#L0', + $url + ); } }