use of org.jetbrains.plugins.github.api.GithubConnection in project intellij-community by JetBrains.
the class GithubUtil method getTwoFactorAuthData.
private static void getTwoFactorAuthData(@NotNull final Project project, @NotNull final GithubAuthDataHolder authHolder, @NotNull final ProgressIndicator indicator, @NotNull final GithubAuthData oldAuth) throws GithubOperationCanceledException {
authHolder.runTransaction(oldAuth, () -> {
if (authHolder.getAuthData().getAuthType() != GithubAuthData.AuthType.BASIC) {
throw new GithubOperationCanceledException("Two factor authentication can be used only with Login/Password");
}
GithubApiUtil.askForTwoFactorCodeSMS(new GithubConnection(oldAuth, false));
final Ref<String> codeRef = new Ref<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
codeRef.set(Messages.showInputDialog(project, "Authentication Code", "Github Two-Factor Authentication", null));
}, indicator.getModalityState());
if (codeRef.isNull()) {
throw new GithubOperationCanceledException("Can't get two factor authentication code");
}
GithubSettings settings = GithubSettings.getInstance();
if (settings.getAuthType() == GithubAuthData.AuthType.BASIC && StringUtil.equalsIgnoreCase(settings.getLogin(), oldAuth.getBasicAuth().getLogin())) {
settings.setValidGitAuth(false);
}
return oldAuth.copyWithTwoFactorCode(codeRef.get());
});
}
use of org.jetbrains.plugins.github.api.GithubConnection in project intellij-community by JetBrains.
the class GithubUtil method testConnection.
@NotNull
private static GithubUserDetailed testConnection(@NotNull Project project, @NotNull GithubAuthDataHolder authHolder, @NotNull final ProgressIndicator indicator) throws IOException {
GithubAuthData auth = authHolder.getAuthData();
try {
final GithubConnection connection = new GithubConnection(auth, true);
ScheduledFuture<?> future = null;
try {
future = addCancellationListener(indicator, connection);
return GithubApiUtil.getCurrentUser(connection);
} finally {
connection.close();
if (future != null)
future.cancel(true);
}
} catch (GithubTwoFactorAuthenticationException e) {
getTwoFactorAuthData(project, authHolder, indicator, auth);
return testConnection(project, authHolder, indicator);
}
}
use of org.jetbrains.plugins.github.api.GithubConnection in project intellij-community by JetBrains.
the class GithubUtil method runTask.
public static <T> T runTask(@NotNull Project project, @NotNull GithubAuthDataHolder authHolder, @NotNull final ProgressIndicator indicator, @NotNull AuthLevel authLevel, @NotNull ThrowableConvertor<GithubConnection, T, IOException> task) throws IOException {
GithubAuthData auth = authHolder.getAuthData();
try {
if (!authLevel.accepts(auth)) {
throw new GithubAuthenticationException("Expected other authentication type: " + authLevel);
}
final GithubConnection connection = new GithubConnection(auth, true);
ScheduledFuture<?> future = null;
try {
future = addCancellationListener(indicator, connection);
return task.convert(connection);
} finally {
connection.close();
if (future != null)
future.cancel(true);
}
} catch (GithubTwoFactorAuthenticationException e) {
getTwoFactorAuthData(project, authHolder, indicator, auth);
return runTask(project, authHolder, indicator, authLevel, task);
} catch (GithubAuthenticationException e) {
getValidAuthData(project, authHolder, indicator, authLevel, auth);
return runTask(project, authHolder, indicator, authLevel, task);
}
}
use of org.jetbrains.plugins.github.api.GithubConnection in project intellij-community by JetBrains.
the class GithubCreateGistTestBase method deleteGist.
protected void deleteGist() throws IOException {
if (GIST_ID != null) {
GithubApiUtil.deleteGist(new GithubConnection(myGitHubSettings.getAuthData()), GIST_ID);
GIST = null;
GIST_ID = null;
}
}
use of org.jetbrains.plugins.github.api.GithubConnection in project intellij-community by JetBrains.
the class GithubIssuesTest method testAssigneeIssues6.
public void testAssigneeIssues6() throws Exception {
List<GithubIssue> result = GithubApiUtil.getIssuesAssigned(new GithubConnection(myAuth), myLogin2, REPO_NAME, "", 100, true);
List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
@Override
public Long fun(GithubIssue githubIssue) {
return githubIssue.getNumber();
}
});
List<Long> expected = Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L);
assertTrue(Comparing.haveEqualElements(issues, expected));
}
Aggregations