Github: Optimise fork search

This commit is contained in:
Aleksey Pivovarov
2013-08-01 11:33:30 +04:00
parent 20471b30da
commit 1ff03f4eb1

View File

@@ -237,19 +237,33 @@ public class GithubCreatePullRequestAction extends DumbAwareAction {
@NotNull GithubRepoDetailed repo,
@Nullable GithubFullPath upstreamPath) {
String targetUser = onto.substring(0, onto.indexOf(':'));
@Nullable GithubRepo parent = repo.getParent();
@Nullable GithubRepo source = repo.getSource();
if (StringUtil.equalsIgnoreCase(targetUser, repo.getUserName())) {
if (isRepoOwner(targetUser, repo)) {
return repo.getFullPath();
}
if (repo.getParent() != null && StringUtil.equalsIgnoreCase(targetUser, repo.getParent().getUserName())) {
return repo.getParent().getFullPath();
if (parent != null && isRepoOwner(targetUser, parent)) {
return parent.getFullPath();
}
if (source != null && isRepoOwner(targetUser, source)) {
return source.getFullPath();
}
if (upstreamPath != null && StringUtil.equalsIgnoreCase(targetUser, upstreamPath.getUser())) {
return upstreamPath;
}
if (repo.getSource() != null) {
if (source != null) {
try {
GithubRepo fork = GithubApiUtil.findForkByUser(auth, repo.getSource().getUserName(), repo.getSource().getName(), targetUser);
GithubRepoDetailed target = GithubApiUtil.getDetailedRepoInfo(auth, targetUser, repo.getName());
if (target.getSource() != null && StringUtil.equalsIgnoreCase(target.getSource().getUserName(), source.getUserName())) {
return target.getFullPath();
}
}
catch (IOException ignore) {
}
try {
GithubRepo fork = GithubApiUtil.findForkByUser(auth, source.getUserName(), source.getName(), targetUser);
if (fork != null) {
return fork.getFullPath();
}
@@ -262,6 +276,10 @@ public class GithubCreatePullRequestAction extends DumbAwareAction {
return null;
}
private static boolean isRepoOwner(@NotNull String user, @NotNull GithubRepo repo) {
return StringUtil.equalsIgnoreCase(user, repo.getUserName());
}
private static void initLoadAvailableBranches(@NotNull final Project project,
@NotNull final GithubInfo info,
@Nullable final GithubFullPath upstreamPath,