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

Commit ee78503

Browse files
authored
Merge branch 'master' into fixes/1035-pr-list-tooltip
2 parents 8e3ae6a + 0e8ae75 commit ee78503

14 files changed

+115
-12
lines changed

src/GitHub.Exports/Models/DiffUtilities.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ public static DiffLine Match(IEnumerable<DiffChunk> diff, IList<DiffLine> target
9696
{
9797
if (source.Lines[i].Content == target[j].Content)
9898
{
99-
if (++j == target.Count) return source.Lines[i + j - 1];
99+
if (++j == target.Count || i == 0)
100+
{
101+
return source.Lines[i + j - 1];
102+
}
100103
}
101104
else
102105
{

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@
196196
<Project>{6AFE2E2D-6DB0-4430-A2EA-F5F5388D2F78}</Project>
197197
<Name>GitHub.Extensions</Name>
198198
</ProjectReference>
199+
<ProjectReference Include="..\GitHub.UI.Reactive\GitHub.UI.Reactive.csproj">
200+
<Project>{158b05e8-fdbc-4d71-b871-c96e28d5adf5}</Project>
201+
<Name>GitHub.UI.Reactive</Name>
202+
</ProjectReference>
199203
<ProjectReference Include="..\GitHub.UI\GitHub.UI.csproj">
200204
<Project>{346384dd-2445-4a28-af22-b45f3957bd89}</Project>
201205
<Name>GitHub.UI</Name>

src/GitHub.InlineReviews/SampleData/CommentThreadViewModelDesigner.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ class CommentThreadViewModelDesigner : ICommentThreadViewModel
1616
= new AccountDesigner { Login = "shana", IsUser = true };
1717

1818
public ReactiveCommand<ICommentModel> PostComment { get; }
19+
20+
public Uri GetCommentUrl(int id)
21+
{
22+
throw new NotImplementedException();
23+
}
1924
}
2025
}

src/GitHub.InlineReviews/SampleData/CommentViewModelDesigner.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,34 @@
33
using GitHub.InlineReviews.ViewModels;
44
using GitHub.Models;
55
using GitHub.SampleData;
6+
using GitHub.UI;
67
using ReactiveUI;
78

89
namespace GitHub.InlineReviews.SampleData
910
{
10-
class CommentViewModelDesigner : ICommentViewModel
11+
class CommentViewModelDesigner : ReactiveObject, ICommentViewModel
1112
{
1213
public CommentViewModelDesigner()
1314
{
1415
User = new AccountDesigner { Login = "shana", IsUser = true };
1516
}
1617

18+
public void Initialize(ViewWithData data)
19+
{
20+
}
21+
1722
public int Id { get; set; }
1823
public string Body { get; set; }
1924
public string ErrorMessage { get; set; }
2025
public CommentEditState EditState { get; set; }
2126
public bool IsReadOnly { get; set; }
27+
public ICommentThreadViewModel Thread { get; }
2228
public DateTimeOffset UpdatedAt => DateTime.Now.Subtract(TimeSpan.FromDays(3));
2329
public IAccount User { get; set; }
2430

2531
public ReactiveCommand<object> BeginEdit { get; }
2632
public ReactiveCommand<object> CancelEdit { get; }
2733
public ReactiveCommand<Unit> CommitEdit { get; }
34+
public ReactiveCommand<object> OpenOnGitHub { get; }
2835
}
2936
}

src/GitHub.InlineReviews/ViewModels/CommentThreadViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public void Dispose()
5454
GC.SuppressFinalize(this);
5555
}
5656

57+
/// <inheritdoc/>
58+
public abstract Uri GetCommentUrl(int id);
59+
5760
protected virtual void Dispose(bool disposing)
5861
{
5962
if (disposing)

src/GitHub.InlineReviews/ViewModels/CommentViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using GitHub.Extensions;
77
using GitHub.Models;
8+
using GitHub.UI;
89
using ReactiveUI;
910

1011
namespace GitHub.InlineReviews.ViewModels
@@ -73,6 +74,8 @@ public CommentViewModel(
7374
CancelEdit = ReactiveCommand.Create(CommitEdit.IsExecuting.Select(x => !x));
7475
CancelEdit.Subscribe(DoCancelEdit);
7576
AddErrorHandler(CancelEdit);
77+
78+
OpenOnGitHub = ReactiveCommand.Create(this.WhenAnyValue(x => x.Id, x => x != 0));
7679
}
7780

7881
/// <summary>
@@ -89,6 +92,11 @@ public CommentViewModel(
8992
{
9093
}
9194

95+
public void Initialize(ViewWithData data)
96+
{
97+
// Nothing to do here: initialized in constructor.
98+
}
99+
92100
/// <summary>
93101
/// Creates a placeholder comment which can be used to add a new comment to a thread.
94102
/// </summary>
@@ -208,5 +216,8 @@ public DateTimeOffset UpdatedAt
208216

209217
/// <inheritdoc/>
210218
public ReactiveCommand<Unit> CommitEdit { get; }
219+
220+
/// <inheritdoc/>
221+
public ReactiveCommand<object> OpenOnGitHub { get; }
211222
}
212223
}

src/GitHub.InlineReviews/ViewModels/ICommentThreadViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ namespace GitHub.InlineReviews.ViewModels
1010
/// </summary>
1111
public interface ICommentThreadViewModel
1212
{
13+
/// <summary>
14+
/// Gets the browser URI for a comment in the thread.
15+
/// </summary>
16+
/// <param name="id">The ID of the comment.</param>
17+
/// <returns>The URI.</returns>
18+
Uri GetCommentUrl(int id);
19+
1320
/// <summary>
1421
/// Gets the comments in the thread.
1522
/// </summary>

src/GitHub.InlineReviews/ViewModels/ICommentViewModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Reactive;
33
using GitHub.Models;
4+
using GitHub.ViewModels;
45
using ReactiveUI;
56

67
namespace GitHub.InlineReviews.ViewModels
@@ -12,7 +13,7 @@ public enum CommentEditState
1213
Placeholder,
1314
}
1415

15-
public interface ICommentViewModel
16+
public interface ICommentViewModel : IViewModel
1617
{
1718
/// <summary>
1819
/// Gets the ID of the comment.
@@ -49,6 +50,11 @@ public interface ICommentViewModel
4950
/// </summary>
5051
IAccount User { get; }
5152

53+
/// <summary>
54+
/// Gets the thread that the comment is a part of.
55+
/// </summary>
56+
ICommentThreadViewModel Thread { get; }
57+
5258
/// <summary>
5359
/// Gets a command which will begin editing of the comment.
5460
/// </summary>
@@ -63,5 +69,10 @@ public interface ICommentViewModel
6369
/// Gets a command which will commit edits to the comment.
6470
/// </summary>
6571
ReactiveCommand<Unit> CommitEdit { get; }
72+
73+
/// <summary>
74+
/// Gets a command to open the comment in a browser.
75+
/// </summary>
76+
ReactiveCommand<object> OpenOnGitHub { get; }
6677
}
6778
}

src/GitHub.InlineReviews/ViewModels/InlineCommentThreadViewModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Reactive.Linq;
45
using System.Threading.Tasks;
56
using GitHub.Api;
@@ -34,6 +35,7 @@ public InlineCommentThreadViewModel(
3435

3536
this.apiClient = apiClient;
3637
Session = session;
38+
3739
PostComment = ReactiveCommand.CreateAsyncTask(
3840
Observable.Return(true),
3941
DoPostComment);
@@ -51,6 +53,17 @@ public InlineCommentThreadViewModel(
5153
/// </summary>
5254
public IPullRequestSession Session { get; }
5355

56+
/// <inheritdoc/>
57+
public override Uri GetCommentUrl(int id)
58+
{
59+
return new Uri(string.Format(
60+
CultureInfo.InvariantCulture,
61+
"{0}/pull/{1}#discussion_r{2}",
62+
Session.Repository.CloneUrl.ToRepositoryUrl(),
63+
Session.PullRequest.Number,
64+
id));
65+
}
66+
5467
async Task<ICommentModel> DoPostComment(object parameter)
5568
{
5669
Guard.ArgumentNotNull(parameter, nameof(parameter));

src/GitHub.InlineReviews/ViewModels/IssueCommentThreadViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public IssueCommentThreadViewModel(
1717
Number = number;
1818
}
1919

20+
/// <inheritdoc/>
21+
public override Uri GetCommentUrl(int id)
22+
{
23+
throw new NotImplementedException();
24+
}
25+
2026
public IRepositoryModel Repository { get; }
2127
public int Number { get; }
2228
}

0 commit comments

Comments
 (0)