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

Commit 18dc78d

Browse files
Link to inline review from file
1 parent 214e1a5 commit 18dc78d

File tree

13 files changed

+128
-57
lines changed

13 files changed

+128
-57
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Reactive;
3+
using GitHub.Models;
4+
using GitHub.ViewModels.GitHubPane;
5+
using ReactiveUI;
6+
7+
namespace GitHub.SampleData
8+
{
9+
[ExcludeFromCodeCoverage]
10+
public sealed class PullRequestAnnotationItemViewModelDesigner : IPullRequestAnnotationItemViewModel
11+
{
12+
public CheckRunAnnotationModel Annotation { get; set; }
13+
public bool IsExpanded { get; set; }
14+
public string LineDescription => $"{Annotation.StartLine}:{Annotation.EndLine}";
15+
public bool IsFileInPullRequest { get; set; }
16+
public ReactiveCommand<Unit> OpenAnnotation { get; }
17+
}
18+
}

src/GitHub.App/SampleData/PullRequestAnnotationsViewModelDesigner.cs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,42 @@ public sealed class PullRequestAnnotationsViewModelDesigner : PanePageViewModelB
2020
public string CheckRunName { get; } = "Psuedo Check Run";
2121
public IReadOnlyList<IPullRequestAnnotationItemViewModel> Annotations { get; } = new[]
2222
{
23-
new PullRequestAnnotationItemViewModel(new CheckRunAnnotationModel
24-
{
25-
AnnotationLevel = CheckAnnotationLevel.Notice,
26-
StartLine = 3,
27-
EndLine = 4,
28-
Filename = "asdf/asdf.cs",
29-
Message = "; is expected",
30-
Title = "CS 12345"
31-
}),
32-
new PullRequestAnnotationItemViewModel(new CheckRunAnnotationModel
33-
{
34-
AnnotationLevel = CheckAnnotationLevel.Warning,
35-
StartLine = 3,
36-
EndLine = 4,
37-
Filename = "asdf/asdf.cs",
38-
Message = "; is expected",
39-
Title = "CS 12345"
40-
}),
41-
new PullRequestAnnotationItemViewModel(new CheckRunAnnotationModel
42-
{
43-
AnnotationLevel = CheckAnnotationLevel.Failure,
44-
StartLine = 3,
45-
EndLine = 4,
46-
Filename = "blah.cs",
47-
Message = "; is expected",
48-
Title = "CS 12345"
49-
})
23+
new PullRequestAnnotationItemViewModelDesigner{
24+
Annotation = new CheckRunAnnotationModel
25+
{
26+
AnnotationLevel = CheckAnnotationLevel.Notice,
27+
StartLine = 3,
28+
EndLine = 4,
29+
Path = "asdf/asdf.cs",
30+
Message = "; is expected",
31+
Title = "CS 12345"
32+
},
33+
IsExpanded = true,
34+
IsFileInPullRequest = true
35+
},
36+
new PullRequestAnnotationItemViewModelDesigner{
37+
Annotation = new CheckRunAnnotationModel
38+
{
39+
AnnotationLevel = CheckAnnotationLevel.Warning,
40+
StartLine = 3,
41+
EndLine = 4,
42+
Path = "asdf/asdf.cs",
43+
Message = "; is expected",
44+
Title = "CS 12345"
45+
},
46+
IsExpanded = true
47+
},
48+
new PullRequestAnnotationItemViewModelDesigner{
49+
Annotation = new CheckRunAnnotationModel
50+
{
51+
AnnotationLevel = CheckAnnotationLevel.Failure,
52+
StartLine = 3,
53+
EndLine = 4,
54+
Path = "blah.cs",
55+
Message = "; is expected",
56+
Title = "CS 12345"
57+
}
58+
}
5059
};
5160

5261
public Task InitializeAsync(ILocalRepositoryModel localRepository, IConnection connection, string owner, string repo,

src/GitHub.App/ViewModels/GitHubPane/PullRequestAnnotationItemViewModel.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using GitHub.Models;
1+
using System.Linq;
2+
using System.Reactive;
3+
using System.Reactive.Linq;
4+
using GitHub.Models;
5+
using GitHub.Services;
26
using GitHub.ViewModels;
37
using GitHub.ViewModels.GitHubPane;
48
using ReactiveUI;
@@ -7,16 +11,40 @@ namespace GitHub.App.ViewModels.GitHubPane
711
{
812
public class PullRequestAnnotationItemViewModel : ViewModelBase, IPullRequestAnnotationItemViewModel
913
{
14+
readonly CheckSuiteModel checkSuite;
15+
readonly CheckRunModel checkRun;
16+
readonly IPullRequestSession session;
17+
readonly IPullRequestEditorService editorService;
18+
1019
bool isExpanded;
1120

12-
public PullRequestAnnotationItemViewModel(CheckRunAnnotationModel model)
21+
public PullRequestAnnotationItemViewModel(CheckSuiteModel checkSuite,
22+
CheckRunModel checkRun,
23+
CheckRunAnnotationModel annotation,
24+
IPullRequestSession session,
25+
IPullRequestEditorService editorService)
1326
{
14-
this.Model = model;
27+
this.checkSuite = checkSuite;
28+
this.checkRun = checkRun;
29+
this.session = session;
30+
this.editorService = editorService;
31+
this.Annotation = annotation;
32+
33+
IsFileInPullRequest = session.PullRequest.ChangedFiles.Any(model => model.FileName == annotation.Path);
34+
35+
OpenAnnotation = ReactiveCommand.CreateAsyncTask(Observable.Return(IsFileInPullRequest), async x =>
36+
{
37+
await editorService.OpenDiff(session, annotation.Path, checkSuite.HeadSha, annotation.EndLine - 1);
38+
});
1539
}
1640

17-
public CheckRunAnnotationModel Model { get; }
41+
public bool IsFileInPullRequest { get; }
42+
43+
public CheckRunAnnotationModel Annotation { get; }
44+
45+
public string LineDescription => $"{Annotation.StartLine}:{Annotation.EndLine}";
1846

19-
public string LineDescription => $"{Model.StartLine}:{Model.EndLine}";
47+
public ReactiveCommand<Unit> OpenAnnotation { get; }
2048

2149
public bool IsExpanded
2250
{

src/GitHub.App/ViewModels/GitHubPane/PullRequestAnnotationsViewModel.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ namespace GitHub.App.ViewModels.GitHubPane
1414
[PartCreationPolicy(CreationPolicy.NonShared)]
1515
public class PullRequestAnnotationsViewModel : PanePageViewModelBase, IPullRequestAnnotationsViewModel
1616
{
17-
private readonly IPullRequestSessionManager sessionManager;
17+
readonly IPullRequestSessionManager sessionManager;
18+
readonly IPullRequestEditorService pullRequestEditorService;
1819

1920
IPullRequestSession session;
2021
string title;
2122
string checkRunName;
2223
IReadOnlyList<IPullRequestAnnotationItemViewModel> annotations;
2324

2425
[ImportingConstructor]
25-
public PullRequestAnnotationsViewModel(IPullRequestSessionManager sessionManager)
26+
public PullRequestAnnotationsViewModel(IPullRequestSessionManager sessionManager, IPullRequestEditorService pullRequestEditorService)
2627
{
2728
this.sessionManager = sessionManager;
29+
this.pullRequestEditorService = pullRequestEditorService;
2830
NavigateToPullRequest = ReactiveCommand.Create().OnExecuteCompleted(_ =>
2931
NavigateTo(FormattableString.Invariant($"{LocalRepository.Owner}/{LocalRepository.Name}/pull/{PullRequestNumber}")));
3032
}
@@ -93,12 +95,12 @@ async Task Load(PullRequestDetailModel pullRequest)
9395
PullRequestTitle = pullRequest.Title;
9496

9597
var checkRunModel = pullRequest
96-
.CheckSuites.SelectMany(model => model.CheckRuns)
97-
.First(model => model.DatabaseId == CheckRunId);
98+
.CheckSuites.SelectMany(checkSuite => checkSuite.CheckRuns.Select(checkRun => new {checkSuite, checkRun}))
99+
.First(model => model.checkRun.DatabaseId == CheckRunId);
98100

99-
CheckRunName = checkRunModel.Name;
100-
Annotations = checkRunModel.Annotations
101-
.Select(model => new PullRequestAnnotationItemViewModel(model))
101+
CheckRunName = checkRunModel.checkRun.Name;
102+
Annotations = checkRunModel.checkRun.Annotations
103+
.Select(annotation => new PullRequestAnnotationItemViewModel(checkRunModel.checkSuite, checkRunModel.checkRun, annotation, session, pullRequestEditorService))
102104
.ToArray();
103105
}
104106
finally

src/GitHub.App/ViewModels/GitHubPane/PullRequestDetailViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ public Uri WebUrl
317317
/// </summary>
318318
public ReactiveCommand<object> ShowReview { get; }
319319

320+
/// <summary>
321+
/// Gets a command that navigates to a pull request annotations.
322+
/// </summary>
320323
public ReactiveCommand<object> ShowAnnotations { get; }
321324

322325
public IReadOnlyList<IPullRequestCheckViewModel> Checks

src/GitHub.Exports.Reactive/Models/InlineAnnotationModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public InlineAnnotationModel(CheckSuiteModel checkSuite, CheckRunModel checkRun,
2020
this.annotation = annotation;
2121
}
2222

23-
public string FileName => annotation.Filename;
23+
public string FileName => annotation.Path;
2424

2525
public int StartLine => annotation.StartLine;
2626

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
using GitHub.Models;
1+
using System.Reactive;
2+
using GitHub.Models;
3+
using ReactiveUI;
24

35
namespace GitHub.ViewModels.GitHubPane
46
{
57
public interface IPullRequestAnnotationItemViewModel
68
{
7-
CheckRunAnnotationModel Model { get; }
9+
CheckRunAnnotationModel Annotation { get; }
810
bool IsExpanded { get; set; }
911
string LineDescription { get; }
12+
bool IsFileInPullRequest { get; }
13+
ReactiveCommand<Unit> OpenAnnotation { get; }
1014
}
1115
}

src/GitHub.Exports/Models/AnnotationModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class CheckRunAnnotationModel
1818
/// <summary>
1919
/// The path that this annotation was made on.
2020
/// </summary>
21-
public string Filename { get; set; }
21+
public string Path { get; set; }
2222

2323
/// <summary>
2424
/// The annotation's message.

src/GitHub.InlineReviews/Commands/NextInlineReviewCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public override Task Execute(InlineReviewNavigationParams parameter)
5353
if (tags.Count > 0)
5454
{
5555
var cursorPoint = GetCursorPoint(textViews[0], parameter);
56-
var next = tags.FirstOrDefault(x => x.Point > cursorPoint) ?? tags.First();
56+
var next = tags.FirstOrDefault(x => x.Point >= cursorPoint) ?? tags.First();
5757
ShowPeekComments(parameter, next.TextView, next.Tag, textViews);
5858
}
5959

src/GitHub.InlineReviews/SampleData/InlineAnnotationViewModelDesigner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public InlineAnnotationViewModelDesigner()
1111
var checkRunAnnotationModel = new CheckRunAnnotationModel
1212
{
1313
AnnotationLevel = CheckAnnotationLevel.Failure,
14-
Filename = "SomeFile.cs",
14+
Path = "SomeFile.cs",
1515
EndLine = 12,
1616
StartLine = 12,
1717
Message = "Some Error Message",

0 commit comments

Comments
 (0)