Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/GitHub.App/GitHub.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
<HintPath>..\..\packages\Microsoft.VisualStudio.Utilities.14.3.25407\lib\net45\Microsoft.VisualStudio.Utilities.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.Utilities, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.VisualStudio.Utilities.14.3.25407\lib\net45\Microsoft.VisualStudio.Utilities.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="rothko, Version=0.0.3.0, Culture=neutral, PublicKeyToken=9f664c41f503810a, processorArchitecture=MSIL">
Expand Down Expand Up @@ -236,6 +240,7 @@
<Compile Include="ViewModels\GitHubPane\PullRequestCreationViewModel.cs" />
<Compile Include="ViewModels\GitHubPane\NotAGitHubRepositoryViewModel.cs" />
<Compile Include="ViewModels\GitHubPane\NotAGitRepositoryViewModel.cs" />
<Compile Include="ViewModels\GitHubPane\PullRequestReviewSummaryViewModel.cs" />
<Compile Include="ViewModels\RepositoryFormViewModel.cs" />
<Compile Include="ViewModels\TeamExplorer\RepositoryPublishViewModel.cs" />
<Compile Include="Caches\CacheIndex.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.App/Models/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public BitmapSource Avatar
set { avatar = value; this.RaisePropertyChanged(); }
}

#region Equality things
#region Equality things
public void CopyFrom(IAccount other)
{
if (!Equals(other))
Expand Down
36 changes: 36 additions & 0 deletions src/GitHub.App/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/GitHub.App/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,16 @@
Please install Git for Windows from:
https://git-scm.com/download/win</value>
</data>
<data name="Approved" xml:space="preserve">
<value>Approved</value>
</data>
<data name="ChangesRequested" xml:space="preserve">
<value>Changes Requested</value>
</data>
<data name="Commented" xml:space="preserve">
<value>Commented</value>
</data>
<data name="InProgress" xml:space="preserve">
<value>InProgress</value>
</data>
</root>
30 changes: 30 additions & 0 deletions src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ public PullRequestDetailViewModelDesigner()
modelsDir.Files.Add(oldBranchModel);
gitHubDir.Directories.Add(modelsDir);

Reviews = new[]
{
new PullRequestReviewSummaryViewModel
{
Id = 2,
User = new AccountDesigner { Login = "grokys", IsUser = true },
State = PullRequestReviewState.Pending,
FileCommentCount = 0,
},
new PullRequestReviewSummaryViewModel
{
Id = 1,
User = new AccountDesigner { Login = "jcansdale", IsUser = true },
State = PullRequestReviewState.Approved,
FileCommentCount = 5,
},
new PullRequestReviewSummaryViewModel
{
Id = 2,
User = new AccountDesigner { Login = "shana", IsUser = true },
State = PullRequestReviewState.ChangesRequested,
FileCommentCount = 5,
},
new PullRequestReviewSummaryViewModel
{
},
};

Files = new PullRequestFilesViewModelDesigner();
}

Expand All @@ -81,6 +109,7 @@ public PullRequestDetailViewModelDesigner()
public bool IsCheckedOut { get; }
public bool IsFromFork { get; }
public string Body { get; }
public IReadOnlyList<IPullRequestReviewSummaryViewModel> Reviews { get; }
public IPullRequestFilesViewModel Files { get; set; }
public IPullRequestCheckoutState CheckoutState { get; set; }
public IPullRequestUpdateState UpdateState { get; set; }
Expand All @@ -92,6 +121,7 @@ public PullRequestDetailViewModelDesigner()
public ReactiveCommand<Unit> Pull { get; }
public ReactiveCommand<Unit> Push { get; }
public ReactiveCommand<object> OpenOnGitHub { get; }
public ReactiveCommand<object> ShowReview { get; }

public Task InitializeAsync(ILocalRepositoryModel localRepository, IConnection connection, string owner, string repo, int number) => Task.CompletedTask;

Expand Down
23 changes: 23 additions & 0 deletions src/GitHub.App/ViewModels/GitHubPane/PullRequestDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public sealed class PullRequestDetailViewModel : PanePageViewModelBase, IPullReq
string targetBranchDisplayName;
int commentCount;
string body;
IReadOnlyList<IPullRequestReviewSummaryViewModel> reviews;
IPullRequestCheckoutState checkoutState;
IPullRequestUpdateState updateState;
string operationError;
Expand Down Expand Up @@ -117,6 +118,7 @@ public PullRequestDetailViewModel(
SubscribeOperationError(SyncSubmodules);

OpenOnGitHub = ReactiveCommand.Create();
ShowReview = ReactiveCommand.Create().OnExecuteCompleted(DoShowReview);
}

/// <summary>
Expand Down Expand Up @@ -244,6 +246,15 @@ public string OperationError
private set { this.RaiseAndSetIfChanged(ref operationError, value); }
}

/// <summary>
/// Gets the latest pull request review for each user.
/// </summary>
public IReadOnlyList<IPullRequestReviewSummaryViewModel> Reviews
{
get { return reviews; }
private set { this.RaiseAndSetIfChanged(ref reviews, value); }
}

/// <summary>
/// Gets the pull request's changed files.
/// </summary>
Expand Down Expand Up @@ -283,6 +294,11 @@ public Uri WebUrl
/// </summary>
public ReactiveCommand<object> OpenOnGitHub { get; }

/// <summary>
/// Gets a command that navigates to a pull request review.
/// </summary>
public ReactiveCommand<object> ShowReview { get; }

/// <summary>
/// Initializes the view model.
/// </summary>
Expand Down Expand Up @@ -353,6 +369,8 @@ public async Task Load(IPullRequestModel pullRequest)
TargetBranchDisplayName = GetBranchDisplayName(IsFromFork, pullRequest.Base?.Label);
CommentCount = pullRequest.Comments.Count + pullRequest.ReviewComments.Count;
Body = !string.IsNullOrWhiteSpace(pullRequest.Body) ? pullRequest.Body : Resources.NoDescriptionProvidedMarkdown;
Reviews = PullRequestReviewSummaryViewModel.BuildByUser(Session.User, pullRequest).ToList();

await Files.InitializeAsync(Session);

var localBranches = await pullRequestsService.GetLocalBranches(LocalRepository, pullRequest).ToList();
Expand Down Expand Up @@ -616,6 +634,11 @@ async Task DoSyncSubmodules(object unused)
}
}

void DoShowReview(object item)
{
// TODO
}

class CheckoutCommandState : IPullRequestCheckoutState
{
public CheckoutCommandState(string caption, string disabledMessage)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GitHub.App;
using GitHub.Models;

namespace GitHub.ViewModels.GitHubPane
{
/// <summary>
/// Displays a short overview of a pull request review in the <see cref="PullRequestDetailViewModel"/>.
/// </summary>
public class PullRequestReviewSummaryViewModel : IPullRequestReviewSummaryViewModel
{
/// <inheritdoc/>
public long Id { get; set; }

/// <inheritdoc/>
public IAccount User { get; set; }

/// <inheritdoc/>
public PullRequestReviewState State { get; set; }

/// <inheritdoc/>
public string StateDisplay => ToString(State);

/// <inheritdoc/>
public int FileCommentCount { get; set; }

/// <summary>
/// Builds a collection of <see cref="PullRequestReviewSummaryViewModel"/>s by user.
/// </summary>
/// <param name="currentUser">The current user.</param>
/// <param name="pullRequest">The pull request model.</param>
/// <remarks>
/// This method builds a list similar to that found in the "Reviewers" section at the top-
/// right of the Pull Request page on GitHub.
/// </remarks>
public static IEnumerable<PullRequestReviewSummaryViewModel> BuildByUser(
IAccount currentUser,
IPullRequestModel pullRequest)
{
var existing = new Dictionary<string, PullRequestReviewSummaryViewModel>();

foreach (var review in pullRequest.Reviews.OrderBy(x => x.Id))
{
if (review.State == PullRequestReviewState.Pending && review.User.Login != currentUser.Login)
continue;

PullRequestReviewSummaryViewModel previous;
existing.TryGetValue(review.User.Login, out previous);

var previousPriority = ToPriority(previous);
var reviewPriority = ToPriority(review.State);

if (reviewPriority >= previousPriority)
{
var count = pullRequest.ReviewComments
.Where(x => x.PullRequestReviewId == review.Id)
.Count();
existing[review.User.Login] = new PullRequestReviewSummaryViewModel
{
Id = review.Id,
User = review.User,
State = review.State,
FileCommentCount = count
};
}
}

var result = existing.Values.OrderBy(x => x.User).AsEnumerable();

if (!result.Any(x => x.State == PullRequestReviewState.Pending))
{
var newReview = new PullRequestReviewSummaryViewModel
{
State = PullRequestReviewState.Pending,
User = currentUser,
};
result = result.Concat(new[] { newReview });
}

return result;
}

static int ToPriority(PullRequestReviewSummaryViewModel review)
{
return review != null ? ToPriority(review.State) : 0;
}

static int ToPriority(PullRequestReviewState state)
{
switch (state)
{
case PullRequestReviewState.Approved:
case PullRequestReviewState.ChangesRequested:
return 1;
case PullRequestReviewState.Pending:
return 2;
default:
return 0;
}
}

static string ToString(PullRequestReviewState state)
{
switch (state)
{
case PullRequestReviewState.Approved:
return Resources.Approved;
case PullRequestReviewState.ChangesRequested:
return Resources.ChangesRequested;
case PullRequestReviewState.Commented:
case PullRequestReviewState.Dismissed:
return Resources.Commented;
case PullRequestReviewState.Pending:
return Resources.InProgress;
default:
throw new NotSupportedException();
}
}
}
}
1 change: 1 addition & 0 deletions src/GitHub.Exports.Reactive/GitHub.Exports.Reactive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
<Compile Include="ViewModels\GitHubPane\IPanePageViewModel.cs" />
<Compile Include="ViewModels\GitHubPane\IPullRequestFilesViewModel.cs" />
<Compile Include="ViewModels\GitHubPane\IPullRequestListViewModel.cs" />
<Compile Include="ViewModels\GitHubPane\IPullRequestReviewSummaryViewModel.cs" />
<Compile Include="ViewModels\GitHubPane\ISearchablePageViewModel.cs" />
<Compile Include="ViewModels\GitHubPane\IPullRequestCreationViewModel.cs" />
<Compile Include="ViewModels\GitHubPane\IPullRequestDetailViewModel.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public interface IPullRequestDetailViewModel : IPanePageViewModel, IOpenInBrowse
/// </summary>
string Body { get; }

/// <summary>
/// Gets the latest pull request review for each user.
/// </summary>
IReadOnlyList<IPullRequestReviewSummaryViewModel> Reviews { get; }

/// <summary>
/// Gets the pull request's changed files.
/// </summary>
Expand Down Expand Up @@ -165,6 +170,11 @@ public interface IPullRequestDetailViewModel : IPanePageViewModel, IOpenInBrowse
/// </summary>
ReactiveCommand<object> OpenOnGitHub { get; }

/// <summary>
/// Gets a command that navigates to a pull request review.
/// </summary>
ReactiveCommand<object> ShowReview { get; }

/// <summary>
/// Initializes the view model.
/// </summary>
Expand Down
Loading