Пример #1
0
 /**
  * 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);
         }
       });
 }
Пример #2
0
 /**
  * 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);
         }
       });
 }
Пример #3
0
 /**
  * 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
  @Override
  public AuthData getAuthData(@NotNull String url) {
    if (!GithubUtil.isGithubUrl(url)) {
      return null;
    }

    GithubSettings settings = GithubSettings.getInstance();
    String login = settings.getLogin();
    if (StringUtil.isEmptyOrSpaces(login)) {
      return null;
    }

    return new AuthData(login, settings.getPassword());
  }
Пример #5
0
  @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;
  }
Пример #6
0
 /**
  * @deprecated The host may be defined in different formats. Use {@link
  *     GithubApiUtil#getApiUrl(String)} instead.
  */
 @Deprecated
 public static String getHttpsUrl() {
   return "https://" + GithubSettings.getInstance().getHost();
 }
Пример #7
0
 public static boolean isGithubUrl(@NotNull String url) {
   return url.contains(GithubApiUtil.removeProtocolPrefix(GithubSettings.getInstance().getHost()));
 }