Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit b14a405

Browse files
Merge branch 'master' into fixes/1828-pr-list-deadlock
2 parents 1c94bcc + 659df5b commit b14a405

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public IObservable<Unit> Checkout(ILocalRepositoryModel repository, PullRequestD
392392
{
393393
await gitClient.Checkout(repo, localBranchName);
394394
}
395-
else if (repository.CloneUrl.Owner == pullRequest.HeadRepositoryOwner)
395+
else if (string.Equals(repository.CloneUrl.Owner, pullRequest.HeadRepositoryOwner, StringComparison.OrdinalIgnoreCase))
396396
{
397397
var remote = await gitClient.GetHttpRemote(repo, "origin");
398398
await gitClient.Fetch(repo, remote.Name);
@@ -524,7 +524,7 @@ public IObservable<bool> EnsureLocalBranchesAreMarkedAsPullRequests(ILocalReposi
524524

525525
public bool IsPullRequestFromRepository(ILocalRepositoryModel repository, PullRequestDetailModel pullRequest)
526526
{
527-
return pullRequest.HeadRepositoryOwner == repository.CloneUrl.Owner;
527+
return string.Equals(repository.CloneUrl?.Owner, pullRequest.HeadRepositoryOwner, StringComparison.OrdinalIgnoreCase);
528528
}
529529

530530
public IObservable<Unit> SwitchToBranch(ILocalRepositoryModel repository, PullRequestDetailModel pullRequest)

src/GitHub.InlineReviews/Services/PullRequestSessionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ async Task<PullRequestSession> GetSessionInternal(string owner, string name, int
225225
{
226226
PullRequestSession session = null;
227227
WeakReference<PullRequestSession> weakSession;
228-
var key = Tuple.Create(owner, number);
228+
var key = Tuple.Create(owner.ToLowerInvariant(), number);
229229

230230
if (sessions.TryGetValue(key, out weakSession))
231231
{

test/GitHub.App.UnitTests/Services/PullRequestServiceTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,35 @@ public async Task ShouldCheckoutLocalBranchAsync()
777777
Assert.That(4, Is.EqualTo(gitClient.ReceivedCalls().Count()));
778778
}
779779

780+
[Test]
781+
public async Task ShouldCheckoutLocalBranchOwnerCaseMismatchAsync()
782+
{
783+
var gitClient = MockGitClient();
784+
var service = CreateTarget(gitClient, MockGitService());
785+
786+
var localRepo = Substitute.For<ILocalRepositoryModel>();
787+
localRepo.CloneUrl.Returns(new UriString("https://foo.bar/Owner/repo"));
788+
789+
var pr = new PullRequestDetailModel
790+
{
791+
Number = 5,
792+
BaseRefName = "master",
793+
BaseRefSha = "123",
794+
BaseRepositoryOwner = "owner",
795+
HeadRefName = "prbranch",
796+
HeadRefSha = "123",
797+
HeadRepositoryOwner = "owner",
798+
};
799+
800+
await service.Checkout(localRepo, pr, "prbranch");
801+
802+
gitClient.Received().Fetch(Arg.Any<IRepository>(), "origin").Forget();
803+
gitClient.Received().Checkout(Arg.Any<IRepository>(), "prbranch").Forget();
804+
gitClient.Received().SetConfig(Arg.Any<IRepository>(), "branch.prbranch.ghfvs-pr-owner-number", "owner#5").Forget();
805+
806+
Assert.That(4, Is.EqualTo(gitClient.ReceivedCalls().Count()));
807+
}
808+
780809
[Test]
781810
public async Task ShouldCheckoutBranchFromForkAsync()
782811
{
@@ -899,6 +928,19 @@ public async Task ShouldReturnPullRequestBranchForPullRequestFromSameRepositoryA
899928
Assert.That("source", Is.EqualTo(result.Name));
900929
}
901930

931+
[Test]
932+
public async Task ShouldReturnPullRequestBranchForPullRequestFromSameRepositoryOwnerCaseMismatchAsync()
933+
{
934+
var service = CreateTarget(MockGitClient(), MockGitService());
935+
936+
var localRepo = Substitute.For<ILocalRepositoryModel>();
937+
localRepo.CloneUrl.Returns(new UriString("https://github.com/Foo/bar"));
938+
939+
var result = await service.GetLocalBranches(localRepo, CreatePullRequest(fromFork: false));
940+
941+
Assert.That("source", Is.EqualTo(result.Name));
942+
}
943+
902944
[Test]
903945
public async Task ShouldReturnMarkedBranchForPullRequestFromForkAsync()
904946
{

test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionManagerTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,19 @@ public async Task GetSessionReturnsSameSessionForSamePullRequest()
770770
Assert.That(result1, Is.Not.SameAs(result3));
771771
}
772772

773+
[Test]
774+
public async Task GetSessionReturnsSameSessionForSamePullRequestOwnerCaseMismatch()
775+
{
776+
var target = CreateTarget();
777+
var newModel = CreatePullRequestModel(NotCurrentBranchPullRequestNumber);
778+
var result1 = await target.GetSession("owner", "repo", 5);
779+
var result2 = await target.GetSession("Owner", "repo", 5);
780+
var result3 = await target.GetSession("owner", "repo", 6);
781+
782+
Assert.That(result1, Is.SameAs(result2));
783+
Assert.That(result1, Is.Not.SameAs(result3));
784+
}
785+
773786
[Test]
774787
public async Task SessionCanBeCollected()
775788
{

0 commit comments

Comments
 (0)