Created
April 26, 2013 11:52
-
-
Save StanAngeloff/5466930 to your computer and use it in GitHub Desktop.
Composer -> GitHub compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
#vim: set ft=php: | |
$input = ''; | |
while (( ! feof(STDIN))) { | |
$input = $input . fgets(STDIN); | |
} | |
$patterns = [ | |
<<<EOD | |
Removing.*\((?<from>.*?)\)$ | |
.* | |
Installing\s+(?<package>[^\s]+).*\((?<to>.*?)\)$ | |
EOD | |
, | |
<<<EOD | |
Updating\s+(?<package>[^\s]+).*\((?<from>.*?)\s*=>\s*(?<to>.*?)\)$ | |
EOD | |
]; | |
$updates = []; | |
$paragraphs = preg_split('#(\r\n|\r|\n){2,}#', $input); | |
foreach ($paragraphs as $paragraph) { | |
foreach ($patterns as $pattern) { | |
if (preg_match("#{$pattern}#xms", $paragraph, $captures)) { | |
$updates[] = array($captures['package'], $captures['from'], $captures['to']); | |
} | |
} | |
} | |
foreach ($updates as list ($package, $from, $to)) { | |
$packagist = file_get_contents("https://packagist.org/packages/{$package}.json"); | |
$json = json_decode($packagist, true); | |
$repository = $json['package']['repository']; | |
$repository = preg_replace('#^\w+://#', 'http://', $repository); | |
$repository = rtrim($repository, '/'); | |
$repository = preg_replace('#\.git$#', '', $repository); | |
foreach (array(&$from, &$to) as &$version) { | |
$version = preg_split('#\s+#', $version); | |
$version = end($version); | |
} | |
print $repository . '/compare/' . $from . '...' . $to . PHP_EOL . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment