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

Commit c0cb0c2

Browse files
Identifying what files are contained in the pull request
1 parent a6f8a46 commit c0cb0c2

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

src/GitHub.App/SampleData/PullRequestAnnotationItemViewModelDesigner.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Diagnostics.CodeAnalysis;
2+
using System.Reactive;
23
using GitHub.Models;
34
using GitHub.ViewModels.GitHubPane;
5+
using ReactiveUI;
46

57
namespace GitHub.SampleData
68
{
@@ -10,5 +12,7 @@ public sealed class PullRequestAnnotationItemViewModelDesigner : IPullRequestAnn
1012
public CheckRunAnnotationModel Annotation { get; set; }
1113
public bool IsExpanded { get; set; }
1214
public string LineDescription => $"{Annotation.StartLine}:{Annotation.EndLine}";
15+
public bool IsFileInPullRequest { get; }
16+
public ReactiveCommand<Unit, Unit> OpenAnnotation { get; }
1317
}
1418
}

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

Lines changed: 17 additions & 3 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;
@@ -14,17 +18,27 @@ public class PullRequestAnnotationItemViewModel : ViewModelBase, IPullRequestAnn
1418
/// Initializes the <see cref="PullRequestAnnotationItemViewModel"/>.
1519
/// </summary>
1620
/// <param name="annotation">The check run annotation model.</param>
17-
public PullRequestAnnotationItemViewModel(CheckRunAnnotationModel annotation)
21+
/// <param name="isFileInPullRequest">A flag that denotes if the annotation is part of the pull request's changes.</param>
22+
public PullRequestAnnotationItemViewModel(CheckRunAnnotationModel annotation, bool isFileInPullRequest)
1823
{
19-
this.Annotation = annotation;
24+
Annotation = annotation;
25+
IsFileInPullRequest = isFileInPullRequest;
26+
27+
OpenAnnotation = ReactiveCommand.Create(() => { });
2028
}
2129

30+
/// <inheritdoc />
31+
public bool IsFileInPullRequest { get; }
32+
2233
/// <inheritdoc />
2334
public CheckRunAnnotationModel Annotation { get; }
2435

2536
/// <inheritdoc />
2637
public string LineDescription => $"{Annotation.StartLine}:{Annotation.EndLine}";
2738

39+
/// <inheritdoc />
40+
public ReactiveCommand<Unit, Unit> OpenAnnotation { get; }
41+
2842
/// <inheritdoc />
2943
public bool IsExpanded
3044
{

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class PullRequestAnnotationsViewModel : PanePageViewModelBase, IPullReque
2020
{
2121
private readonly IPullRequestSessionManager sessionManager;
2222

23+
IPullRequestSession session;
2324
string title;
2425
string checkSuiteName;
2526
string checkRunName;
@@ -56,7 +57,7 @@ public async Task InitializeAsync(LocalRepositoryModel localRepository, IConnect
5657
RemoteRepositoryOwner = owner;
5758
PullRequestNumber = pullRequestNumber;
5859
CheckRunId = checkRunId;
59-
var session = await sessionManager.GetSession(owner, repo, pullRequestNumber);
60+
session = await sessionManager.GetSession(owner, repo, pullRequestNumber);
6061
Load(session.PullRequest);
6162
}
6263
finally
@@ -123,12 +124,18 @@ void Load(PullRequestDetailModel pullRequest)
123124
CheckSuiteName = checkSuiteRun.checkSuite.ApplicationName;
124125
CheckRunName = checkSuiteRun.checkRun.Name;
125126

126-
AnnotationsDictionary = checkSuiteRun.checkRun.Annotations
127-
.GroupBy(annotation => annotation.Path)
127+
var changedFiles = new HashSet<string>(session.PullRequest.ChangedFiles.Select(model => model.FileName));
128+
129+
var annotationsLookup = checkSuiteRun.checkRun.Annotations
130+
.ToLookup(annotation => annotation.Path);
131+
132+
AnnotationsDictionary = annotationsLookup
133+
.Select(models => models.Key)
134+
.OrderBy(s => s)
128135
.ToDictionary(
129-
grouping => grouping.Key,
130-
grouping => grouping
131-
.Select(annotation => new PullRequestAnnotationItemViewModel(annotation))
136+
path => path,
137+
path => annotationsLookup[path]
138+
.Select(annotation => new PullRequestAnnotationItemViewModel(annotation, changedFiles.Contains(path)))
132139
.Cast<IPullRequestAnnotationItemViewModel>()
133140
.ToArray()
134141
);
@@ -138,6 +145,5 @@ void Load(PullRequestDetailModel pullRequest)
138145
IsBusy = false;
139146
}
140147
}
141-
142148
}
143149
}

src/GitHub.Exports.Reactive/ViewModels/GitHubPane/IPullRequestAnnotationItemViewModel.cs

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

35
namespace GitHub.ViewModels.GitHubPane
46
{
@@ -21,5 +23,15 @@ public interface IPullRequestAnnotationItemViewModel
2123
/// Gets or sets a flag to control the expanded state.
2224
/// </summary>
2325
bool IsExpanded { get; set; }
26+
27+
/// <summary>
28+
/// Gets a flag which indicates this annotation item is from a file changed in this pull request.
29+
/// </summary>
30+
bool IsFileInPullRequest { get; }
31+
32+
/// <summary>
33+
/// Gets a command which opens the annotation in the diff view.
34+
/// </summary>
35+
ReactiveCommand<Unit, Unit> OpenAnnotation { get; }
2436
}
2537
}

0 commit comments

Comments
 (0)