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

Commit 0f59f7e

Browse files
committed
Make GetPullRequestForCurrentBranch return (tuple)
Convert GetPullRequestForCurrentBranch to return (string owner, int number). This allows the tuple to be compared directly.
1 parent 713d9c4 commit 0f59f7e

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
231231
if (hasCheckRuns)
232232
{
233233
checksHasFailure = checkRuns
234-
.Any(model => model.Conclusion.HasValue
235-
&& (model.Conclusion.Value == CheckConclusionState.Failure
234+
.Any(model => model.Conclusion.HasValue
235+
&& (model.Conclusion.Value == CheckConclusionState.Failure
236236
|| model.Conclusion.Value == CheckConclusionState.ActionRequired));
237237

238238
if (!checksHasFailure)
@@ -718,7 +718,7 @@ public IObservable<Unit> SwitchToBranch(ILocalRepositoryModel repository, PullRe
718718
});
719719
}
720720

721-
public IObservable<Tuple<string, int>> GetPullRequestForCurrentBranch(ILocalRepositoryModel repository)
721+
public IObservable<(string owner, int number)> GetPullRequestForCurrentBranch(ILocalRepositoryModel repository)
722722
{
723723
return Observable.Defer(async () =>
724724
{
@@ -912,7 +912,7 @@ async Task<bool> IsBranchMarkedAsPullRequest(IRepository repo, string branchName
912912
{
913913
var prConfigKey = $"branch.{branchName}.{SettingGHfVSPullRequest}";
914914
var value = ParseGHfVSConfigKeyValue(await gitClient.GetConfig<string>(repo, prConfigKey));
915-
return value != null &&
915+
return value != default &&
916916
value.Item1 == pullRequest.BaseRepositoryOwner &&
917917
value.Item2 == pullRequest.Number;
918918
}
@@ -983,7 +983,7 @@ static string BuildGHfVSConfigKeyValue(string owner, int number)
983983
return owner + '#' + number.ToString(CultureInfo.InvariantCulture);
984984
}
985985

986-
static Tuple<string, int> ParseGHfVSConfigKeyValue(string value)
986+
static (string owner, int number) ParseGHfVSConfigKeyValue(string value)
987987
{
988988
if (value != null)
989989
{
@@ -996,12 +996,12 @@ static Tuple<string, int> ParseGHfVSConfigKeyValue(string value)
996996

997997
if (int.TryParse(value.Substring(separator + 1), NumberStyles.None, CultureInfo.InvariantCulture, out number))
998998
{
999-
return Tuple.Create(owner, number);
999+
return (owner, number);
10001000
}
10011001
}
10021002
}
10031003

1004-
return null;
1004+
return default;
10051005
}
10061006

10071007
class ListItemAdapter : PullRequestListItemModel

src/GitHub.App/Services/TeamExplorerContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class TeamExplorerContext : ITeamExplorerContext
4040
string solutionPath;
4141
string repositoryPath;
4242
UriString cloneUrl;
43-
Tuple<string, int> pullRequest;
43+
(string owner, int number) pullRequest;
4444

4545
ILocalRepositoryModel repositoryModel;
4646
JoinableTask refreshJoinableTask;
@@ -110,7 +110,7 @@ async Task RefreshAsync()
110110
{
111111
var newRepositoryPath = repo?.LocalPath;
112112
var newCloneUrl = repo?.CloneUrl;
113-
var newPullRequest = repo != null ? await pullRequestService.GetPullRequestForCurrentBranch(repo) : null;
113+
var newPullRequest = repo != null ? await pullRequestService.GetPullRequestForCurrentBranch(repo) : default;
114114

115115
if (newRepositoryPath != repositoryPath)
116116
{

src/GitHub.Exports.Reactive/Services/IPullRequestService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ IObservable<IPullRequestModel> CreatePullRequest(IModelService modelService,
173173
/// This method does not do an API request - it simply checks the mark left in the git
174174
/// config by <see cref="Checkout(ILocalRepositoryModel, PullRequestDetailModel, string)"/>.
175175
/// </remarks>
176-
IObservable<Tuple<string, int>> GetPullRequestForCurrentBranch(ILocalRepositoryModel repository);
176+
IObservable<(string owner, int number)> GetPullRequestForCurrentBranch(ILocalRepositoryModel repository);
177177

178178
/// <summary>
179179
/// Gets the encoding for the specified local file.

src/GitHub.InlineReviews/Services/PullRequestSessionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ async Task StatusChanged()
203203
var session = CurrentSession;
204204

205205
var pr = await service.GetPullRequestForCurrentBranch(repository).FirstOrDefaultAsync();
206-
if (pr != null)
206+
if (pr != default)
207207
{
208208
var changePR =
209209
pr.Item1 != (session?.PullRequest.BaseRepositoryOwner) ||

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void ReadsPullRequestFromCorrectFork()
4141
var sessionService = CreateSessionService();
4242

4343
service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(
44-
Observable.Return(Tuple.Create("fork", CurrentBranchPullRequestNumber)));
44+
Observable.Return(("fork", CurrentBranchPullRequestNumber)));
4545

4646
var connectionManager = CreateConnectionManager();
4747
var target = CreateTarget(
@@ -80,7 +80,7 @@ public void CreatesSessionForCurrentBranch()
8080
public void CurrentSessionIsNullIfNoPullRequestForCurrentBranch()
8181
{
8282
var service = CreatePullRequestService();
83-
service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Empty<Tuple<string, int>>());
83+
service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Empty<(string, int)>());
8484

8585
var target = CreateTarget(service: service);
8686

@@ -98,7 +98,7 @@ public void CurrentSessionChangesWhenBranchChanges()
9898

9999
var session = target.CurrentSession;
100100

101-
service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(Tuple.Create("foo", 22)));
101+
service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(("foo", 22)));
102102
teamExplorerContext.StatusChanged += Raise.Event();
103103

104104
Assert.That(session, Is.Not.SameAs(target.CurrentSession));
@@ -124,7 +124,7 @@ public void CurrentSessionChangesToNullIfNoPullRequestForCurrentBranch()
124124
teamExplorerContext: teamExplorerContext);
125125
Assert.That(target.CurrentSession, Is.Not.Null);
126126

127-
Tuple<string, int> newPullRequest = null;
127+
(string owner, int number) newPullRequest = default;
128128
service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(newPullRequest));
129129
teamExplorerContext.StatusChanged += Raise.Event();
130130

@@ -813,14 +813,14 @@ public async Task GetSessionUpdatesCurrentSessionIfCurrentBranchIsPullRequestBut
813813
var model = CreatePullRequestModel();
814814
var sessionService = CreateSessionService(model);
815815

816-
service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Empty<Tuple<string, int>>());
816+
service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Empty<(string, int)>());
817817

818818
var target = CreateTarget(service: service, sessionService: sessionService);
819819

820820
Assert.That(target.CurrentSession, Is.Null);
821821

822822
service.EnsureLocalBranchesAreMarkedAsPullRequests(Arg.Any<ILocalRepositoryModel>(), model).Returns(Observable.Return(true));
823-
service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(Tuple.Create("owner", CurrentBranchPullRequestNumber)));
823+
service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(("owner", CurrentBranchPullRequestNumber)));
824824

825825
var session = await target.GetSession("owner", "name", CurrentBranchPullRequestNumber);
826826

@@ -881,7 +881,7 @@ PullRequestDetailModel CreatePullRequestModel(
881881
IPullRequestService CreatePullRequestService(string owner = "owner")
882882
{
883883
var result = Substitute.For<IPullRequestService>();
884-
result.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return(Tuple.Create(owner, CurrentBranchPullRequestNumber)));
884+
result.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Return((owner, CurrentBranchPullRequestNumber)));
885885
return result;
886886
}
887887

0 commit comments

Comments
 (0)