From ebefa6928b62f54386b2bf77cd0905116ead8c9a Mon Sep 17 00:00:00 2001 From: ivinokur Date: Fri, 17 Nov 2023 12:44:31 +0200 Subject: [PATCH] fixup! Add support for PATs in GitHub Enterprise server --- .../github/AbstractGithubPersonalAccessTokenFetcher.java | 1 + .../api/factory/server/github/AbstractGithubURLParser.java | 3 +++ .../api/factory/server/gitlab/GitlabOAuthTokenFetcher.java | 4 ---- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubPersonalAccessTokenFetcher.java b/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubPersonalAccessTokenFetcher.java index 1aa4f0e28f..efb7646435 100644 --- a/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubPersonalAccessTokenFetcher.java +++ b/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubPersonalAccessTokenFetcher.java @@ -207,6 +207,7 @@ public abstract class AbstractGithubPersonalAccessTokenFetcher public Optional> isValid(PersonalAccessTokenParams params) { GithubApiClient apiClient; if (githubApiClient.isConnected(params.getScmProviderUrl())) { + // The url from the token has the same url as the api client, no need to create a new one. apiClient = githubApiClient; } else { if ("github".equals(params.getScmTokenName())) { diff --git a/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubURLParser.java b/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubURLParser.java index 24b3a47736..008df378a7 100644 --- a/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubURLParser.java +++ b/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubURLParser.java @@ -90,7 +90,10 @@ public abstract class AbstractGithubURLParser { String trimmedUrl = trimEnd(url, '/'); return githubPattern.matcher(trimmedUrl).matches() || githubSSHPattern.matcher(trimmedUrl).matches() + // If the GitHub URL is not configured, try to find it in a manually added user namespace + // token. || isUserTokenPresent(trimmedUrl) + // Try to call an API request to see if the URL matches GitHub. || isApiRequestRelevant(trimmedUrl); } diff --git a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabOAuthTokenFetcher.java b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabOAuthTokenFetcher.java index 92cae768ef..aaf4811edd 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabOAuthTokenFetcher.java +++ b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabOAuthTokenFetcher.java @@ -232,8 +232,4 @@ public class GitlabOAuthTokenFetcher implements PersonalAccessTokenFetcher { ? new GitlabApiClient(scmServerUrl) : null; } - - public String getProviderName() { - return OAUTH_PROVIDER_NAME; - } }