fix: Avoid GitHub api request without token (#325)

GitHub allows to use only 60 unauthorized reqests per host. In order to avid API rate limit exceeded GitHub eroor,
substitute the unauthorized GitHub API request to an HTTP repository request.
pull/327/head
Igor Vinokur 2022-07-11 15:26:06 +03:00 committed by GitHub
parent 1d87137f6f
commit 8aaf918353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -43,10 +43,10 @@ class GithubAuthorizingFileContentProvider extends AuthorizingFileContentProvide
protected boolean isPublicRepository(GithubUrl remoteFactoryUrl) {
try {
urlFetcher.fetch(
GithubApiClient.GITHUB_API_SERVER
+ "/repos/"
remoteFactoryUrl.getHostName()
+ '/'
+ remoteFactoryUrl.getUsername()
+ "/"
+ '/'
+ remoteFactoryUrl.getRepository());
return true;
} catch (IOException e) {

View File

@ -19,6 +19,7 @@ import java.io.FileNotFoundException;
import org.eclipse.che.api.factory.server.scm.GitCredentialManager;
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;
@ -70,11 +71,10 @@ public class GithubAuthorizingFileContentProviderTest {
public void shouldThrowNotFoundForPublicRepos() throws Exception {
URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
String url = "https://raw.githubusercontent.com/foo/bar/devfile.yaml";
when(urlFetcher.fetch(eq(url), anyString())).thenThrow(FileNotFoundException.class);
var personalAccessToken = new PersonalAccessToken(url, "che", "token");
when(personalAccessTokenManager.fetchAndSave(any(), anyString()))
.thenReturn(personalAccessToken);
when(urlFetcher.fetch(eq("https://api.github.com/repos/eclipse/che"))).thenReturn("OK");
.thenThrow(UnknownScmProviderException.class);
when(urlFetcher.fetch(eq(url))).thenThrow(FileNotFoundException.class);
when(urlFetcher.fetch(eq("https://github.com/eclipse/che"))).thenReturn("OK");
GithubUrl githubUrl = new GithubUrl().withUsername("eclipse").withRepository("che");
FileContentProvider fileContentProvider =
new GithubAuthorizingFileContentProvider(