Compare commits
9 Commits
main
...
sync-eng/c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5a4c64c36 | ||
|
|
1dc056f265 | ||
|
|
28ae0f9bba | ||
|
|
ef74176810 | ||
|
|
b4ff6c4578 | ||
|
|
cbff29908b | ||
|
|
210faebfba | ||
|
|
e528dc9c10 | ||
|
|
377d7094f5 |
@ -37,16 +37,18 @@ steps:
|
||||
parameters:
|
||||
WorkingDirectory: ${{ parameters.SourceRootPath }}
|
||||
|
||||
- task: Powershell@2
|
||||
- task: AzureCLI@2
|
||||
inputs:
|
||||
filePath: ${{ parameters.SourceRootPath }}/eng/common/scripts/Create-APIReview.ps1
|
||||
azureSubscription: 'APIView prod deployment'
|
||||
scriptType: pscore
|
||||
scriptLocation: scriptPath
|
||||
scriptPath: ${{ parameters.SourceRootPath }}/eng/common/scripts/Create-APIReview.ps1
|
||||
# PackageInfoFiles example: @('a/file1.json','a/file2.json')
|
||||
arguments: >
|
||||
-PackageInfoFiles @('${{ join(''',''', parameters.PackageInfoFiles) }}')
|
||||
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name)
|
||||
-ArtifactPath '${{parameters.ArtifactPath}}'
|
||||
-ArtifactName ${{ parameters.ArtifactName }}
|
||||
-APIKey '$(azuresdk-apiview-apikey)'
|
||||
-PackageName '${{parameters.PackageName}}'
|
||||
-SourceBranch '$(Build.SourceBranchName)'
|
||||
-DefaultBranch '$(DefaultBranch)'
|
||||
@ -54,7 +56,6 @@ steps:
|
||||
-BuildId '$(Build.BuildId)'
|
||||
-RepoName '$(Build.Repository.Name)'
|
||||
-MarkPackageAsShipped $${{parameters.MarkPackageAsShipped}}
|
||||
pwsh: true
|
||||
displayName: Create API Review
|
||||
condition: >-
|
||||
and(
|
||||
|
||||
@ -4,15 +4,13 @@ Param (
|
||||
[array] $ArtifactList,
|
||||
[Parameter(Mandatory=$True)]
|
||||
[string] $ArtifactPath,
|
||||
[Parameter(Mandatory=$True)]
|
||||
[string] $APIKey,
|
||||
[string] $SourceBranch,
|
||||
[string] $DefaultBranch,
|
||||
[string] $RepoName,
|
||||
[string] $BuildId,
|
||||
[string] $PackageName = "",
|
||||
[string] $ConfigFileDir = "",
|
||||
[string] $APIViewUri = "https://apiview.dev/AutoReview",
|
||||
[string] $APIViewUri = "https://apiview.dev/autoreview",
|
||||
[string] $ArtifactName = "packages",
|
||||
[bool] $MarkPackageAsShipped = $false,
|
||||
[Parameter(Mandatory=$False)]
|
||||
@ -20,9 +18,28 @@ Param (
|
||||
)
|
||||
|
||||
Set-StrictMode -Version 3
|
||||
|
||||
. (Join-Path $PSScriptRoot common.ps1)
|
||||
. (Join-Path $PSScriptRoot Helpers ApiView-Helpers.ps1)
|
||||
|
||||
# Get Bearer token for APIView authentication
|
||||
# In Azure DevOps, this uses the service connection's Managed Identity/Service Principal
|
||||
function Get-ApiViewBearerToken()
|
||||
{
|
||||
try {
|
||||
$tokenResponse = az account get-access-token --resource "api://apiview" --output json 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "Failed to acquire access token: $tokenResponse"
|
||||
return $null
|
||||
}
|
||||
return ($tokenResponse | ConvertFrom-Json).accessToken
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to acquire access token: $($_.Exception.Message)"
|
||||
return $null
|
||||
}
|
||||
}
|
||||
|
||||
# Submit API review request and return status whether current revision is approved or pending or failed to create review
|
||||
function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVersion, $packageType)
|
||||
{
|
||||
@ -78,9 +95,17 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer
|
||||
Write-Host "Request param, compareAllRevisions: true"
|
||||
}
|
||||
|
||||
$uri = "${APIViewUri}/UploadAutoReview"
|
||||
$uri = "${APIViewUri}/upload"
|
||||
|
||||
# Get Bearer token for authentication
|
||||
$bearerToken = Get-ApiViewBearerToken
|
||||
if (-not $bearerToken) {
|
||||
Write-Error "Failed to acquire Bearer token for APIView authentication."
|
||||
return [System.Net.HttpStatusCode]::Unauthorized
|
||||
}
|
||||
|
||||
$headers = @{
|
||||
"ApiKey" = $apiKey;
|
||||
"Authorization" = "Bearer $bearerToken";
|
||||
"content-type" = "multipart/form-data"
|
||||
}
|
||||
|
||||
@ -115,20 +140,28 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review
|
||||
if($MarkPackageAsShipped) {
|
||||
$params += "&setReleaseTag=true"
|
||||
}
|
||||
$uri = "${APIViewUri}/CreateApiReview?${params}"
|
||||
$uri = "${APIViewUri}/create?${params}"
|
||||
if ($releaseStatus -and ($releaseStatus -ne "Unreleased"))
|
||||
{
|
||||
$uri += "&compareAllRevisions=true"
|
||||
}
|
||||
|
||||
Write-Host "Request to APIView: $uri"
|
||||
|
||||
# Get Bearer token for authentication
|
||||
$bearerToken = Get-ApiViewBearerToken
|
||||
if (-not $bearerToken) {
|
||||
Write-Error "Failed to acquire Bearer token for APIView authentication."
|
||||
return [System.Net.HttpStatusCode]::Unauthorized
|
||||
}
|
||||
|
||||
$headers = @{
|
||||
"ApiKey" = $APIKey;
|
||||
"Authorization" = "Bearer $bearerToken"
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$Response = Invoke-WebRequest -Method 'GET' -Uri $uri -Headers $headers
|
||||
$Response = Invoke-WebRequest -Method 'POST' -Uri $uri -Headers $headers
|
||||
Write-Host "API review: $($Response.Content)"
|
||||
$StatusCode = $Response.StatusCode
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user