From 1c4d8ebb4b9eb2f7c1b4cb8e6a3d8f27d2015224 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Tue, 6 May 2025 09:31:04 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 10534 (#6560) * Add helper function for spec-gen-sdk pipeline * Move logging script sourceing to global scope --------- Co-authored-by: Chidozie Ononiwu --- .../scripts/Helpers/ApiView-Helpers.ps1 | 63 +++++++++++++++++-- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/eng/common/scripts/Helpers/ApiView-Helpers.ps1 b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 index a05ca868d..2fd9f609f 100644 --- a/eng/common/scripts/Helpers/ApiView-Helpers.ps1 +++ b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 @@ -1,3 +1,5 @@ +. ${PSScriptRoot}\..\logging.ps1 + function MapLanguageToRequestParam($language) { $lang = $language @@ -230,11 +232,60 @@ function Set-ApiViewCommentForPR { } } -function Save-PackageProperties ($repoRoot, $serviceNames, $outputDirectory) { - $scriptPath = Join-Path $repoRoot "eng" "common" "scripts" "Save-Package-Properties.ps1" - $serviceDirectories = $serviceNames -split "," +# Helper function used to create API review requests for Spec generation SDKs pipelines +function Create-API-Review { + param ( + [string]$apiviewEndpoint = "https://apiview.dev/PullRequest/DetectAPIChanges", + [string]$specGenSDKArtifactPath, + [string]$apiviewArtifactName, + [string]$buildId, + [string]$commitish, + [string]$repoName, + [string]$pullRequestNumber + ) + $specGenSDKContent = Get-Content -Path $SpecGenSDKArtifactPath -Raw | ConvertFrom-Json + $language = ($specGenSDKContent.language -split "-")[-1] + + foreach ($requestData in $specGenSDKContent.apiViewRequestData) { + $requestUri = [System.UriBuilder]$apiviewEndpoint + $requestParam = [System.Web.HttpUtility]::ParseQueryString('') + $requestParam.Add('artifactName', $apiviewArtifactName) + $requestParam.Add('buildId', $buildId) + $requestParam.Add('commitSha', $commitish) + $requestParam.Add('repoName', $repoName) + $requestParam.Add('pullRequestNumber', $pullRequestNumber) + $requestParam.Add('packageName', $requestData.packageName) + $requestParam.Add('filePath', $requestData.filePath) + $requestParam.Add('language', $language) + $requestUri.query = $requestParam.toString() + $correlationId = [System.Guid]::NewGuid().ToString() - foreach ($serviceDirectory in $serviceDirectories) { - & $scriptPath -ServiceDirectory $serviceDirectory.Trim() -OutDirectory $outputDirectory + $headers = @{ + "Content-Type" = "application/json" + "x-correlation-id" = $correlationId + } + + LogInfo "Request URI: $($requestUri.Uri.OriginalString)" + LogInfo "Correlation ID: $correlationId" + + try + { + $response = Invoke-WebRequest -Method 'GET' -Uri $requestUri.Uri -Headers $headers -MaximumRetryCount 3 + if ($response.StatusCode -eq 201) { + LogSuccess "Status Code: $($response.StatusCode)`nAPI review request created successfully.`n$($response.Content)" + } + elseif ($response.StatusCode -eq 208) { + LogSuccess "Status Code: $($response.StatusCode)`nThere is no API change compared with the previous version." + } + else { + LogError "Failed to create API review request. $($response)" + exit 1 + } + } + catch + { + LogError "Error : $($_.Exception)" + exit 1 + } } -} +} \ No newline at end of file