Search in sources :

Example 1 with GithubAuthData

use of org.jetbrains.plugins.github.util.GithubAuthData in project intellij-community by JetBrains.

the class GithubShareProjectTest method checkGithubExists.

protected void checkGithubExists() throws IOException {
    GithubAuthData auth = myGitHubSettings.getAuthData();
    GithubRepoDetailed githubInfo = GithubApiUtil.getDetailedRepoInfo(new GithubConnection(auth), myLogin1, PROJECT_NAME);
    assertNotNull("GitHub repository does not exist", githubInfo);
}
Also used : GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubRepoDetailed(org.jetbrains.plugins.github.api.data.GithubRepoDetailed) GithubAuthData(org.jetbrains.plugins.github.util.GithubAuthData)

Example 2 with GithubAuthData

use of org.jetbrains.plugins.github.util.GithubAuthData in project intellij-community by JetBrains.

the class GithubHttpAuthDataProvider method getAuthData.

@Nullable
@Override
public AuthData getAuthData(@NotNull String url) {
    if (!GithubUrlUtil.isGithubUrl(url)) {
        return null;
    }
    GithubSettings settings = GithubSettings.getInstance();
    if (!settings.isValidGitAuth()) {
        return null;
    }
    String host1 = GithubUrlUtil.getHostFromUrl(settings.getHost());
    String host2 = GithubUrlUtil.getHostFromUrl(url);
    if (!host1.equalsIgnoreCase(host2)) {
        return null;
    }
    GithubAuthData auth = settings.getAuthData();
    switch(auth.getAuthType()) {
        case BASIC:
            GithubAuthData.BasicAuth basicAuth = auth.getBasicAuth();
            assert basicAuth != null;
            if (StringUtil.isEmptyOrSpaces(basicAuth.getLogin()) || StringUtil.isEmptyOrSpaces(basicAuth.getPassword())) {
                return null;
            }
            return new AuthData(basicAuth.getLogin(), basicAuth.getPassword());
        case TOKEN:
            GithubAuthData.TokenAuth tokenAuth = auth.getTokenAuth();
            assert tokenAuth != null;
            if (StringUtil.isEmptyOrSpaces(tokenAuth.getToken())) {
                return null;
            }
            return new AuthData(tokenAuth.getToken(), "x-oauth-basic");
        default:
            return null;
    }
}
Also used : AuthData(com.intellij.util.AuthData) GithubAuthData(org.jetbrains.plugins.github.util.GithubAuthData) GithubAuthData(org.jetbrains.plugins.github.util.GithubAuthData) GithubSettings(org.jetbrains.plugins.github.util.GithubSettings) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GithubAuthData (org.jetbrains.plugins.github.util.GithubAuthData)2 AuthData (com.intellij.util.AuthData)1 Nullable (org.jetbrains.annotations.Nullable)1 GithubConnection (org.jetbrains.plugins.github.api.GithubConnection)1 GithubRepoDetailed (org.jetbrains.plugins.github.api.data.GithubRepoDetailed)1 GithubSettings (org.jetbrains.plugins.github.util.GithubSettings)1