async Task <InlineAnnotationModel> GetFirstAnnotation(IPullRequestFileNode file,
                                                              CheckAnnotationLevel annotationLevel)
        {
            var sessionFile = await pullRequestSession.GetFile(file.RelativePath);

            var annotations = sessionFile.InlineAnnotations;

            return(annotations.OrderBy(model => model.EndLine).FirstOrDefault(model => model.AnnotationLevel == annotationLevel));
        }
        private async Task OpenFirstAnnotation(IPullRequestEditorService editorService, IPullRequestFileNode file,
                                               CheckAnnotationLevel checkAnnotationLevel)
        {
            var annotationModel = await GetFirstAnnotation(file, checkAnnotationLevel);

            if (annotationModel != null)
            {
                await editorService.OpenDiff(pullRequestSession, file.RelativePath, annotationModel.HeadSha, annotationModel.EndLine);
            }
        }
        private async Task OpenFirstAnnotation(IPullRequestEditorService editorService, IPullRequestFileNode file,
                                               CheckAnnotationLevel checkAnnotationLevel)
        {
            var annotationModel = await GetFirstAnnotation(file, checkAnnotationLevel);

            if (annotationModel != null)
            {
                //AnnotationModel.EndLine is a 1-based number
                //EditorService.OpenDiff takes a 0-based line number to start searching AFTER and will open the next tag
                var nextInlineCommentFromLine = annotationModel.EndLine - 2;
                await editorService.OpenDiff(pullRequestSession, file.RelativePath, annotationModel.HeadSha, nextInlineCommentFromLine);
            }
        }
        /// <summary>
        /// Constructs a CheckRunCreateAnnotation request object
        /// </summary>
        /// <param name="path">Required. The path of the file to add an annotation to. For example, assets/css/main.css</param>
        /// <param name="startLine">Required. The start line of the annotation</param>
        /// <param name="endLine">Required. The end line of the annotation</param>
        /// <param name="annotationLevel">Required. The level of the annotation. Can be one of notice, warning, or failure</param>
        /// <param name="message">Required. A short description of the feedback for these lines of code. The maximum size is 64 KB</param>
        public NewCheckRunAnnotation(string path, int startLine, int endLine, CheckAnnotationLevel annotationLevel, string message)
        {
            Path            = path;
            StartLine       = startLine;
            EndLine         = endLine;
            AnnotationLevel = annotationLevel;
            Message         = message;

            // Ensure legacy properties are explicitly null
#pragma warning disable CS0618 // Type or member is obsolete
            Filename     = null;
            BlobHref     = null;
            WarningLevel = null;
#pragma warning restore CS0618 // Type or member is obsolete
        }