Skip to content

Commit

Permalink
Fixed the Git SSH syntax in an error message
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Apr 21, 2018
1 parent bbd0c87 commit 3a39d4e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Configuration/DefaultConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public function repositoryUrl(string $url): self
// https://github.com/<user>/<repo>
// https://bitbucket.org/<user>/<repo>
// https://gitlab.com/<user>/<repo>.git
if (Str::startsWith($url, 'https://')) {
$sshUrl = str_replace('https://', 'git@', $url);
if (Str::startsWith($url, 'http://') || Str::startsWith($url, 'https://')) {
$sshUrl = preg_replace('/https?:\/\/(?<server>.*)\/(?<vendor>.*)\/(?<repository>.*)/', 'git@$1:$2/$3', $url);
if (!Str::endsWith($sshUrl, '.git')) {
$sshUrl .= '.git';
}
Expand Down
17 changes: 14 additions & 3 deletions tests/Configuration/DefaultConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
class DefaultConfigurationTest extends TestCase
{
/**
* @dataProvider provideHttpRepositoryUrls
* @expectedException \EasyCorp\Bundle\EasyDeployBundle\Exception\InvalidConfigurationException
* @expectedExceptionMessageRegExp /The repository URL must use the SSH syntax instead of the HTTPs syntax to make it work on any remote server. Replace "https:\/\/.*" by "git@.*"/
* @expectedExceptionMessageRegExp /The repository URL must use the SSH syntax instead of the HTTPs syntax to make it work on any remote server. Replace "https?:\/\/.*\/symfony\/symfony-demo.git" by "git@.*:symfony\/symfony-demo.git"/
*/
public function test_repository_url_protocol()
public function test_repository_url_protocol(string $url)
{
(new DefaultConfiguration(__DIR__))
->repositoryUrl('https://github.com/symfony/symfony-demo.git')
->repositoryUrl($url)
;
}

Expand All @@ -37,4 +38,14 @@ public function test_reset_opcache_for()
->resetOpCacheFor('symfony.com')
;
}

public function provideHttpRepositoryUrls()
{
yield ['http://github.com/symfony/symfony-demo.git'];
yield ['https://github.com/symfony/symfony-demo.git'];
yield ['http://bitbucket.org/symfony/symfony-demo.git'];
yield ['https://bitbucket.org/symfony/symfony-demo.git'];
yield ['http://gitlab.com/symfony/symfony-demo.git'];
yield ['https://gitlab.com/symfony/symfony-demo.git'];
}
}

0 comments on commit 3a39d4e

Please sign in to comment.