diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java index 0155eb17cddb..60e6bb91ea4d 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java @@ -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,