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

Commit 63cf8e0

Browse files
Merge pull request #2255 from michaelbayles/fix-null-commit-author
Fix null commit author
2 parents cb13c51 + 548757c commit 63cf8e0

File tree

11 files changed

+84
-15
lines changed

11 files changed

+84
-15
lines changed

src/GitHub.App/SampleData/Documents/PullRequestPageViewModelDesigner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ Depends on #1993
5959
new CommitListViewModel(
6060
new CommitSummaryViewModel(new CommitModel
6161
{
62-
Author = new ActorModel { Login = "grokys" },
62+
Author = new CommitActorModel { User = new ActorModel{ Login = "grokys" }},
6363
AbbreviatedOid = "c7c7d25",
6464
MessageHeadline = "Refactor comment view models."
6565
}),
6666
new CommitSummaryViewModel(new CommitModel
6767
{
68-
Author = new ActorModel { Login = "shana" },
68+
Author = new CommitActorModel { User = new ActorModel{ Login = "shana" }},
6969
AbbreviatedOid = "04e6a90",
7070
MessageHeadline = "Refactor comment view models.",
7171
})),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using GitHub.Models;
2+
3+
namespace GitHub.ViewModels
4+
{
5+
public class CommitActorViewModel: ActorViewModel, ICommitActorViewModel
6+
{
7+
public CommitActorViewModel(CommitActorModel model)
8+
:base(model.User)
9+
{
10+
Name = model.Name;
11+
Email = model.Email;
12+
HasLogin = model.User != null;
13+
}
14+
15+
public string Email { get; }
16+
public string Name { get; }
17+
public bool HasLogin { get; }
18+
}
19+
}

src/GitHub.App/ViewModels/Documents/CommitListViewModel.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public CommitListViewModel(params ICommitSummaryViewModel[] commits)
2525

2626
Commits = commits;
2727
Author = Commits[0].Author;
28+
AuthorName = GetAuthorDisplayName(Commits[0].Author);
2829
AuthorCaption = BuildAuthorCaption();
2930
}
3031

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

4445
Author = Commits[0].Author;
46+
AuthorName = GetAuthorDisplayName(Commits[0].Author);
4547
AuthorCaption = BuildAuthorCaption();
4648
}
4749

4850
/// <inheritdoc/>
49-
public IActorViewModel Author { get; }
51+
public ICommitActorViewModel Author { get; }
5052

53+
/// <inheritdoc/>
54+
public string AuthorName { get; }
55+
5156
/// <inheritdoc/>
5257
public string AuthorCaption { get; }
5358

@@ -58,7 +63,7 @@ string BuildAuthorCaption()
5863
{
5964
var result = new StringBuilder();
6065

61-
if (Commits.Any(x => x.Author.Login != Author.Login))
66+
if (Commits.Any(x => GetAuthorDisplayName(x.Author) != AuthorName))
6267
{
6368
result.Append(Resources.AndOthers);
6469
result.Append(' ');
@@ -67,5 +72,10 @@ string BuildAuthorCaption()
6772
result.Append(Resources.AddedSomeCommits);
6873
return result.ToString();
6974
}
75+
76+
string GetAuthorDisplayName(ICommitActorViewModel commitActorViewModel)
77+
{
78+
return commitActorViewModel.HasLogin ? commitActorViewModel.Login : commitActorViewModel.Name;
79+
}
7080
}
7181
}

src/GitHub.App/ViewModels/Documents/CommitSummaryViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class CommitSummaryViewModel : ViewModelBase, ICommitSummaryViewModel
1414
public CommitSummaryViewModel(CommitModel commit)
1515
{
1616
AbbreviatedOid = commit.AbbreviatedOid;
17-
Author = new ActorViewModel(commit.Author);
17+
Author = new CommitActorViewModel(commit.Author);
1818
Header = commit.MessageHeadline;
1919
Oid = commit.Oid;
2020
}
@@ -23,7 +23,7 @@ public CommitSummaryViewModel(CommitModel commit)
2323
public string AbbreviatedOid { get; private set; }
2424

2525
/// <inheritdoc/>
26-
public IActorViewModel Author { get; private set; }
26+
public ICommitActorViewModel Author { get; private set; }
2727

2828
/// <inheritdoc/>
2929
public string Header { get; private set; }

src/GitHub.Exports.Reactive/ViewModels/Documents/ICommitListViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ public interface ICommitListViewModel : IViewModel
1111
/// <summary>
1212
/// Gets the first author of the commits in the list.
1313
/// </summary>
14-
IActorViewModel Author { get; }
14+
ICommitActorViewModel Author { get; }
15+
16+
/// <summary>
17+
/// Gets a string to display the author login or the author name.
18+
/// </summary>
19+
string AuthorName { get; }
1520

1621
/// <summary>
1722
/// Gets a string to display next to the author in the view.

src/GitHub.Exports.Reactive/ViewModels/Documents/ICommitSummaryViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface ICommitSummaryViewModel : IViewModel
1313
/// <summary>
1414
/// Gets the commit author.
1515
/// </summary>
16-
IActorViewModel Author { get; }
16+
ICommitActorViewModel Author { get; }
1717

1818
/// <summary>
1919
/// Gets the commit message header.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace GitHub.ViewModels
2+
{
3+
public interface ICommitActorViewModel : IActorViewModel
4+
{
5+
string Email { get; }
6+
string Name { get; }
7+
bool HasLogin { get; }
8+
}
9+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace GitHub.Models
2+
{
3+
/// <summary>
4+
/// Represents a commit actor (which may or may not have an associated User or Bot).
5+
/// </summary>
6+
public class CommitActorModel
7+
{
8+
/// <summary>
9+
/// Gets or sets the actor user
10+
/// </summary>
11+
public ActorModel User { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets the actor name
15+
/// </summary>
16+
public string Name { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the actor email
20+
/// </summary>
21+
public string Email { get; set; }
22+
}
23+
}

src/GitHub.Exports/Models/CommitModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class CommitModel
1010
/// <summary>
1111
/// Gets or sets the author of the commit.
1212
/// </summary>
13-
public ActorModel Author { get; set; }
13+
public CommitActorModel Author { get; set; }
1414

1515
/// <summary>
1616
/// Gets or sets the abbreviated git object ID for the commit.

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,14 @@ public virtual async Task<PullRequestDetailModel> ReadPullRequestDetail(HostAddr
365365
when.Commit(commit => new CommitModel
366366
{
367367
AbbreviatedOid = commit.AbbreviatedOid,
368-
// TODO: commit.Author.User can be null
369-
Author = new ActorModel
370-
{
371-
Login = commit.Author.User.Login,
372-
AvatarUrl = commit.Author.User.AvatarUrl(null),
368+
Author = new CommitActorModel {
369+
Name = commit.Author.Name,
370+
Email = commit.Author.Email,
371+
User = commit.Author.User != null ? new ActorModel
372+
{
373+
Login = commit.Author.User.Login,
374+
AvatarUrl = commit.Author.User.AvatarUrl(null),
375+
} : null
373376
},
374377
MessageHeadline = commit.MessageHeadline,
375378
Oid = commit.Oid,

src/GitHub.VisualStudio.UI/Views/Documents/CommitListView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
ViewModel="{Binding Author}"/>
5050

5151
<TextBlock Foreground="{DynamicResource VsBrush.WindowText}" VerticalAlignment="Center">
52-
<Run FontWeight="SemiBold" Text="{Binding Author.Login, Mode=OneWay}" />
52+
<Run FontWeight="SemiBold" Text="{Binding AuthorName, Mode=OneWay}" />
5353
<Run Text="{Binding AuthorCaption, Mode=OneWay}" />
5454
</TextBlock>
5555
</StackPanel>

0 commit comments

Comments
 (0)