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

Commit ea3c850

Browse files
Functionality to open an annotation tag from the file list
1 parent 4f0f721 commit ea3c850

23 files changed

+189
-39
lines changed

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<Unit> DiffFileWithWorkingDirectory { get; }
3737
public ReactiveCommand<Unit> OpenFileInWorkingDirectory { get; }
3838
public ReactiveCommand<Unit> OpenFirstComment { get; }
39+
public ReactiveCommand<Unit> OpenFirstAnnotationNotice { get; }
40+
public ReactiveCommand<Unit> OpenFirstAnnotationWarning { get; }
41+
public ReactiveCommand<Unit> OpenFirstAnnotationFailure { get; }
3942

4043
public Task InitializeAsync(
4144
IPullRequestSession session,

src/GitHub.App/Services/PullRequestEditorService.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ await pullRequestService.ExtractToTempFile(
238238
}
239239

240240
/// <inheritdoc/>
241-
public async Task<IDifferenceViewer> OpenDiff(
241+
public Task<IDifferenceViewer> OpenDiff(
242242
IPullRequestSession session,
243243
string relativePath,
244244
IInlineCommentThreadModel thread)
@@ -247,11 +247,16 @@ public async Task<IDifferenceViewer> OpenDiff(
247247
Guard.ArgumentNotEmptyString(relativePath, nameof(relativePath));
248248
Guard.ArgumentNotNull(thread, nameof(thread));
249249

250-
var diffViewer = await OpenDiff(session, relativePath, thread.CommitSha, scrollToFirstDiff: false);
250+
return OpenDiff(session, relativePath, thread.CommitSha, thread.LineNumber - 1);
251+
}
252+
253+
public async Task<IDifferenceViewer> OpenDiff(IPullRequestSession session, string relativePath, string headSha, int fromLine)
254+
{
255+
var diffViewer = await OpenDiff(session, relativePath, headSha, scrollToFirstDiff: false);
251256

252-
var param = (object)new InlineCommentNavigationParams
257+
var param = (object) new InlineReviewNavigationParams
253258
{
254-
FromLine = thread.LineNumber - 1,
259+
FromLine = fromLine,
255260
};
256261

257262
// 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/PullRequestAnnotationsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async Task Load(PullRequestDetailModel pullRequest)
9494

9595
var checkRunModel = pullRequest
9696
.CheckSuites.SelectMany(model => model.CheckRuns)
97-
.First(model => model.CheckRunId == CheckRunId);
97+
.First(model => model.DatabaseId == CheckRunId);
9898

9999
CheckRunName = checkRunModel.Name;
100100
Annotations = checkRunModel.Annotations

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static IEnumerable<IPullRequestCheckViewModel> Build(IViewViewModelFactor
9191

9292
var pullRequestCheckViewModel = (PullRequestCheckViewModel)viewViewModelFactory.CreateViewModel<IPullRequestCheckViewModel>();
9393
pullRequestCheckViewModel.CheckType = PullRequestCheckType.ChecksApi;
94-
pullRequestCheckViewModel.CheckRunId = checkRunModel.CheckRunId;
94+
pullRequestCheckViewModel.CheckRunId = checkRunModel.DatabaseId;
9595
pullRequestCheckViewModel.HasAnnotations = checkRunModel.Annotations?.Any() ?? false;
9696
pullRequestCheckViewModel.Title = checkRunModel.Name;
9797
pullRequestCheckViewModel.Description = checkRunModel.Summary;

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ namespace GitHub.ViewModels.GitHubPane
1313
public class PullRequestFileNode : ReactiveObject, IPullRequestFileNode
1414
{
1515
int commentCount;
16+
int annotationNoticeCount;
1617
int annotationWarningCount;
17-
int annotationErrorCount;
18+
int _annotationFailureCount;
1819

1920
/// <summary>
2021
/// Initializes a new instance of the <see cref="PullRequestFileNode"/> class.
@@ -102,6 +103,15 @@ public int CommentCount
102103
set { this.RaiseAndSetIfChanged(ref commentCount, value); }
103104
}
104105

106+
/// <summary>
107+
/// Gets or sets the number of annotation notices on the file.
108+
/// </summary>
109+
public int AnnotationNoticeCount
110+
{
111+
get { return annotationNoticeCount; }
112+
set { this.RaiseAndSetIfChanged(ref annotationNoticeCount, value); }
113+
}
114+
105115
/// <summary>
106116
/// Gets or sets the number of annotation errors on the file.
107117
/// </summary>
@@ -112,12 +122,12 @@ public int AnnotationWarningCount
112122
}
113123

114124
/// <summary>
115-
/// Gets or sets the number of annotation errors on the file.
125+
/// Gets or sets the number of annotation failures on the file.
116126
/// </summary>
117-
public int AnnotationErrorCount
127+
public int AnnotationFailureCount
118128
{
119-
get { return annotationErrorCount; }
120-
set { this.RaiseAndSetIfChanged(ref annotationErrorCount, value); }
129+
get { return _annotationFailureCount; }
130+
set { this.RaiseAndSetIfChanged(ref _annotationFailureCount, value); }
121131
}
122132
}
123133
}

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

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ public PullRequestFilesViewModel(
6666
await editorService.OpenDiff(pullRequestSession, file.RelativePath, thread);
6767
}
6868
});
69+
70+
OpenFirstAnnotationNotice = ReactiveCommand.CreateAsyncTask(async x =>
71+
{
72+
await OpenFirstAnnotation(editorService, (IPullRequestFileNode) x, CheckAnnotationLevel.Notice);
73+
});
74+
75+
OpenFirstAnnotationWarning = ReactiveCommand.CreateAsyncTask(async x =>
76+
{
77+
await OpenFirstAnnotation(editorService, (IPullRequestFileNode) x, CheckAnnotationLevel.Warning);
78+
});
79+
80+
OpenFirstAnnotationFailure = ReactiveCommand.CreateAsyncTask(async x =>
81+
{
82+
await OpenFirstAnnotation(editorService, (IPullRequestFileNode) x, CheckAnnotationLevel.Failure);
83+
});
84+
}
85+
86+
private async Task OpenFirstAnnotation(IPullRequestEditorService editorService, IPullRequestFileNode file,
87+
CheckAnnotationLevel checkAnnotationLevel)
88+
{
89+
var annotationModel = await GetFirstAnnotation(file, checkAnnotationLevel);
90+
91+
if (annotationModel != null)
92+
{
93+
await editorService.OpenDiff(pullRequestSession, file.RelativePath, annotationModel.HeadSha, annotationModel.EndLine);
94+
}
6995
}
7096

7197
/// <inheritdoc/>
@@ -127,10 +153,13 @@ public async Task InitializeAsync(
127153
subscriptions.Add(file.WhenAnyValue(x => x.InlineAnnotations)
128154
.Subscribe(x =>
129155
{
130-
var count = x.Count(model => model.AnnotationLevel == CheckAnnotationLevel.Failure);
156+
var noticeCount = x.Count(model => model.AnnotationLevel == CheckAnnotationLevel.Notice);
157+
var warningCount = x.Count(model => model.AnnotationLevel == CheckAnnotationLevel.Warning);
158+
var failureCount = x.Count(model => model.AnnotationLevel == CheckAnnotationLevel.Failure);
131159

132-
node.AnnotationErrorCount = count;
133-
node.AnnotationWarningCount = x.Count - count;
160+
node.AnnotationNoticeCount = noticeCount;
161+
node.AnnotationWarningCount = warningCount;
162+
node.AnnotationFailureCount = failureCount;
134163
}));
135164
}
136165

@@ -158,6 +187,15 @@ public async Task InitializeAsync(
158187
/// <inheritdoc/>
159188
public ReactiveCommand<Unit> OpenFirstComment { get; }
160189

190+
/// <inheritdoc/>
191+
public ReactiveCommand<Unit> OpenFirstAnnotationNotice { get; }
192+
193+
/// <inheritdoc/>
194+
public ReactiveCommand<Unit> OpenFirstAnnotationWarning { get; }
195+
196+
/// <inheritdoc/>
197+
public ReactiveCommand<Unit> OpenFirstAnnotationFailure { get; }
198+
161199
static int CountComments(
162200
IEnumerable<IInlineCommentThreadModel> thread,
163201
Func<IInlineCommentThreadModel, bool> commentFilter)
@@ -210,6 +248,15 @@ async Task<IInlineCommentThreadModel> GetFirstCommentThread(IPullRequestFileNode
210248
return threads.FirstOrDefault();
211249
}
212250

251+
async Task<IInlineAnnotationModel> GetFirstAnnotation(IPullRequestFileNode file,
252+
CheckAnnotationLevel annotationLevel)
253+
{
254+
var sessionFile = await pullRequestSession.GetFile(file.RelativePath);
255+
var annotations = sessionFile.InlineAnnotations;
256+
257+
return annotations.FirstOrDefault(model => model.AnnotationLevel == annotationLevel);
258+
}
259+
213260
/// <summary>
214261
/// Implements the <see cref="OpenFileInWorkingDirectory"/> command.
215262
/// </summary>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ public interface IInlineAnnotationModel
1313
string FileName { get; }
1414
string LineDescription { get; }
1515
string CheckRunName { get; }
16+
string HeadSha { get; }
1617
}
1718
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ namespace GitHub.Models
44
{
55
public class InlineAnnotationModel: IInlineAnnotationModel
66
{
7+
readonly CheckSuiteModel checkSuite;
78
readonly CheckRunModel checkRun;
89
readonly CheckRunAnnotationModel annotation;
910

10-
public InlineAnnotationModel(CheckRunModel checkRun, CheckRunAnnotationModel annotation)
11+
public InlineAnnotationModel(CheckSuiteModel checkSuite, CheckRunModel checkRun,
12+
CheckRunAnnotationModel annotation)
1113
{
1214
Guard.ArgumentNotNull(checkRun, nameof(checkRun));
1315
Guard.ArgumentNotNull(annotation, nameof(annotation));
1416
Guard.ArgumentNotNull(annotation.AnnotationLevel, nameof(annotation.AnnotationLevel));
1517

18+
this.checkSuite = checkSuite;
1619
this.checkRun = checkRun;
1720
this.annotation = annotation;
1821
}
@@ -31,6 +34,8 @@ public InlineAnnotationModel(CheckRunModel checkRun, CheckRunAnnotationModel ann
3134

3235
public string Message => annotation.Message;
3336

37+
public string HeadSha => checkSuite.HeadSha;
38+
3439
public string LineDescription => $"{StartLine}:{EndLine}";
3540
}
3641
}

src/GitHub.Exports.Reactive/Services/IPullRequestEditorService.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,28 @@ public interface IPullRequestEditorService
3737
Task<IDifferenceViewer> OpenDiff(IPullRequestSession session, string relativePath, string headSha = null, bool scrollToFirstDiff = true);
3838

3939
/// <summary>
40-
/// Opens an diff viewer for a file in a pull request with the specified inline comment
41-
/// thread open.
40+
/// Opens an diff viewer for a file in a pull request with the specified inline review
41+
/// comment thread open.
4242
/// </summary>
4343
/// <param name="session">The pull request session.</param>
4444
/// <param name="relativePath">The path to the file, relative to the repository.</param>
4545
/// <param name="thread">The thread to open</param>
4646
/// <returns>The opened diff viewer.</returns>
4747
Task<IDifferenceViewer> OpenDiff(IPullRequestSession session, string relativePath, IInlineCommentThreadModel thread);
4848

49+
/// <summary>
50+
/// Opens an diff viewer for a file in a pull request with the specified inline review line open.
51+
/// </summary>
52+
/// <param name="session">The pull request session.</param>
53+
/// <param name="relativePath">The path to the file, relative to the repository.</param>
54+
/// <param name="headSha">
55+
/// The commit SHA of the right hand side of the diff. Pass null to compare with the
56+
/// working directory, or "HEAD" to compare with the HEAD commit of the pull request.
57+
/// </param>
58+
/// <param name="fromLine">The line number to open</param>
59+
/// <returns>The opened diff viewer.</returns>
60+
Task<IDifferenceViewer> OpenDiff(IPullRequestSession session, string relativePath, string headSha, int fromLine);
61+
4962
/// <summary>
5063
/// Find the active text view.
5164
/// </summary>

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ public interface IPullRequestFilesViewModel : IViewModel, IDisposable
5151
/// </summary>
5252
ReactiveCommand<Unit> OpenFirstComment { get; }
5353

54+
/// <summary>
55+
/// Gets a command that opens the first annotation notice for a <see cref="IPullRequestFileNode"/> in
56+
/// the diff viewer.
57+
/// </summary>
58+
ReactiveCommand<Unit> OpenFirstAnnotationNotice { get; }
59+
60+
/// <summary>
61+
/// Gets a command that opens the first annotation warning for a <see cref="IPullRequestFileNode"/> in
62+
/// the diff viewer.
63+
/// </summary>
64+
ReactiveCommand<Unit> OpenFirstAnnotationWarning { get; }
65+
66+
/// <summary>
67+
/// Gets a command that opens the first annotation failure for a <see cref="IPullRequestFileNode"/> in
68+
/// the diff viewer.
69+
/// </summary>
70+
ReactiveCommand<Unit> OpenFirstAnnotationFailure { get; }
71+
5472
/// <summary>
5573
/// Initializes the view model.
5674
/// </summary>

0 commit comments

Comments
 (0)