Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getProviderUrl() instead of getHostName() when generating gitlab … #739

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GitlabAuthorizingFileContentProvider extends AuthorizingFileContentProvide
@Override
protected boolean isPublicRepository(GitlabUrl remoteFactoryUrl) {
try {
urlFetcher.fetch(remoteFactoryUrl.getHostName() + '/' + remoteFactoryUrl.getSubGroups());
urlFetcher.fetch(remoteFactoryUrl.getProviderUrl() + '/' + remoteFactoryUrl.getSubGroups());
return true;
} catch (IOException e) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.FileNotFoundException;
import org.eclipse.che.api.factory.server.scm.PersonalAccessToken;
import org.eclipse.che.api.factory.server.scm.PersonalAccessTokenManager;
import org.eclipse.che.api.factory.server.scm.exception.UnknownScmProviderException;
import org.eclipse.che.api.workspace.server.devfile.FileContentProvider;
import org.eclipse.che.api.workspace.server.devfile.URLFetcher;
import org.mockito.Mock;
Expand Down Expand Up @@ -59,4 +61,23 @@ public void shouldPreserveAbsolutePaths() throws Exception {
fileContentProvider.fetchContent(url);
verify(urlFetcher).fetch(eq(url), eq("Bearer my-token"));
}

@Test(expectedExceptions = FileNotFoundException.class)
public void shouldThrowFileNotFoundException() throws Exception {
// given
URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
when(urlFetcher.fetch(
eq(
"https://gitlab.com/api/v4/projects/eclipse%2Fche/repository/files/devfile.yaml/raw?ref=HEAD")))
.thenThrow(new FileNotFoundException());
when(urlFetcher.fetch(eq("https://gitlab.com/eclipse/che"))).thenReturn("content");
when(personalAccessTokenManager.getAndStore(anyString()))
.thenThrow(new UnknownScmProviderException("", ""));
GitlabUrl gitlabUrl = new GitlabUrl().withHostName("gitlab.com").withSubGroups("eclipse/che");
FileContentProvider fileContentProvider =
new GitlabAuthorizingFileContentProvider(gitlabUrl, urlFetcher, personalAccessTokenManager);

// when
fileContentProvider.fetchContent("devfile.yaml");
}
}
Loading