Example #1
0
        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("```");
        }
Example #2
0
        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));
        }
        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));
        }