From 6edfa3910f6298b73f5d02f7ead41cbfd18ee28d Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Tue, 5 Sep 2023 12:51:27 +0300 Subject: [PATCH] Apply permanetn `ref` query param to the GitLab raw file location request (#545) A user claims that he couldn't start a workspace form GitLab repository because of the raw file location request doesn't contain the ref query parameter. Rework the way of generating the GitLab raw file location function to permanently add the ref query param. --- .../org/eclipse/che/api/factory/server/gitlab/GitlabUrl.java | 5 +---- .../gitlab/GitlabAuthorizingFileContentProviderTest.java | 2 +- .../eclipse/che/api/factory/server/gitlab/GitlabUrlTest.java | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrl.java b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrl.java index 74f3f108c3..f0bda15187 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrl.java +++ b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrl.java @@ -178,11 +178,8 @@ public String rawFileLocation(String fileName) { .add("repository") .add("files") .add(encode(fileName, Charsets.UTF_8)) - .add("raw") + .add("raw?ref=" + (isNullOrEmpty(branch) ? "HEAD" : branch)) .toString(); - if (branch != null) { - resultUrl = resultUrl + "?ref=" + branch; - } return resultUrl; } diff --git a/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProviderTest.java b/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProviderTest.java index 6150c317b7..ca74f83fae 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProviderTest.java +++ b/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProviderTest.java @@ -41,7 +41,7 @@ public void shouldExpandRelativePaths() throws Exception { verify(urlFetcher) .fetch( eq( - "https://gitlab.net/api/v4/projects/eclipse%2Fche/repository/files/devfile.yaml/raw"), + "https://gitlab.net/api/v4/projects/eclipse%2Fche/repository/files/devfile.yaml/raw?ref=HEAD"), eq("Bearer my-token")); } diff --git a/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlTest.java b/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlTest.java index c392362af6..6abaac16fa 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlTest.java +++ b/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlTest.java @@ -80,11 +80,11 @@ public static Object[][] urlsProvider() { return new Object[][] { { "https://gitlab.net/eclipse/che.git", - "https://gitlab.net/api/v4/projects/eclipse%%2Fche/repository/files/%s/raw" + "https://gitlab.net/api/v4/projects/eclipse%%2Fche/repository/files/%s/raw?ref=HEAD" }, { "https://gitlab.net/eclipse/fooproj/che.git", - "https://gitlab.net/api/v4/projects/eclipse%%2Ffooproj%%2Fche/repository/files/%s/raw" + "https://gitlab.net/api/v4/projects/eclipse%%2Ffooproj%%2Fche/repository/files/%s/raw?ref=HEAD" }, { "git@gitlab.net:eclipse/che.git",