From 0269eea85d55e053f9730852c32bd0d5fdfb832c Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 16 Jul 2024 09:26:26 -0400 Subject: [PATCH] RepositoryUtils: fix GitLab URL generation 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. --- app/Utils/RepositoryUtils.php | 47 +++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/app/Utils/RepositoryUtils.php b/app/Utils/RepositoryUtils.php index f22a290e01..a7a8c37a28 100644 --- a/app/Utils/RepositoryUtils.php +++ b/app/Utils/RepositoryUtils.php @@ -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) { @@ -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 */ @@ -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 */