diff --git a/src/GitHub.App/SampleData/Documents/PullRequestPageViewModelDesigner.cs b/src/GitHub.App/SampleData/Documents/PullRequestPageViewModelDesigner.cs index c334e08489..82ecf90d70 100644 --- a/src/GitHub.App/SampleData/Documents/PullRequestPageViewModelDesigner.cs +++ b/src/GitHub.App/SampleData/Documents/PullRequestPageViewModelDesigner.cs @@ -59,13 +59,13 @@ Depends on #1993 new CommitListViewModel( new CommitSummaryViewModel(new CommitModel { - Author = new ActorModel { Login = "grokys" }, + Author = new CommitActorModel { User = new ActorModel{ Login = "grokys" }}, AbbreviatedOid = "c7c7d25", MessageHeadline = "Refactor comment view models." }), new CommitSummaryViewModel(new CommitModel { - Author = new ActorModel { Login = "shana" }, + Author = new CommitActorModel { User = new ActorModel{ Login = "shana" }}, AbbreviatedOid = "04e6a90", MessageHeadline = "Refactor comment view models.", })), diff --git a/src/GitHub.App/ViewModels/CommitActorViewModel.cs b/src/GitHub.App/ViewModels/CommitActorViewModel.cs new file mode 100644 index 0000000000..3f40c05089 --- /dev/null +++ b/src/GitHub.App/ViewModels/CommitActorViewModel.cs @@ -0,0 +1,19 @@ +using GitHub.Models; + +namespace GitHub.ViewModels +{ + public class CommitActorViewModel: ActorViewModel, ICommitActorViewModel + { + public CommitActorViewModel(CommitActorModel model) + :base(model.User) + { + Name = model.Name; + Email = model.Email; + HasLogin = model.User != null; + } + + public string Email { get; } + public string Name { get; } + public bool HasLogin { get; } + } +} \ No newline at end of file diff --git a/src/GitHub.App/ViewModels/Documents/CommitListViewModel.cs b/src/GitHub.App/ViewModels/Documents/CommitListViewModel.cs index a72006ffd3..982661a556 100644 --- a/src/GitHub.App/ViewModels/Documents/CommitListViewModel.cs +++ b/src/GitHub.App/ViewModels/Documents/CommitListViewModel.cs @@ -25,6 +25,7 @@ public CommitListViewModel(params ICommitSummaryViewModel[] commits) Commits = commits; Author = Commits[0].Author; + AuthorName = GetAuthorDisplayName(Commits[0].Author); AuthorCaption = BuildAuthorCaption(); } @@ -42,12 +43,16 @@ public CommitListViewModel(IEnumerable commits) } Author = Commits[0].Author; + AuthorName = GetAuthorDisplayName(Commits[0].Author); AuthorCaption = BuildAuthorCaption(); } /// - public IActorViewModel Author { get; } + public ICommitActorViewModel Author { get; } + /// + public string AuthorName { get; } + /// public string AuthorCaption { get; } @@ -58,7 +63,7 @@ string BuildAuthorCaption() { var result = new StringBuilder(); - if (Commits.Any(x => x.Author.Login != Author.Login)) + if (Commits.Any(x => GetAuthorDisplayName(x.Author) != AuthorName)) { result.Append(Resources.AndOthers); result.Append(' '); @@ -67,5 +72,10 @@ string BuildAuthorCaption() result.Append(Resources.AddedSomeCommits); return result.ToString(); } + + string GetAuthorDisplayName(ICommitActorViewModel commitActorViewModel) + { + return commitActorViewModel.HasLogin ? commitActorViewModel.Login : commitActorViewModel.Name; + } } } diff --git a/src/GitHub.App/ViewModels/Documents/CommitSummaryViewModel.cs b/src/GitHub.App/ViewModels/Documents/CommitSummaryViewModel.cs index dc105488ed..7cb9b10e0b 100644 --- a/src/GitHub.App/ViewModels/Documents/CommitSummaryViewModel.cs +++ b/src/GitHub.App/ViewModels/Documents/CommitSummaryViewModel.cs @@ -14,7 +14,7 @@ public class CommitSummaryViewModel : ViewModelBase, ICommitSummaryViewModel public CommitSummaryViewModel(CommitModel commit) { AbbreviatedOid = commit.AbbreviatedOid; - Author = new ActorViewModel(commit.Author); + Author = new CommitActorViewModel(commit.Author); Header = commit.MessageHeadline; Oid = commit.Oid; } @@ -23,7 +23,7 @@ public CommitSummaryViewModel(CommitModel commit) public string AbbreviatedOid { get; private set; } /// - public IActorViewModel Author { get; private set; } + public ICommitActorViewModel Author { get; private set; } /// public string Header { get; private set; } diff --git a/src/GitHub.Exports.Reactive/ViewModels/Documents/ICommitListViewModel.cs b/src/GitHub.Exports.Reactive/ViewModels/Documents/ICommitListViewModel.cs index 83dbdf4def..46ad9c13c6 100644 --- a/src/GitHub.Exports.Reactive/ViewModels/Documents/ICommitListViewModel.cs +++ b/src/GitHub.Exports.Reactive/ViewModels/Documents/ICommitListViewModel.cs @@ -11,7 +11,12 @@ public interface ICommitListViewModel : IViewModel /// /// Gets the first author of the commits in the list. /// - IActorViewModel Author { get; } + ICommitActorViewModel Author { get; } + + /// + /// Gets a string to display the author login or the author name. + /// + string AuthorName { get; } /// /// Gets a string to display next to the author in the view. diff --git a/src/GitHub.Exports.Reactive/ViewModels/Documents/ICommitSummaryViewModel.cs b/src/GitHub.Exports.Reactive/ViewModels/Documents/ICommitSummaryViewModel.cs index b6a645e558..49d046b503 100644 --- a/src/GitHub.Exports.Reactive/ViewModels/Documents/ICommitSummaryViewModel.cs +++ b/src/GitHub.Exports.Reactive/ViewModels/Documents/ICommitSummaryViewModel.cs @@ -13,7 +13,7 @@ public interface ICommitSummaryViewModel : IViewModel /// /// Gets the commit author. /// - IActorViewModel Author { get; } + ICommitActorViewModel Author { get; } /// /// Gets the commit message header. diff --git a/src/GitHub.Exports.Reactive/ViewModels/ICommitActorViewModel.cs b/src/GitHub.Exports.Reactive/ViewModels/ICommitActorViewModel.cs new file mode 100644 index 0000000000..a736aac349 --- /dev/null +++ b/src/GitHub.Exports.Reactive/ViewModels/ICommitActorViewModel.cs @@ -0,0 +1,9 @@ +namespace GitHub.ViewModels +{ + public interface ICommitActorViewModel : IActorViewModel + { + string Email { get; } + string Name { get; } + bool HasLogin { get; } + } +} \ No newline at end of file diff --git a/src/GitHub.Exports/Models/CommitActorModel.cs b/src/GitHub.Exports/Models/CommitActorModel.cs new file mode 100644 index 0000000000..02280bfbd1 --- /dev/null +++ b/src/GitHub.Exports/Models/CommitActorModel.cs @@ -0,0 +1,23 @@ +namespace GitHub.Models +{ + /// + /// Represents a commit actor (which may or may not have an associated User or Bot). + /// + public class CommitActorModel + { + /// + /// Gets or sets the actor user + /// + public ActorModel User { get; set; } + + /// + /// Gets or sets the actor name + /// + public string Name { get; set; } + + /// + /// Gets or sets the actor email + /// + public string Email { get; set; } + } +} \ No newline at end of file diff --git a/src/GitHub.Exports/Models/CommitModel.cs b/src/GitHub.Exports/Models/CommitModel.cs index 370c38cb1f..a0aaad8a83 100644 --- a/src/GitHub.Exports/Models/CommitModel.cs +++ b/src/GitHub.Exports/Models/CommitModel.cs @@ -10,7 +10,7 @@ public class CommitModel /// /// Gets or sets the author of the commit. /// - public ActorModel Author { get; set; } + public CommitActorModel Author { get; set; } /// /// Gets or sets the abbreviated git object ID for the commit. diff --git a/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs b/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs index 08e816830c..44b0126e36 100644 --- a/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs +++ b/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs @@ -365,11 +365,14 @@ public virtual async Task ReadPullRequestDetail(HostAddr when.Commit(commit => new CommitModel { AbbreviatedOid = commit.AbbreviatedOid, - // TODO: commit.Author.User can be null - Author = new ActorModel - { - Login = commit.Author.User.Login, - AvatarUrl = commit.Author.User.AvatarUrl(null), + Author = new CommitActorModel { + Name = commit.Author.Name, + Email = commit.Author.Email, + User = commit.Author.User != null ? new ActorModel + { + Login = commit.Author.User.Login, + AvatarUrl = commit.Author.User.AvatarUrl(null), + } : null }, MessageHeadline = commit.MessageHeadline, Oid = commit.Oid, diff --git a/src/GitHub.VisualStudio.UI/Views/Documents/CommitListView.xaml b/src/GitHub.VisualStudio.UI/Views/Documents/CommitListView.xaml index 3929fd36ef..f3491ca6e4 100644 --- a/src/GitHub.VisualStudio.UI/Views/Documents/CommitListView.xaml +++ b/src/GitHub.VisualStudio.UI/Views/Documents/CommitListView.xaml @@ -49,7 +49,7 @@ ViewModel="{Binding Author}"/> - +