private async Task <ReviewRevisionModel> CreateBaselineRevision( CodeFile baselineCodeFile, MemoryStream baseLineStream, PullRequestModel prModel, string fileName) { var newRevision = new ReviewRevisionModel() { Author = prModel.Author, Label = $"Baseline for PR {prModel.PullRequestNumber}" }; var reviewCodeFileModel = await _reviewManager.CreateReviewCodeFileModel(newRevision.RevisionId, baseLineStream, baselineCodeFile); reviewCodeFileModel.FileName = fileName; newRevision.Files.Add(reviewCodeFileModel); return(newRevision); }
public async Task <string> GetApiDiffFromAutomaticReview(CodeFile codeFile, int prNumber, string originalFileName, MemoryStream memoryStream, PullRequestModel pullRequestModel) { // Get automatically generated master review for package or previously cloned review for this pull request var review = await GetBaseLineReview(codeFile.Language, codeFile.PackageName, pullRequestModel); if (review == null) { return(""); } // Check if API surface level matches with any revisions var renderedCodeFile = new RenderedCodeFile(codeFile); if (await IsReviewSame(review, renderedCodeFile)) { return(""); } if (pullRequestModel.ReviewId != null) { // If baseline review was already created and if APIs in current commit doesn't match any of the revisions in generated review then create new baseline using main branch and compare again. // If APIs are still different, find the diff against latest baseline. review = await GetBaseLineReview(codeFile.Language, codeFile.PackageName, pullRequestModel, true); review.ReviewId = pullRequestModel.ReviewId; if (await IsReviewSame(review, renderedCodeFile)) { return(""); } } var newRevision = new ReviewRevisionModel() { Author = review.Author, Label = "Created for PR " + prNumber }; var stringBuilder = new StringBuilder(); var diffUrl = REVIEW_DIFF_URL.Replace("{ReviewId}", review.ReviewId).Replace("{NewRevision}", review.Revisions.Last().RevisionId); stringBuilder.Append($"API changes have been detected in `{codeFile.PackageName}`. You can review API changes [here]({diffUrl})").Append(Environment.NewLine); // If review doesn't match with any revisions then generate formatted diff against last revision of automatic review await GetFormattedDiff(renderedCodeFile, review.Revisions.Last(), stringBuilder); var reviewCodeFileModel = await _reviewManager.CreateReviewCodeFileModel(newRevision.RevisionId, memoryStream, codeFile); reviewCodeFileModel.FileName = originalFileName; newRevision.Files.Add(reviewCodeFileModel); review.Revisions.Add(newRevision); pullRequestModel.ReviewId = review.ReviewId; review.FilterType = ReviewType.PullRequest; await _reviewsRepository.UpsertReviewAsync(review); await _pullRequestsRepository.UpsertPullRequestAsync(pullRequestModel); return(stringBuilder.ToString()); }