Skip to content

Commit

Permalink
RepositoryUtils: fix GitLab URL generation
Browse files Browse the repository at this point in the history
GitLab started using a `/-/` component to act as a separator between
project paths and project resources.

Also fold the old factored-out function back into the Gitorious
implementation.

Also make the static analysis happy with stricter comparisons.
  • Loading branch information
mathstuf committed Jul 16, 2024
1 parent cd9b934 commit 0269eea
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions app/Utils/RepositoryUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,23 +357,6 @@ public static function get_gitweb2_diff_url($projecturl, $directory, $file, $rev
return make_cdash_url($diff_url);
}

/** Return the Gitorious/GitHub diff URL */
public static function get_gitoriousish_diff_url($projecturl, $directory, $file, $revision, $blobs, $branch = 'master')
{
if ($revision != '') {
$diff_url = $projecturl . '/commit/' . $revision;
} elseif ($file != '') {
$diff_url = $projecturl . '/' . $blobs . '/' . $branch . '/';
if ($directory != '') {
$diff_url .= $directory . '/';
}
$diff_url .= $file;
} else {
return '';
}
return make_cdash_url($diff_url);
}

/** Return the Stash diff URL */
public static function get_stash_diff_url($projecturl, $directory, $file, $revision)
{
Expand All @@ -388,8 +371,18 @@ public static function get_stash_diff_url($projecturl, $directory, $file, $revis
/** Return the Gitorious diff URL */
public static function get_gitorious_diff_url($projecturl, $directory, $file, $revision)
{
// Gitorious uses 'blobs' or 'trees' (plural)
return self::get_gitoriousish_diff_url($projecturl, $directory, $file, $revision, 'blobs');
if ($revision !== '') {
$diff_url = $projecturl . '/commit/' . $revision;
} elseif ($file !== '') {
$diff_url = $projecturl . '/blobs/master/';
if ($directory !== '') {
$diff_url .= $directory . '/';
}
$diff_url .= $file;
} else {
return '';
}
return make_cdash_url($diff_url);
}

/** Return the source directory for a source file */
Expand Down Expand Up @@ -449,8 +442,20 @@ public static function get_github_diff_url($projecturl, $directory, $file, $revi
/** Return the GitLab diff URL */
public static function get_gitlab_diff_url($projecturl, $directory, $file, $revision)
{
// GitLab uses 'blob' or 'tree' (singular, no s)
return self::get_gitoriousish_diff_url($projecturl, $directory, $file, $revision, 'blob');
// Since GitLab supports arbitrarily nested groups, there is a `/-/`
// component to start per-project resources.
if ($revision !== '') {
$diff_url = $projecturl . '/-/commit/' . $revision;
} elseif ($file !== '') {
$diff_url = $projecturl . '/-/blob/master/';
if ($directory !== '') {
$diff_url .= $directory . '/';
}
$diff_url .= $file;
} else {
return '';
}
return make_cdash_url($diff_url);
}

/** Return the cgit diff URL */
Expand Down

0 comments on commit 0269eea

Please sign in to comment.