public async Task <IActionResult> OnGetAsync(string id, string revisionId = null) { TempData["Page"] = "api"; Review = await _manager.GetReviewAsync(User, id); if (!Review.Revisions.Any()) { return(RedirectToPage("LegacyReview", new { id = id })); } Comments = await _commentsManager.GetReviewCommentsAsync(id); Revision = revisionId != null? Review.Revisions.Single(r => r.RevisionId == revisionId) : Review.Revisions.Last(); PreviousRevisions = Review.Revisions.TakeWhile(r => r != Revision).ToArray(); var renderedCodeFile = await _codeFileRepository.GetCodeFileAsync(Revision); CodeFile = renderedCodeFile.CodeFile; var fileDiagnostics = CodeFile.Diagnostics ?? Array.Empty <CodeDiagnostic>(); var fileHtmlLines = renderedCodeFile.Render(ShowDocumentation); if (DiffRevisionId != null) { DiffRevision = PreviousRevisions.Single(r => r.RevisionId == DiffRevisionId); var previousRevisionFile = await _codeFileRepository.GetCodeFileAsync(DiffRevision); var previousHtmlLines = previousRevisionFile.RenderReadOnly(ShowDocumentation); var previousRevisionTextLines = previousRevisionFile.RenderText(ShowDocumentation); var fileTextLines = renderedCodeFile.RenderText(ShowDocumentation); var diffLines = InlineDiff.Compute( previousRevisionTextLines, fileTextLines, previousHtmlLines, fileHtmlLines); Lines = CreateLines(fileDiagnostics, diffLines, Comments); } else { Lines = CreateLines(fileDiagnostics, fileHtmlLines, Comments); } ActiveConversations = ComputeActiveConversations(fileHtmlLines, Comments); TotalActiveConversations = Comments.Threads.Count(t => !t.IsResolved); var filterPreference = _preferenceCache.GetFilterType(User.GetGitHubLogin(), Review.FilterType); ReviewsForPackage = await _manager.GetReviewsAsync(Review.ServiceName, Review.PackageDisplayName, filterPreference); return(Page()); }
private async Task <bool> IsReviewSame(ReviewRevisionModel revision, RenderedCodeFile renderedCodeFile) { //This will compare and check if new code file content is same as revision in parameter var lastRevisionFile = await _codeFileRepository.GetCodeFileAsync(revision); var lastRevisionTextLines = lastRevisionFile.RenderText(showDocumentation: false, skipDiff: true); var fileTextLines = renderedCodeFile.RenderText(showDocumentation: false, skipDiff: true); return(lastRevisionTextLines.SequenceEqual(fileTextLines)); }
public async Task <IActionResult> OnGetAsync(string id, string revisionId = null) { TempData["Page"] = "api"; Review = await _manager.GetReviewAsync(User, id); if (!Review.Revisions.Any()) { return(RedirectToPage("LegacyReview", new { id = id })); } Comments = await _commentsManager.GetReviewCommentsAsync(id); Revision = revisionId != null? Review.Revisions.Single(r => r.RevisionId == revisionId) : Review.Revisions.Last(); PreviousRevisions = Review.Revisions.TakeWhile(r => r != Revision).ToArray(); CodeFile = await _codeFileRepository.GetCodeFileAsync(Revision); var fileDiagnostics = CodeFile.Diagnostics ?? Array.Empty <CodeDiagnostic>(); var fileHtmlLines = CodeFileHtmlRenderer.Normal.Render(CodeFile); if (DiffRevisionId != null) { DiffRevision = PreviousRevisions.Single(r => r.RevisionId == DiffRevisionId); var previousRevisionFile = await _codeFileRepository.GetCodeFileAsync(DiffRevision); var previousHtmlLines = CodeFileHtmlRenderer.ReadOnly.Render(previousRevisionFile); var previousRevisionTextLines = CodeFileRenderer.Instance.Render(previousRevisionFile); var fileTextLines = CodeFileRenderer.Instance.Render(CodeFile); var diffLines = InlineDiff.Compute( previousRevisionTextLines, fileTextLines, previousHtmlLines, fileHtmlLines); Lines = CreateLines(fileDiagnostics, diffLines, Comments); } else { Lines = CreateLines(fileDiagnostics, fileHtmlLines, Comments); } ActiveConversations = ComputeActiveConversations(fileHtmlLines, Comments); TotalActiveConversations = Comments.Threads.Count(t => !t.IsResolved); return(Page()); }
private async Task GetFormattedDiff(RenderedCodeFile renderedCodeFile, ReviewRevisionModel lastRevision, StringBuilder stringBuilder) { RenderedCodeFile autoReview = await _codeFileRepository.GetCodeFileAsync(lastRevision, false); var autoReviewTextFile = autoReview.RenderText(showDocumentation: false, skipDiff: true); var prCodeTextFile = renderedCodeFile.RenderText(showDocumentation: false, skipDiff: true); var diffLines = InlineDiff.Compute(autoReviewTextFile, prCodeTextFile, autoReviewTextFile, prCodeTextFile); if (diffLines == null || diffLines.Length == 0 || diffLines.Count(l => l.Kind != DiffLineKind.Unchanged) > 10) { return; } stringBuilder.Append(Environment.NewLine).Append("**API changes**").Append(Environment.NewLine); stringBuilder.Append("```diff").Append(Environment.NewLine); foreach (var line in diffLines) { if (line.Kind == DiffLineKind.Added) { stringBuilder.Append("+ ").Append(line.Line.DisplayString).Append(Environment.NewLine); } else if (line.Kind == DiffLineKind.Removed) { stringBuilder.Append("- ").Append(line.Line.DisplayString).Append(Environment.NewLine); } } stringBuilder.Append("```"); }
public async Task <IActionResult> OnGetAsync(string id, string revisionId = null) { TempData["Page"] = "api"; Review = await _manager.GetReviewAsync(User, id); if (!Review.Revisions.Any()) { return(RedirectToPage("LegacyReview", new { id = id })); } Revision = revisionId != null? Review.Revisions.Single(r => r.RevisionId == revisionId) : Review.Revisions.Last(); var reviewFile = Revision.Files.Single(); CodeFile = await _codeFileRepository.GetCodeFileAsync(Revision.RevisionId, reviewFile.ReviewFileId); Lines = new CodeFileHtmlRenderer().Render(CodeFile).ToArray(); Comments = await _commentsManager.GetReviewCommentsAsync(id); ActiveConversations = ComputeActiveConversations(Lines, Comments); TotalActiveConversations = Comments.Threads.Count(t => !t.IsResolved); return(Page()); }
private async Task <bool> IsReviewSame(ReviewModel review, CodeFile newCodeFile) { //This will compare and check if new code file content is same as last revision of given review in parameter //Get latest revision of review and check diff var lastRevisionFile = await _codeFileRepository.GetCodeFileAsync(review.Revisions.Last()); var lastRevisionTextLines = lastRevisionFile.RenderText(false); var renderedCodeFile = new RenderedCodeFile(newCodeFile); var fileTextLines = renderedCodeFile.RenderText(false); return(lastRevisionTextLines.SequenceEqual(fileTextLines)); }