Skip to content
This repository was archived by the owner on Jul 8, 2024. It is now read-only.

Commit b25c571

Browse files
authored
Merge pull request #158 from xemlock/github-shorthand
Add support for GitHub shorthand
2 parents d0ce99d + f28cbb3 commit b25c571

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Bowerphp/Util/PackageNameVersionExtractor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public static function fromString($endpoint)
4646
$name = isset($map[0]) ? $map[0] : $endpoint;
4747
$version = isset($map[1]) ? $map[1] : '*';
4848

49+
// Convert user/package shorthand to GitHub url
50+
if (preg_match('/^([-_a-z0-9]+)\/([-_a-z0-9]+)$/i', $name)) {
51+
$name = 'https://github.com/' . $name . '.git';
52+
}
53+
4954
return new self($name, $version);
5055
}
5156
}

tests/Bowerphp/Test/Util/PackageNameVersionExtractorTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,24 @@ public function testReturnPackageAndVersionIsSet()
3232
$this->assertEquals('jquery', $packageNameVersion->name);
3333
$this->assertEquals('1.10.2', $packageNameVersion->version);
3434
}
35+
36+
public function testReturnPackageGithubUrlFromShorthand()
37+
{
38+
$package = 'jquery/jquery';
39+
40+
$packageNameVersion = PackageNameVersionExtractor::fromString($package);
41+
42+
$this->assertEquals('https://github.com/jquery/jquery.git', $packageNameVersion->name);
43+
$this->assertEquals('*', $packageNameVersion->version);
44+
}
45+
46+
public function testReturnPackageGithubUrlAndVersionFromShorthand()
47+
{
48+
$package = 'jquery/jquery#1.10.2';
49+
50+
$packageNameVersion = PackageNameVersionExtractor::fromString($package);
51+
52+
$this->assertEquals('https://github.com/jquery/jquery.git', $packageNameVersion->name);
53+
$this->assertEquals('1.10.2', $packageNameVersion->version);
54+
}
3555
}

0 commit comments

Comments
 (0)