/** * Shows GitHub login settings if credentials are wrong or empty and return the list of all the * watched repos by user * * @param project * @return */ @Nullable public static List<RepositoryInfo> getAvailableRepos(final Project project) throws IOException { while (!checkCredentials(project)) { final GithubLoginDialog dialog = new GithubLoginDialog(project); dialog.show(); if (!dialog.isOK()) { return null; } } // Otherwise our credentials are valid and they are successfully stored in settings final GithubSettings settings = GithubSettings.getInstance(); final String validPassword = settings.getPassword(); return accessToGithubWithModalProgress( project, settings.getHost(), new ThrowableComputable<List<RepositoryInfo>, IOException>() { @Override public List<RepositoryInfo> compute() throws IOException { ProgressManager.getInstance() .getProgressIndicator() .setText("Extracting info about available repositories"); return getAvailableRepos(settings.getHost(), settings.getLogin(), validPassword); } }); }
/** * Shows GitHub login settings if credentials are wrong or empty and return the list of all the * watched repos by user * * @param project * @return */ @Nullable public static RepositoryInfo getDetailedRepositoryInfo( final Project project, final String owner, final String name) throws IOException { while (!checkCredentials(project)) { final GithubLoginDialog dialog = new GithubLoginDialog(project); dialog.show(); if (!dialog.isOK()) { return null; } } // Otherwise our credentials are valid and they are successfully stored in settings final GithubSettings settings = GithubSettings.getInstance(); final String validPassword = settings.getPassword(); return accessToGithubWithModalProgress( project, settings.getHost(), new ThrowableComputable<RepositoryInfo, IOException>() { @Nullable @Override public RepositoryInfo compute() { ProgressManager.getInstance() .getProgressIndicator() .setText("Extracting detailed info about repository ''" + name + "''"); return getDetailedRepoInfo( settings.getHost(), settings.getLogin(), validPassword, owner, name); } }); }
/** * Checks if user has set up correct user credentials for GitHub access in the settings. * * @return true if we could successfully login with these credentials, false if authentication * failed or in the case of some other error. */ public static boolean checkCredentials(final Project project) { final GithubSettings settings = GithubSettings.getInstance(); try { return checkCredentials( project, settings.getHost(), settings.getLogin(), settings.getPassword()); } catch (IOException e) { // this method is a quick-check if we've got valid user setup. // if an exception happens, we'll show the reason in the login dialog that will be shown right // after checkCredentials failure. LOG.info(e); return false; } }
@Nullable public static String getGithubUrl(final GitRemote gitRemote) { final GithubSettings githubSettings = GithubSettings.getInstance(); final String host = githubSettings.getHost(); final String username = githubSettings.getLogin(); // TODO this doesn't work with organizational accounts final String userRepoMarkerSSHProtocol = host + ":" + username + "/"; final String userRepoMarkerOtherProtocols = host + "/" + username + "/"; for (String pushUrl : gitRemote.getUrls()) { if (pushUrl.contains(userRepoMarkerSSHProtocol) || pushUrl.contains(userRepoMarkerOtherProtocols)) { return pushUrl; } } return null; }