Apply permanetn `ref` query param to the GitLab raw file location request

Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
pull/545/head
Igor Vinokur 2023-08-17 14:29:22 +03:00
parent b2dfdb0c84
commit 68b3fe3f74
3 changed files with 6 additions and 9 deletions

View File

@ -11,10 +11,10 @@
*/
package org.eclipse.che.api.factory.server.gitlab;
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.net.URLEncoder.encode;
import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@ -120,7 +120,7 @@ public class GitlabUrl extends DefaultFactoryUrl {
}
protected GitlabUrl withBranch(String branch) {
if (!Strings.isNullOrEmpty(branch)) {
if (!isNullOrEmpty(branch)) {
this.branch = branch;
}
return this;
@ -165,11 +165,8 @@ public class GitlabUrl extends DefaultFactoryUrl {
.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;
}

View File

@ -42,7 +42,7 @@ public class GitlabAuthorizingFileContentProviderTest {
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"));
}

View File

@ -71,11 +71,11 @@ public class GitlabUrlTest {
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"
},
{
"https://gitlab.net/eclipse/fooproj/-/tree/master/",