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 <chononiw@microsoft.com>
This commit is contained in:
Azure SDK Bot 2025-05-06 09:31:04 -07:00 committed by GitHub
parent 6e242c11c2
commit 1c4d8ebb4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
}
}
}
}