@Nullable private String doLoadDefaultBranch( @NotNull final GithubFullPath fork, @NotNull ProgressIndicator indicator) throws IOException { GithubRepo repo = GithubUtil.runTask( myProject, myAuthHolder, indicator, new ThrowableConvertor<GithubConnection, GithubRepo, IOException>() { @Override public GithubRepo convert(@NotNull GithubConnection connection) throws IOException { return GithubApiUtil.getDetailedRepoInfo( connection, fork.getUser(), fork.getRepository()); } }); return repo.getDefaultBranch(); }
@Nullable private static GithubFullPath findRepositoryByUser( @NotNull Project project, @NotNull String user, @NotNull Set<GithubFullPath> forks, @NotNull GithubAuthData auth, @NotNull GithubRepo source) { for (GithubFullPath path : forks) { if (StringUtil.equalsIgnoreCase(user, path.getUser())) { return path; } } try { GithubRepoDetailed target = GithubApiUtil.getDetailedRepoInfo(auth, user, source.getName()); if (target.getSource() != null && StringUtil.equals(target.getSource().getUserName(), source.getUserName())) { return target.getFullPath(); } } catch (IOException ignore) { // such repo may not exist } try { GithubRepo fork = GithubApiUtil.findForkByUser(auth, source.getUserName(), source.getName(), user); if (fork != null) { return fork.getFullPath(); } } catch (IOException e) { GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e); } return null; }
@Nullable private ForkInfo doAddFork(@NotNull GithubRepo repo, @NotNull ProgressIndicator indicator) { GithubFullPath path = repo.getFullPath(); for (ForkInfo fork : myForks) { if (fork.getPath().equals(path)) { return fork; } } try { List<String> branches = loadBranches(path, indicator); String defaultBranch = repo.getDefaultBranch(); ForkInfo fork = new ForkInfo(path, branches, defaultBranch); myForks.add(fork); return fork; } catch (IOException e) { GithubNotifications.showWarning( myProject, "Can't load branches for " + path.getFullName(), e); return null; } }