1+ . ${PSScriptRoot} \..\logging.ps1
2+
13function MapLanguageToRequestParam ($language )
24{
35 $lang = $language
@@ -230,11 +232,60 @@ function Set-ApiViewCommentForPR {
230232 }
231233}
232234
233- function Save-PackageProperties ($repoRoot , $serviceNames , $outputDirectory ) {
234- $scriptPath = Join-Path $repoRoot " eng" " common" " scripts" " Save-Package-Properties.ps1"
235- $serviceDirectories = $serviceNames -split " ,"
235+ # Helper function used to create API review requests for Spec generation SDKs pipelines
236+ function Create-API-Review {
237+ param (
238+ [string ]$apiviewEndpoint = " https://apiview.dev/PullRequest/DetectAPIChanges" ,
239+ [string ]$specGenSDKArtifactPath ,
240+ [string ]$apiviewArtifactName ,
241+ [string ]$buildId ,
242+ [string ]$commitish ,
243+ [string ]$repoName ,
244+ [string ]$pullRequestNumber
245+ )
246+ $specGenSDKContent = Get-Content - Path $SpecGenSDKArtifactPath - Raw | ConvertFrom-Json
247+ $language = ($specGenSDKContent.language -split " -" )[-1 ]
248+
249+ foreach ($requestData in $specGenSDKContent.apiViewRequestData ) {
250+ $requestUri = [System.UriBuilder ]$apiviewEndpoint
251+ $requestParam = [System.Web.HttpUtility ]::ParseQueryString(' ' )
252+ $requestParam.Add (' artifactName' , $apiviewArtifactName )
253+ $requestParam.Add (' buildId' , $buildId )
254+ $requestParam.Add (' commitSha' , $commitish )
255+ $requestParam.Add (' repoName' , $repoName )
256+ $requestParam.Add (' pullRequestNumber' , $pullRequestNumber )
257+ $requestParam.Add (' packageName' , $requestData.packageName )
258+ $requestParam.Add (' filePath' , $requestData.filePath )
259+ $requestParam.Add (' language' , $language )
260+ $requestUri.query = $requestParam.toString ()
261+ $correlationId = [System.Guid ]::NewGuid().ToString()
262+
263+ $headers = @ {
264+ " Content-Type" = " application/json"
265+ " x-correlation-id" = $correlationId
266+ }
267+
268+ LogInfo " Request URI: $ ( $requestUri.Uri.OriginalString ) "
269+ LogInfo " Correlation ID: $correlationId "
236270
237- foreach ($serviceDirectory in $serviceDirectories ) {
238- & $scriptPath - ServiceDirectory $serviceDirectory.Trim () - OutDirectory $outputDirectory
271+ try
272+ {
273+ $response = Invoke-WebRequest - Method ' GET' - Uri $requestUri.Uri - Headers $headers - MaximumRetryCount 3
274+ if ($response.StatusCode -eq 201 ) {
275+ LogSuccess " Status Code: $ ( $response.StatusCode ) `n API review request created successfully.`n $ ( $response.Content ) "
276+ }
277+ elseif ($response.StatusCode -eq 208 ) {
278+ LogSuccess " Status Code: $ ( $response.StatusCode ) `n There is no API change compared with the previous version."
279+ }
280+ else {
281+ LogError " Failed to create API review request. $ ( $response ) "
282+ exit 1
283+ }
284+ }
285+ catch
286+ {
287+ LogError " Error : $ ( $_.Exception ) "
288+ exit 1
289+ }
239290 }
240- }
291+ }
0 commit comments