예제 #1
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());
  }
예제 #3
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;
  }