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
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
})),
Expand Down
19 changes: 19 additions & 0 deletions src/GitHub.App/ViewModels/CommitActorViewModel.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
14 changes: 12 additions & 2 deletions src/GitHub.App/ViewModels/Documents/CommitListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public CommitListViewModel(params ICommitSummaryViewModel[] commits)

Commits = commits;
Author = Commits[0].Author;
AuthorName = GetAuthorDisplayName(Commits[0].Author);
AuthorCaption = BuildAuthorCaption();
}

Expand All @@ -42,12 +43,16 @@ public CommitListViewModel(IEnumerable<ICommitSummaryViewModel> commits)
}

Author = Commits[0].Author;
AuthorName = GetAuthorDisplayName(Commits[0].Author);
AuthorCaption = BuildAuthorCaption();
}

/// <inheritdoc/>
public IActorViewModel Author { get; }
public ICommitActorViewModel Author { get; }

/// <inheritdoc/>
public string AuthorName { get; }

/// <inheritdoc/>
public string AuthorCaption { get; }

Expand All @@ -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(' ');
Expand All @@ -67,5 +72,10 @@ string BuildAuthorCaption()
result.Append(Resources.AddedSomeCommits);
return result.ToString();
}

string GetAuthorDisplayName(ICommitActorViewModel commitActorViewModel)
{
return commitActorViewModel.HasLogin ? commitActorViewModel.Login : commitActorViewModel.Name;
}
}
}
4 changes: 2 additions & 2 deletions src/GitHub.App/ViewModels/Documents/CommitSummaryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -23,7 +23,7 @@ public CommitSummaryViewModel(CommitModel commit)
public string AbbreviatedOid { get; private set; }

/// <inheritdoc/>
public IActorViewModel Author { get; private set; }
public ICommitActorViewModel Author { get; private set; }

/// <inheritdoc/>
public string Header { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ public interface ICommitListViewModel : IViewModel
/// <summary>
/// Gets the first author of the commits in the list.
/// </summary>
IActorViewModel Author { get; }
ICommitActorViewModel Author { get; }

/// <summary>
/// Gets a string to display the author login or the author name.
/// </summary>
string AuthorName { get; }

/// <summary>
/// Gets a string to display next to the author in the view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ICommitSummaryViewModel : IViewModel
/// <summary>
/// Gets the commit author.
/// </summary>
IActorViewModel Author { get; }
ICommitActorViewModel Author { get; }

/// <summary>
/// Gets the commit message header.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GitHub.ViewModels
{
public interface ICommitActorViewModel : IActorViewModel
{
string Email { get; }
string Name { get; }
bool HasLogin { get; }
}
}
23 changes: 23 additions & 0 deletions src/GitHub.Exports/Models/CommitActorModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace GitHub.Models
{
/// <summary>
/// Represents a commit actor (which may or may not have an associated User or Bot).
/// </summary>
public class CommitActorModel
{
/// <summary>
/// Gets or sets the actor user
/// </summary>
public ActorModel User { get; set; }

/// <summary>
/// Gets or sets the actor name
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets or sets the actor email
/// </summary>
public string Email { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/GitHub.Exports/Models/CommitModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class CommitModel
/// <summary>
/// Gets or sets the author of the commit.
/// </summary>
public ActorModel Author { get; set; }
public CommitActorModel Author { get; set; }

/// <summary>
/// Gets or sets the abbreviated git object ID for the commit.
Expand Down
13 changes: 8 additions & 5 deletions src/GitHub.InlineReviews/Services/PullRequestSessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,14 @@ public virtual async Task<PullRequestDetailModel> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
ViewModel="{Binding Author}"/>

<TextBlock Foreground="{DynamicResource VsBrush.WindowText}" VerticalAlignment="Center">
<Run FontWeight="SemiBold" Text="{Binding Author.Login, Mode=OneWay}" />
<Run FontWeight="SemiBold" Text="{Binding AuthorName, Mode=OneWay}" />
<Run Text="{Binding AuthorCaption, Mode=OneWay}" />
</TextBlock>
</StackPanel>
Expand Down