Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public AutoReviewController(IAuthorizationService authorizationService, ICodeFil
}

[HttpPost]
public async Task<ActionResult> UploadAutoReview([FromForm] IFormFile file, string label, bool compareAllRevisions = false)
public async Task<ActionResult> UploadAutoReview([FromForm] IFormFile file, string label, bool compareAllRevisions = false, string packageVersion = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be helpful to document in which cases the function expects packageVersion not to be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it as null for now until all individual caller from language repo starts to send it. Once change is merged to individual repos, I will change this as required param.

{
if (file != null)
{
Expand All @@ -46,9 +46,9 @@ public async Task<ActionResult> UploadAutoReview([FromForm] IFormFile file, stri
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);
}
Expand Down Expand Up @@ -100,7 +100,8 @@ public async Task<ActionResult> CreateApiReview(
string repoName,
string packageName,
bool compareAllRevisions,
string project
string project,
string packageVersion = null
)
{
using var memoryStream = new MemoryStream();
Expand All @@ -115,6 +116,7 @@ string project
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);
}
Expand Down Expand Up @@ -198,8 +200,8 @@ private async Task<APIRevisionListItemModel> CreateAutomaticRevisionAsync(CodeFi
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;
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Managers/APIRevisionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -828,5 +828,16 @@ private async Task GenerateAPIRevisionInExternalResource(ReviewListItemModel rev
}
return result;
}

public async Task<APIRevisionListItemModel> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public Task<APIRevisionListItemModel> CreateAPIRevisionAsync(string userName, st
public Task AutoArchiveAPIRevisions(int archiveAfterMonths);
public Task AssignReviewersToAPIRevisionAsync(ClaimsPrincipal User, string apiRevisionId, HashSet<string> reviewers);
public Task<IEnumerable<APIRevisionListItemModel>> GetAPIRevisionsAssignedToUser(string userName);
public Task<APIRevisionListItemModel> UpdateRevisionMetadataAsync(APIRevisionListItemModel revision, string packageVersion, string label);
}
}