void BrowsePullRequest(GitPullRequestService service, Repository repo) { var gitHubRepositories = service.GetGitHubRepositories(repo); var prs = service.FindPullRequests(gitHubRepositories, repo.Head); if (prs.Count > 0) { foreach (var pr in prs) { var prUrl = service.GetPullRequestUrl(pr.Repository, pr.Number); Browse(prUrl); } return; } var compareUrl = service.FindCompareUrl(gitHubRepositories, repo); if (compareUrl != null) { Browse(compareUrl); return; } Console.WriteLine("Couldn't find pull request or remote branch"); }
public void FindCompareUrl(string remoteName, string remoteUrl, string upstreamBranchCanonicalName, string referenceCanonicalName, string expectUrl) { var remote = remoteName != null?CreateRemote(remoteName, remoteUrl) : null; var remotes = remoteName != null ? new[] { remote } : Array.Empty <Remote>(); var repo = CreateRepository("headSha", remoteName, upstreamBranchCanonicalName, remotes); if (remote != null) { AddRemoteReferences(repo, remote, new Dictionary <string, string> { { referenceCanonicalName, "refSha" } }); } var target = new GitPullRequestService(); var gitHubRepositories = target.GetGitHubRepositories(repo); var compareUrl = target.FindCompareUrl(gitHubRepositories, repo); Assert.That(compareUrl, Is.EqualTo(expectUrl)); }
void BrowsePullRequest(GitPullRequestService service, Repository repo, Action <Exception> exceptionLogger) { var remoteRepositoryCache = service.GetRemoteRepositoryCache(repo, exceptionLogger); var upstreamRepositoires = CreateUpstreamRepositoires(remoteRepositoryCache, repo); var prs = (PullRequestNumber == 0 ? service.FindPullRequests(remoteRepositoryCache, upstreamRepositoires, repo.Head) : repo.Branches .SelectMany(b => service.FindPullRequests(remoteRepositoryCache, upstreamRepositoires, b)) .Where(pr => pr.Number == PullRequestNumber) .Distinct()).ToList(); if (prs.Count > 0) { foreach (var pr in prs) { var url = pr.Repository.GetPullRequestUrl(pr.Number); Console.WriteLine(url); TryBrowse(url); } return; } if (PullRequestNumber != 0) { Console.WriteLine("Couldn't find pull request #" + PullRequestNumber); return; } var compareUrl = service.FindCompareUrl(remoteRepositoryCache, repo); if (compareUrl != null) { Console.WriteLine(compareUrl); TryBrowse(compareUrl); return; } Console.WriteLine("Couldn't find pull request or remote branch"); }