diff --git a/eng/common/pipelines/templates/steps/detect-api-changes.yml b/eng/common/pipelines/templates/steps/detect-api-changes.yml index 2525dade5205..573a23c1979d 100644 --- a/eng/common/pipelines/templates/steps/detect-api-changes.yml +++ b/eng/common/pipelines/templates/steps/detect-api-changes.yml @@ -24,5 +24,5 @@ steps: -ArtifactName ${{ parameters.ArtifactName }} -DevopsProject $(System.TeamProject) pwsh: true - displayName: Detect API changes + displayName: Create APIView if API has changes condition: and(${{ parameters.Condition }}, succeededOrFailed(), eq(variables['Build.Reason'],'PullRequest')) diff --git a/eng/common/scripts/Detect-Api-Changes.ps1 b/eng/common/scripts/Detect-Api-Changes.ps1 index 6be93332118c..9556d6d52848 100644 --- a/eng/common/scripts/Detect-Api-Changes.ps1 +++ b/eng/common/scripts/Detect-Api-Changes.ps1 @@ -55,11 +55,20 @@ function Submit-Request($filePath, $packageName) } $uri = [System.UriBuilder]$APIViewUri $uri.query = $query.toString() + + $correlationId = [System.Guid]::NewGuid().ToString() + $headers = @{ + "Content-Type" = "application/json" + "x-correlation-id" = $correlationId + } LogInfo "Request URI: $($uri.Uri.OriginalString)" + LogInfo "Correlation ID: $correlationId" try { - $Response = Invoke-WebRequest -Method 'GET' -Uri $uri.Uri -MaximumRetryCount 3 + $Response = Invoke-WebRequest -Method 'GET' -Uri $uri.Uri -Headers $headers -MaximumRetryCount 3 $StatusCode = $Response.StatusCode + $responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10 + LogSuccess $responseContent } catch { diff --git a/eng/common/scripts/Helpers/ApiView-Helpers.ps1 b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 index af5335a98def..126d1f02cdf7 100644 --- a/eng/common/scripts/Helpers/ApiView-Helpers.ps1 +++ b/eng/common/scripts/Helpers/ApiView-Helpers.ps1 @@ -168,10 +168,16 @@ function Set-ApiViewCommentForPR { $apiviewEndpoint = "$APIViewHost/api/pullrequests?pullRequestNumber=$PrNumber&repoName=$repoFullName&commitSHA=$HeadCommitish" LogDebug "Get APIView information for PR using endpoint: $apiviewEndpoint" + $correlationId = [System.Guid]::NewGuid().ToString() + $headers = @{ + "x-correlation-id" = $correlationId + } + LogInfo "Correlation ID: $correlationId" + $commentText = @() $commentText += "## API Change Check" try { - $response = Invoke-WebRequest -Uri $apiviewEndpoint -Method Get -MaximumRetryCount 3 + $response = Invoke-WebRequest -Uri $apiviewEndpoint -Method Get -Headers $headers -MaximumRetryCount 3 LogInfo "OperationId: $($response.Headers['X-Operation-Id'])" if ($response.StatusCode -ne 200) { LogInfo "API changes are not detected in this pull request." @@ -272,10 +278,12 @@ function Create-API-Review { { $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)" + $responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10 + LogSuccess "Status Code: $($response.StatusCode)`nAPI review request created successfully.`n$($responseContent)" } elseif ($response.StatusCode -eq 208) { - LogSuccess "Status Code: $($response.StatusCode)`nThere is no API change compared with the previous version." + $responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10 + LogSuccess "Status Code: $($response.StatusCode)`nThere is no API change compared with the previous version.`n$($responseContent)" } else { LogError "Failed to create API review request. $($response)"