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

Commit fef4a16

Browse files
authored
Merge pull request #1900 from github/features/check-suite-annotations-inline
Check Run Annotations Inline
2 parents 9e9978f + 1da4ac2 commit fef4a16

File tree

44 files changed

+824
-281
lines changed

Some content is hidden

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

44 files changed

+824
-281
lines changed

src/GitHub.App/SampleData/CommentThreadViewModelDesigner.cs

Lines changed: 13 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,6 +10,16 @@ namespace GitHub.SampleData
810
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
911
public class CommentThreadViewModelDesigner : ViewModelBase, ICommentThreadViewModel
1012
{
13+
public CommentThreadViewModelDesigner()
14+
{
15+
Comments = new ReactiveList<ICommentViewModel>(){new CommentViewModelDesigner()
16+
{
17+
Author = new ActorViewModel{ Login = "shana"},
18+
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)."
19+
}};
20+
21+
}
22+
1123
public IReadOnlyReactiveList<ICommentViewModel> Comments { get; }
1224
= new ReactiveList<ICommentViewModel>();
1325

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
@@ -40,6 +40,7 @@ public sealed class PullRequestAnnotationsViewModelDesigner : PanePageViewModelB
4040
Title = "CS 12345"
4141
},
4242
IsExpanded = true,
43+
IsFileInPullRequest = true
4344
},
4445
new PullRequestAnnotationItemViewModelDesigner
4546
{
@@ -53,6 +54,7 @@ public sealed class PullRequestAnnotationsViewModelDesigner : PanePageViewModelB
5354
Title = "CS 12345"
5455
},
5556
IsExpanded = true,
57+
IsFileInPullRequest = true
5658
},
5759
}
5860
},

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/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;
@@ -29,10 +30,12 @@ public class PullRequestAnnotationsViewModel : PanePageViewModelBase, IPullReque
2930
/// Initializes a new instance of the <see cref="PullRequestAnnotationsViewModel"/> class.
3031
/// </summary>
3132
/// <param name="sessionManager">The pull request session manager.</param>
33+
/// <param name="pullRequestEditorService">The pull request editor service.</param>
3234
[ImportingConstructor]
33-
public PullRequestAnnotationsViewModel(IPullRequestSessionManager sessionManager)
35+
public PullRequestAnnotationsViewModel(IPullRequestSessionManager sessionManager, IPullRequestEditorService pullRequestEditorService)
3436
{
3537
this.sessionManager = sessionManager;
38+
this.pullRequestEditorService = pullRequestEditorService;
3639
NavigateToPullRequest = ReactiveCommand.Create(() => {
3740
NavigateTo(FormattableString.Invariant(
3841
$"{LocalRepository.Owner}/{LocalRepository.Name}/pull/{PullRequestNumber}"));
@@ -151,7 +154,7 @@ void Load(PullRequestDetailModel pullRequest)
151154
.ToDictionary(
152155
path => path,
153156
path => annotationsLookup[path]
154-
.Select(annotation => new PullRequestAnnotationItemViewModel(annotation, changedFiles.Contains(path)))
157+
.Select(annotation => new PullRequestAnnotationItemViewModel(annotation, changedFiles.Contains(path), checkSuiteRun.checkSuite, session, pullRequestEditorService))
155158
.Cast<IPullRequestAnnotationItemViewModel>()
156159
.ToArray()
157160
);

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using GitHub.Extensions;
88
using GitHub.Factories;
99
using GitHub.Models;
10+
using GitHub.Primitives;
1011
using GitHub.Services;
1112
using ReactiveUI;
1213

@@ -17,6 +18,8 @@ namespace GitHub.ViewModels.GitHubPane
1718
[PartCreationPolicy(CreationPolicy.NonShared)]
1819
public class PullRequestCheckViewModel: ViewModelBase, IPullRequestCheckViewModel
1920
{
21+
const string DefaultAvatar = "pack://application:,,,/GitHub.App;component/Images/default_user_avatar.png";
22+
2023
private readonly IUsageTracker usageTracker;
2124

2225
/// <summary>
@@ -56,11 +59,14 @@ public static IEnumerable<IPullRequestCheckViewModel> Build(IViewViewModelFactor
5659
return pullRequestCheckViewModel;
5760
}) ?? Array.Empty<PullRequestCheckViewModel>();
5861

59-
var checks = pullRequest.CheckSuites?.SelectMany(checkSuiteModel => checkSuiteModel.CheckRuns)
60-
.Select(checkRunModel =>
62+
var checks =
63+
pullRequest.CheckSuites?
64+
.SelectMany(checkSuite => checkSuite.CheckRuns
65+
.Select(checkRun => new { checkSuiteModel = checkSuite, checkRun}))
66+
.Select(arg =>
6167
{
6268
PullRequestCheckStatus checkStatus;
63-
switch (checkRunModel.Status)
69+
switch (arg.checkRun.Status)
6470
{
6571
case CheckStatusState.Requested:
6672
case CheckStatusState.Queued:
@@ -69,7 +75,7 @@ public static IEnumerable<IPullRequestCheckViewModel> Build(IViewViewModelFactor
6975
break;
7076

7177
case CheckStatusState.Completed:
72-
switch (checkRunModel.Conclusion)
78+
switch (arg.checkRun.Conclusion)
7379
{
7480
case CheckConclusionState.Success:
7581
checkStatus = PullRequestCheckStatus.Success;
@@ -94,13 +100,12 @@ public static IEnumerable<IPullRequestCheckViewModel> Build(IViewViewModelFactor
94100

95101
var pullRequestCheckViewModel = (PullRequestCheckViewModel)viewViewModelFactory.CreateViewModel<IPullRequestCheckViewModel>();
96102
pullRequestCheckViewModel.CheckType = PullRequestCheckType.ChecksApi;
97-
pullRequestCheckViewModel.CheckRunId = checkRunModel.Id;
98-
pullRequestCheckViewModel.HasAnnotations = checkRunModel.Annotations?.Any() ?? false;
99-
pullRequestCheckViewModel.Title = checkRunModel.Name;
100-
pullRequestCheckViewModel.Description = checkRunModel.Summary;
103+
pullRequestCheckViewModel.CheckRunId = arg.checkRun.Id;
104+
pullRequestCheckViewModel.HasAnnotations = arg.checkRun.Annotations?.Any() ?? false;
105+
pullRequestCheckViewModel.Title = arg.checkRun.Name;
106+
pullRequestCheckViewModel.Description = arg.checkRun.Summary;
101107
pullRequestCheckViewModel.Status = checkStatus;
102-
pullRequestCheckViewModel.DetailsUrl = new Uri(checkRunModel.DetailsUrl);
103-
108+
pullRequestCheckViewModel.DetailsUrl = new Uri(arg.checkRun.DetailsUrl);
104109
return pullRequestCheckViewModel;
105110
}) ?? Array.Empty<PullRequestCheckViewModel>();
106111

0 commit comments

Comments
 (0)