Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -15,7 +15,6 @@

namespace APIViewWeb.Controllers
{
[TypeFilter(typeof(ApiKeyAuthorizeAsyncFilter))]
public class AutoReviewController : Controller
{
private readonly IAuthorizationService _authorizationService;
Expand All @@ -34,8 +33,11 @@ public AutoReviewController(IAuthorizationService authorizationService, ICodeFil
_reviewManager = reviewManager;
}

// setReleaseTag param is set as true when request is originated from release pipeline to tag matching revision as released
// regular CI pipeline will not send this flag in request
[TypeFilter(typeof(ApiKeyAuthorizeAsyncFilter))]
[HttpPost]
public async Task<ActionResult> UploadAutoReview([FromForm] IFormFile file, string label, bool compareAllRevisions = false, string packageVersion = null)
public async Task<ActionResult> UploadAutoReview([FromForm] IFormFile file, string label, bool compareAllRevisions = false, string packageVersion = null, bool setReleaseTag = false)
{
if (file != null)
{
Expand All @@ -48,7 +50,7 @@ public async Task<ActionResult> UploadAutoReview([FromForm] IFormFile file, stri
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);
apiRevision = await _apiRevisionsManager.UpdateRevisionMetadataAsync(apiRevision, packageVersion ?? codeFile.PackageVersion, label, setReleaseTag);
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 @@ -90,6 +92,9 @@ public async Task<ActionResult> GetReviewStatus(string language, string packageN
throw new Exception("Review is not found for package " + packageName);
}

// setReleaseTag param is set as true when request is originated from release pipeline to tag matching revision as released
// regular CI pipeline will not send this flag in request
[TypeFilter(typeof(ApiKeyAuthorizeAsyncFilter))]
[HttpGet]
public async Task<ActionResult> CreateApiReview(
string buildId,
Expand All @@ -101,7 +106,8 @@ public async Task<ActionResult> CreateApiReview(
string packageName,
bool compareAllRevisions,
string project,
string packageVersion = null
string packageVersion = null,
bool setReleaseTag = false
)
{
using var memoryStream = new MemoryStream();
Expand All @@ -116,7 +122,7 @@ public async Task<ActionResult> CreateApiReview(
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);
apiRevision = await _apiRevisionsManager.UpdateRevisionMetadataAsync(apiRevision, packageVersion ?? codeFile.PackageVersion, label, setReleaseTag);
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 @@ -151,6 +157,7 @@ private async Task<APIRevisionListItemModel> CreateAutomaticRevisionAsync(CodeFi
while (
automaticRevisionsQueue.Any() &&
!latestAutomaticAPIRevision.IsApproved &&
!latestAutomaticAPIRevision.IsReleased &&
!await _apiRevisionsManager.AreAPIRevisionsTheSame(latestAutomaticAPIRevision, renderedCodeFile) &&
!comments.Any(c => latestAutomaticAPIRevision.Id == c.APIRevisionId))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public class APIRevisionListItemModel : BaseListitemModel
public DateTime CreatedOn { get; set; }
public DateTime LastUpdatedOn { get; set; }
public bool IsDeleted { get; set; }
public bool IsReleased { get; set; }
public DateTime ReleasedOn { get; set; }
}

public class SamplesRevisionModel
Expand Down
16 changes: 14 additions & 2 deletions src/dotnet/APIView/APIViewWeb/Managers/APIRevisionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -829,14 +829,26 @@ private async Task GenerateAPIRevisionInExternalResource(ReviewListItemModel rev
return result;
}

public async Task<APIRevisionListItemModel> UpdateRevisionMetadataAsync(APIRevisionListItemModel revision, string packageVersion, string label)
public async Task<APIRevisionListItemModel> UpdateRevisionMetadataAsync(APIRevisionListItemModel revision, string packageVersion, string label, bool setReleaseTag = false)
{
// Do not update package version metadata once a revision is marked as released
// This is to avoid updating metadata when a request is processed with a new version (auto incremented version change) right after a version is released
// without any API changes.
if (revision.IsReleased)
return revision;

if (packageVersion != null && !packageVersion.Equals(revision.Files[0].PackageVersion))
{
revision.Files[0].PackageVersion = packageVersion;
revision.Label = label;
await _apiRevisionsRepository.UpsertAPIRevisionAsync(revision);
}

if (setReleaseTag)
{
revision.IsReleased = true;
revision.ReleasedOn = DateTime.UtcNow;
}
await _apiRevisionsRepository.UpsertAPIRevisionAsync(revision);
return revision;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +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);
public Task<APIRevisionListItemModel> UpdateRevisionMetadataAsync(APIRevisionListItemModel revision, string packageVersion, string label, bool setReleaseTag = false);
}
}