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

Commit 24a501d

Browse files
Merge branch 'features/check-suite-annotations-inline' into donokuda/update-check-icon
# Conflicts: # src/GitHub.VisualStudio.UI/Views/GitHubPane/PullRequestCheckView.xaml
2 parents 766cae5 + 04e6fc7 commit 24a501d

File tree

45 files changed

+954
-256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+954
-256
lines changed

src/GitHub.App/SampleData/CommentThreadViewModelDesigner.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System.Diagnostics.CodeAnalysis;
1+
using System.Collections.Generic;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Threading.Tasks;
4+
using GitHub.Models;
35
using GitHub.ViewModels;
46
using ReactiveUI;
57

@@ -8,9 +10,73 @@ namespace GitHub.SampleData
810
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
911
public class CommentThreadViewModelDesigner : ViewModelBase, ICommentThreadViewModel
1012
{
13+
public CommentThreadViewModelDesigner()
14+
{
15+
16+
var checkRunAnnotationModel1 = new CheckRunAnnotationModel
17+
{
18+
AnnotationLevel = CheckAnnotationLevel.Failure,
19+
Path = "SomeFile.cs",
20+
EndLine = 12,
21+
StartLine = 12,
22+
Message = "CS12345: ; expected",
23+
Title = "CS12345"
24+
};
25+
26+
var checkRunAnnotationModel2 = new CheckRunAnnotationModel
27+
{
28+
AnnotationLevel = CheckAnnotationLevel.Warning,
29+
Path = "SomeFile.cs",
30+
EndLine = 12,
31+
StartLine = 12,
32+
Message = "CS12345: ; expected",
33+
Title = "CS12345"
34+
};
35+
36+
var checkRunAnnotationModel3 = new CheckRunAnnotationModel
37+
{
38+
AnnotationLevel = CheckAnnotationLevel.Notice,
39+
Path = "SomeFile.cs",
40+
EndLine = 12,
41+
StartLine = 12,
42+
Message = "CS12345: ; expected",
43+
Title = "CS12345"
44+
};
45+
46+
var checkRunModel =
47+
new CheckRunModel
48+
{
49+
Annotations = new List<CheckRunAnnotationModel> { checkRunAnnotationModel1, checkRunAnnotationModel2 },
50+
Name = "MSBuildLog Analyzer"
51+
};
52+
53+
var checkSuiteModel = new CheckSuiteModel()
54+
{
55+
HeadSha = "ed6198c37b13638e902716252b0a17d54bd59e4a",
56+
CheckRuns = new List<CheckRunModel> { checkRunModel },
57+
ApplicationName = "My Awesome Check Suite"
58+
};
59+
60+
Annotations = new[]
61+
{
62+
new InlineAnnotationViewModel(new InlineAnnotationModel(checkSuiteModel, checkRunModel, checkRunAnnotationModel1)),
63+
new InlineAnnotationViewModel(new InlineAnnotationModel(checkSuiteModel, checkRunModel, checkRunAnnotationModel2)),
64+
new InlineAnnotationViewModel(new InlineAnnotationModel(checkSuiteModel, checkRunModel, checkRunAnnotationModel3)),
65+
};
66+
67+
Comments = new ReactiveList<ICommentViewModel>(){new CommentViewModelDesigner()
68+
{
69+
Author = new ActorViewModel{ Login = "shana"},
70+
Body = "You can use a `CompositeDisposable` type here, it's designed to handle disposables in an optimal way (you can just call `Dispose()` on it and it will handle disposing everything it holds)."
71+
}};
72+
73+
}
74+
1175
public IReadOnlyReactiveList<ICommentViewModel> Comments { get; }
1276
= new ReactiveList<ICommentViewModel>();
1377

78+
public IReadOnlyList<IInlineAnnotationViewModel> Annotations { get; }
79+
1480
public IActorViewModel CurrentUser { get; set; }
1581
= new ActorViewModel { Login = "shana" };
1682

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
using GitHub.Models;
3+
using GitHub.ViewModels;
4+
5+
namespace GitHub.SampleData
6+
{
7+
public class InlineAnnotationViewModelDesigner : IInlineAnnotationViewModel
8+
{
9+
public InlineAnnotationViewModelDesigner()
10+
{
11+
var checkRunAnnotationModel = new CheckRunAnnotationModel
12+
{
13+
AnnotationLevel = CheckAnnotationLevel.Failure,
14+
Path = "SomeFile.cs",
15+
EndLine = 12,
16+
StartLine = 12,
17+
Message = "Some Error Message",
18+
Title = "CS12345"
19+
};
20+
21+
var checkRunModel =
22+
new CheckRunModel
23+
{
24+
Annotations = new List<CheckRunAnnotationModel> {checkRunAnnotationModel},
25+
Name = "Fake Check Run"
26+
};
27+
28+
var checkSuiteModel = new CheckSuiteModel()
29+
{
30+
ApplicationName = "Fake Check Suite",
31+
HeadSha = "ed6198c37b13638e902716252b0a17d54bd59e4a",
32+
CheckRuns = new List<CheckRunModel> { checkRunModel}
33+
};
34+
35+
Model= new InlineAnnotationModel(checkSuiteModel, checkRunModel, checkRunAnnotationModel);
36+
}
37+
38+
public InlineAnnotationModel Model { get; }
39+
}
40+
}

src/GitHub.App/SampleData/PullRequestAnnotationItemViewModelDesigner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public sealed class PullRequestAnnotationItemViewModelDesigner : IPullRequestAnn
1212
public CheckRunAnnotationModel Annotation { get; set; }
1313
public bool IsExpanded { get; set; }
1414
public string LineDescription => $"{Annotation.StartLine}:{Annotation.EndLine}";
15-
public bool IsFileInPullRequest { get; }
15+
public bool IsFileInPullRequest { get; set; }
1616
public ReactiveCommand<Unit, Unit> OpenAnnotation { get; }
1717
}
1818
}

src/GitHub.App/SampleData/PullRequestAnnotationsViewModelDesigner.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public sealed class PullRequestAnnotationsViewModelDesigner : PanePageViewModelB
3838
Title = "CS 12345"
3939
},
4040
IsExpanded = true,
41+
IsFileInPullRequest = true
4142
},
4243
new PullRequestAnnotationItemViewModelDesigner
4344
{
@@ -51,6 +52,7 @@ public sealed class PullRequestAnnotationsViewModelDesigner : PanePageViewModelB
5152
Title = "CS 12345"
5253
},
5354
IsExpanded = true,
55+
IsFileInPullRequest = true
5456
},
5557
}
5658
},

src/GitHub.App/SampleData/PullRequestCheckViewModelDesigner.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Reactive;
3-
using System.Windows.Media.Imaging;
43
using GitHub.Models;
54
using GitHub.ViewModels;
65
using GitHub.ViewModels.GitHubPane;

src/GitHub.App/SampleData/PullRequestFilesViewModelDesigner.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public PullRequestFilesViewModelDesigner()
3636
public ReactiveCommand<IPullRequestFileNode, Unit> DiffFileWithWorkingDirectory { get; }
3737
public ReactiveCommand<IPullRequestFileNode, Unit> OpenFileInWorkingDirectory { get; }
3838
public ReactiveCommand<IPullRequestFileNode, Unit> OpenFirstComment { get; }
39+
public ReactiveCommand<IPullRequestFileNode, Unit> OpenFirstAnnotationNotice { get; }
40+
public ReactiveCommand<IPullRequestFileNode, Unit> OpenFirstAnnotationWarning { get; }
41+
public ReactiveCommand<IPullRequestFileNode, Unit> OpenFirstAnnotationFailure { get; }
3942

4043
public Task InitializeAsync(
4144
IPullRequestSession session,

src/GitHub.App/Services/PullRequestEditorService.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ await pullRequestService.ExtractToTempFile(
285285
}
286286

287287
/// <inheritdoc/>
288-
public async Task<IDifferenceViewer> OpenDiff(
288+
public Task<IDifferenceViewer> OpenDiff(
289289
IPullRequestSession session,
290290
string relativePath,
291291
IInlineCommentThreadModel thread)
@@ -294,11 +294,17 @@ public async Task<IDifferenceViewer> OpenDiff(
294294
Guard.ArgumentNotEmptyString(relativePath, nameof(relativePath));
295295
Guard.ArgumentNotNull(thread, nameof(thread));
296296

297-
var diffViewer = await OpenDiff(session, relativePath, thread.CommitSha, scrollToFirstDraftOrDiff: false);
297+
return OpenDiff(session, relativePath, thread.CommitSha, thread.LineNumber - 1);
298+
}
299+
300+
/// <inheritdoc/>
301+
public async Task<IDifferenceViewer> OpenDiff(IPullRequestSession session, string relativePath, string headSha, int fromLine)
302+
{
303+
var diffViewer = await OpenDiff(session, relativePath, headSha, scrollToFirstDraftOrDiff: false);
298304

299-
var param = (object)new InlineCommentNavigationParams
305+
var param = (object) new InlineCommentNavigationParams
300306
{
301-
FromLine = thread.LineNumber - 1,
307+
FromLine = fromLine,
302308
};
303309

304310
// HACK: We need to wait here for the inline comment tags to initialize so we can find the next inline comment.

src/GitHub.App/ViewModels/CommentThreadViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public CommentThreadViewModel(
5757
/// <inheritdoc/>
5858
public IActorViewModel CurrentUser { get; private set; }
5959

60+
/// <inheritdoc/>
61+
public IReadOnlyList<IInlineAnnotationViewModel> Annotations { get; private set; }
62+
6063
/// <inheritdoc/>
6164
IReadOnlyReactiveList<ICommentViewModel> ICommentThreadViewModel.Comments => comments;
6265

@@ -92,8 +95,10 @@ protected IDisposable AddPlaceholder(ICommentViewModel placeholder)
9295
/// Intializes a new instance of the <see cref="CommentThreadViewModel"/> class.
9396
/// </summary>
9497
/// <param name="currentUser">The current user.</param>
95-
protected Task InitializeAsync(ActorModel currentUser)
98+
/// <param name="annotations"></param>
99+
protected Task InitializeAsync(ActorModel currentUser, IReadOnlyList<IInlineAnnotationViewModel> annotations)
96100
{
101+
Annotations = annotations;
97102
Guard.ArgumentNotNull(currentUser, nameof(currentUser));
98103
CurrentUser = new ActorViewModel(currentUser);
99104
return Task.CompletedTask;

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Reactive;
2+
using System.Reactive.Linq;
23
using GitHub.Models;
4+
using GitHub.Services;
35
using ReactiveUI;
46

57
namespace GitHub.ViewModels.GitHubPane
@@ -14,12 +16,22 @@ public class PullRequestAnnotationItemViewModel : ViewModelBase, IPullRequestAnn
1416
/// </summary>
1517
/// <param name="annotation">The check run annotation model.</param>
1618
/// <param name="isFileInPullRequest">A flag that denotes if the annotation is part of the pull request's changes.</param>
17-
public PullRequestAnnotationItemViewModel(CheckRunAnnotationModel annotation, bool isFileInPullRequest)
19+
/// <param name="checkSuite">The check suite model.</param>
20+
/// <param name="session">The pull request session.</param>
21+
/// <param name="editorService">The pull request editor service.</param>
22+
public PullRequestAnnotationItemViewModel(
23+
CheckRunAnnotationModel annotation,
24+
bool isFileInPullRequest,
25+
CheckSuiteModel checkSuite,
26+
IPullRequestSession session,
27+
IPullRequestEditorService editorService)
1828
{
1929
Annotation = annotation;
2030
IsFileInPullRequest = isFileInPullRequest;
2131

22-
OpenAnnotation = ReactiveCommand.Create(() => { });
32+
OpenAnnotation = ReactiveCommand.CreateFromTask<Unit>(
33+
async _ => await editorService.OpenDiff(session, annotation.Path, checkSuite.HeadSha, annotation.EndLine - 1),
34+
Observable.Return(IsFileInPullRequest));
2335
}
2436

2537
/// <inheritdoc />

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel.Composition;
44
using System.Linq;
@@ -15,7 +15,8 @@ namespace GitHub.ViewModels.GitHubPane
1515
[PartCreationPolicy(CreationPolicy.NonShared)]
1616
public class PullRequestAnnotationsViewModel : PanePageViewModelBase, IPullRequestAnnotationsViewModel
1717
{
18-
private readonly IPullRequestSessionManager sessionManager;
18+
readonly IPullRequestSessionManager sessionManager;
19+
readonly IPullRequestEditorService pullRequestEditorService;
1920

2021
IPullRequestSession session;
2122
string title;
@@ -27,10 +28,12 @@ public class PullRequestAnnotationsViewModel : PanePageViewModelBase, IPullReque
2728
/// Initializes a new instance of the <see cref="PullRequestAnnotationsViewModel"/> class.
2829
/// </summary>
2930
/// <param name="sessionManager">The pull request session manager.</param>
31+
/// <param name="pullRequestEditorService">The pull request editor service.</param>
3032
[ImportingConstructor]
31-
public PullRequestAnnotationsViewModel(IPullRequestSessionManager sessionManager)
33+
public PullRequestAnnotationsViewModel(IPullRequestSessionManager sessionManager, IPullRequestEditorService pullRequestEditorService)
3234
{
3335
this.sessionManager = sessionManager;
36+
this.pullRequestEditorService = pullRequestEditorService;
3437
NavigateToPullRequest = ReactiveCommand.Create(() => {
3538
NavigateTo(FormattableString.Invariant(
3639
$"{LocalRepository.Owner}/{LocalRepository.Name}/pull/{PullRequestNumber}"));
@@ -132,7 +135,7 @@ void Load(PullRequestDetailModel pullRequest)
132135
.ToDictionary(
133136
path => path,
134137
path => annotationsLookup[path]
135-
.Select(annotation => new PullRequestAnnotationItemViewModel(annotation, changedFiles.Contains(path)))
138+
.Select(annotation => new PullRequestAnnotationItemViewModel(annotation, changedFiles.Contains(path), checkSuiteRun.checkSuite, session, pullRequestEditorService))
136139
.Cast<IPullRequestAnnotationItemViewModel>()
137140
.ToArray()
138141
);

0 commit comments

Comments
 (0)