Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions composer-lock-diff
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,30 @@ function diff($key, $data_from, $data_to) {
$pkgs = array();

foreach($data_from->$key as $pkg) {
$pkgs[$pkg->name] = array(version($pkg), 'REMOVED', '');
$pkgs[$pkg->name] = array(version($pkg), 'REMOVED', '', reference($pkg));
}

foreach($data_to->$key as $pkg) {
if (! array_key_exists($pkg->name, $pkgs)) {
$pkgs[$pkg->name] = array('NEW', version($pkg), '');
$pkgs[$pkg->name] = array('NEW', version($pkg), '', reference($pkg));
continue;
}

if ($pkgs[$pkg->name][0] == version($pkg)) {
unset($pkgs[$pkg->name]);
} else {
$pkgs[$pkg->name][1] = version($pkg);
$pkgs[$pkg->name][4] = reference($pkg);
$pkgs[$pkg->name][2] = makeCompareUrl($pkg, $pkgs);
}
}

foreach ($pkgs as &$pkg) {
// Remove the extra references.
unset($pkg[3], $pkg[4]);
}
unset($pkg);

return $pkgs;
}

Expand All @@ -78,6 +85,17 @@ function version($pkg)
return $version;
}

function reference($pkg)
{
if (isset($pkg->source->reference)) {
if (!preg_match('{^[0-9a-f]{40}$}', $pkg->source->reference)) {
// Not a commit hash, use it.
return $pkg->source->reference;
}
}
return version($pkg);
}

function tableize($header, $data, $opts = array()) {
if (empty($data)) return '';

Expand Down Expand Up @@ -233,7 +251,9 @@ function mustDecodeJson($json, $context) {

function makeCompareUrl($pkg, $diff) {
$func = 'formatCompare' . ucfirst(getSourceRepoType((string) @$pkg->source->url));
return call_user_func($func, @$pkg->source->url, $diff[$pkg->name][0], $diff[$pkg->name][1]);
$from_version = $diff[$pkg->name][3];
$to_version = $diff[$pkg->name][4];
return call_user_func($func, @$pkg->source->url, $from_version, $to_version);
}

function getSourceRepoType($url) {
Expand Down Expand Up @@ -298,7 +318,13 @@ function formatCompareGitlab($url, $from, $to) {
}

function formatCompareDrupal($url, $from, $to) {
// Drupalcode uses self-hosted Gitlab now
// Drupalcode uses self-hosted Gitlab now.
if (strpos($url, 'http') === false) {
$url = preg_replace('/^git@(git\.[^:]+):/', 'https://$1/', $url);
// git.drupal.org automatically redirects to git.drupalcode.org anyway,
// but might as well save the roundtrip.
$url = str_replace('://git.drupal.org/', '://git.drupalcode.org/', $url);
}
return formatCompareGitlab($url, $from, $to);
}

Expand Down