From be7ca145288f442e3dde859448f58a23084098f7 Mon Sep 17 00:00:00 2001 From: Praven Kuttappan <55455725+praveenkuttappan@users.noreply.github.com> Date: Wed, 6 Mar 2024 14:52:54 -0500 Subject: [PATCH] Update package version on automatic API revision (#7819) * Update package version on automatic API revision --- .../APIViewWeb/Controllers/AutoReviewController.cs | 12 +++++++----- .../APIViewWeb/Managers/APIRevisionsManager.cs | 11 +++++++++++ .../Managers/Interfaces/IAPIRevisionsManager.cs | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/dotnet/APIView/APIViewWeb/Controllers/AutoReviewController.cs b/src/dotnet/APIView/APIViewWeb/Controllers/AutoReviewController.cs index a453fcdf6..dd2e0a67c 100644 --- a/src/dotnet/APIView/APIViewWeb/Controllers/AutoReviewController.cs +++ b/src/dotnet/APIView/APIViewWeb/Controllers/AutoReviewController.cs @@ -35,7 +35,7 @@ namespace APIViewWeb.Controllers } [HttpPost] - public async Task UploadAutoReview([FromForm] IFormFile file, string label, bool compareAllRevisions = false) + public async Task UploadAutoReview([FromForm] IFormFile file, string label, bool compareAllRevisions = false, string packageVersion = null) { if (file != null) { @@ -46,9 +46,9 @@ namespace APIViewWeb.Controllers runAnalysis: false, memoryStream: memoryStream); var apiRevision = await CreateAutomaticRevisionAsync(codeFile: codeFile, label: label, originalName: file.FileName, memoryStream: memoryStream, compareAllRevisions); - if (apiRevision != null) { + apiRevision = await _apiRevisionsManager.UpdateRevisionMetadataAsync(apiRevision, packageVersion ?? codeFile.PackageVersion, label); var reviewUrl = $"{this.Request.Scheme}://{this.Request.Host}/Assemblies/Review/{apiRevision.ReviewId}?revisionId={apiRevision.Id}"; return apiRevision.IsApproved ? Ok(reviewUrl) : StatusCode(statusCode: StatusCodes.Status201Created, reviewUrl); } @@ -100,7 +100,8 @@ namespace APIViewWeb.Controllers string repoName, string packageName, bool compareAllRevisions, - string project + string project, + string packageVersion = null ) { using var memoryStream = new MemoryStream(); @@ -115,6 +116,7 @@ namespace APIViewWeb.Controllers var apiRevision = await CreateAutomaticRevisionAsync(codeFile: codeFile, label: label, originalName: originalFilePath, memoryStream: memoryStream, compareAllRevisions); if (apiRevision != null) { + apiRevision = await _apiRevisionsManager.UpdateRevisionMetadataAsync(apiRevision, packageVersion ?? codeFile.PackageVersion, label); var reviewUrl = $"{this.Request.Scheme}://{this.Request.Host}/Assemblies/Review/{apiRevision.ReviewId}?revisionId={apiRevision.Id}"; return apiRevision.IsApproved ? Ok(reviewUrl) : StatusCode(statusCode: StatusCodes.Status201Created, reviewUrl); } @@ -198,8 +200,8 @@ namespace APIViewWeb.Controllers if (apiRev.IsApproved && await _apiRevisionsManager.AreAPIRevisionsTheSame(apiRev, renderedCodeFile)) { await _apiRevisionsManager.ToggleAPIRevisionApprovalAsync(user: User, id: review.Id, apiRevision: apiRevision, notes: $"Approval Copied over from Revision with Id : {apiRev.Id}", approver: apiRev.Approvers.LastOrDefault()); - } - break; + break; + } } } } diff --git a/src/dotnet/APIView/APIViewWeb/Managers/APIRevisionsManager.cs b/src/dotnet/APIView/APIViewWeb/Managers/APIRevisionsManager.cs index 4ed952cc9..8ce9e4134 100644 --- a/src/dotnet/APIView/APIViewWeb/Managers/APIRevisionsManager.cs +++ b/src/dotnet/APIView/APIViewWeb/Managers/APIRevisionsManager.cs @@ -828,5 +828,16 @@ namespace APIViewWeb.Managers } return result; } + + public async Task UpdateRevisionMetadataAsync(APIRevisionListItemModel revision, string packageVersion, string label) + { + if (packageVersion != null && !packageVersion.Equals(revision.Files[0].PackageVersion)) + { + revision.Files[0].PackageVersion = packageVersion; + revision.Label = label; + await _apiRevisionsRepository.UpsertAPIRevisionAsync(revision); + } + return revision; + } } } diff --git a/src/dotnet/APIView/APIViewWeb/Managers/Interfaces/IAPIRevisionsManager.cs b/src/dotnet/APIView/APIViewWeb/Managers/Interfaces/IAPIRevisionsManager.cs index feb072e0e..c61a423d2 100644 --- a/src/dotnet/APIView/APIViewWeb/Managers/Interfaces/IAPIRevisionsManager.cs +++ b/src/dotnet/APIView/APIViewWeb/Managers/Interfaces/IAPIRevisionsManager.cs @@ -40,5 +40,6 @@ namespace APIViewWeb.Managers.Interfaces public Task AutoArchiveAPIRevisions(int archiveAfterMonths); public Task AssignReviewersToAPIRevisionAsync(ClaimsPrincipal User, string apiRevisionId, HashSet reviewers); public Task> GetAPIRevisionsAssignedToUser(string userName); + public Task UpdateRevisionMetadataAsync(APIRevisionListItemModel revision, string packageVersion, string label); } }