Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -49,6 +51,12 @@ public async Task<ActionResult> UploadAutoReview([FromForm] IFormFile file, stri
if (apiRevision != null)
{
apiRevision = await _apiRevisionsManager.UpdateRevisionMetadataAsync(apiRevision, packageVersion ?? codeFile.PackageVersion, label);
if (setReleaseTag)
{
// Set current revision as released. Preview packages are released without api review approval so we cannot really check if revision is approved to mark it as released.
// Pipeline enforces API view approval to release a GA package and request to tag a release is only sent after releasing a package. Hence we don't need to check approval status.
apiRevision = await _apiRevisionsManager.TagRevisionAsReleasedAsync(apiRevision);
}
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 +98,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 +112,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 @@ -117,6 +129,12 @@ public async Task<ActionResult> CreateApiReview(
if (apiRevision != null)
{
apiRevision = await _apiRevisionsManager.UpdateRevisionMetadataAsync(apiRevision, packageVersion ?? codeFile.PackageVersion, label);
if (setReleaseTag)
{
// Set current revision as released. Preview packages are released without api review approval so we cannot really check if revision is approved to mark it as released.
// Pipeline enforces API view approval to release a GA package and request to tag a release is only sent after releasing a package. Hence we don't need to check approval status.
apiRevision = await _apiRevisionsManager.TagRevisionAsReleasedAsync(apiRevision);
}
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 +169,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
20 changes: 20 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Managers/APIRevisionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,12 @@ private async Task GenerateAPIRevisionInExternalResource(ReviewListItemModel rev

public async Task<APIRevisionListItemModel> UpdateRevisionMetadataAsync(APIRevisionListItemModel revision, string packageVersion, string label)
{
// 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;
Expand All @@ -839,5 +845,19 @@ public async Task<APIRevisionListItemModel> UpdateRevisionMetadataAsync(APIRevis
}
return revision;
}

public async Task<APIRevisionListItemModel> TagRevisionAsReleasedAsync(APIRevisionListItemModel revision)
{
// Don't update release date if revision is already marked as released
//This shouldn't be the case but adding this check to safe guard released on property
if (revision.IsReleased)
{
return revision;
}
revision.IsReleased = true;
revision.ReleasedOn = DateTime.UtcNow;
await _apiRevisionsRepository.UpsertAPIRevisionAsync(revision);
return revision; ;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ public Task<APIRevisionListItemModel> CreateAPIRevisionAsync(string userName, st
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> TagRevisionAsReleasedAsync(APIRevisionListItemModel revision);
}
}