From 7daac93087f1e727dc1b3203f328cc5417266189 Mon Sep 17 00:00:00 2001 From: praveenkuttappan <55455725+praveenkuttappan@users.noreply.github.com> Date: Tue, 16 Aug 2022 11:10:09 -0400 Subject: [PATCH] Remove duplicate PR API review revisions (#3949) * Remove duplicate pull request API review revisions --- .../APIView/APIViewWeb/Models/ReviewRevisionModelList.cs | 5 +++++ .../APIView/APIViewWeb/Repositories/PullRequestManager.cs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/dotnet/APIView/APIViewWeb/Models/ReviewRevisionModelList.cs b/src/dotnet/APIView/APIViewWeb/Models/ReviewRevisionModelList.cs index 1a59977998b..d78790e3a5c 100644 --- a/src/dotnet/APIView/APIViewWeb/Models/ReviewRevisionModelList.cs +++ b/src/dotnet/APIView/APIViewWeb/Models/ReviewRevisionModelList.cs @@ -36,6 +36,11 @@ public void AddRange(IEnumerable revisionModels) } } + public void RemoveAll(System.Predicate match) + { + _list.RemoveAll(match); + } + public void Clear() { _list.Clear(); diff --git a/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs b/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs index 806d8f2d421..72ad8ed1b9e 100644 --- a/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs +++ b/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs @@ -293,6 +293,12 @@ private async Task CreateRevisionIfRequired(CodeFile codeFile, var prevRevisionId = review.Revisions.Last().RevisionId; review = await GetBaseLineReview(codeFile.Language, codeFile.PackageName, pullRequestModel, true); review.ReviewId = pullRequestModel.ReviewId; + //Remove previous revisions with revision ID. + //Currently revision ID is getting duplicated when a PR api review is created for a brand new package. + //In case of brand new package, we don't have any baseline from automatic review. So it uses previous PR api review as baseline and + //below revision ID copy step makes duplicate revision IDs in such cases. + //We should ensure that no revision exists in review with previous revision ID before we update new revision + review.Revisions.RemoveAll(r => r.RevisionId == prevRevisionId); newRevision.RevisionId = prevRevisionId; } }