Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
11 changes: 10 additions & 1 deletion eng/common/scripts/Detect-Api-Changes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a 'Content-Type' header on a GET request is misleading—consider replacing it with an 'Accept: application/json' header or removing it entirely.

Suggested change
"Content-Type" = "application/json"
"Accept" = "application/json"

Copilot uses AI. Check for mistakes.

"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
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] LogSuccess only outputs the JSON body. Including the HTTP status code in this log would make troubleshooting easier and consistent with other calls.

Suggested change
LogSuccess $responseContent
LogSuccess "Status Code: $StatusCode, Response: $responseContent"

Copilot uses AI. Check for mistakes.

}
catch
{
Expand Down
14 changes: 11 additions & 3 deletions eng/common/scripts/Helpers/ApiView-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
Comment on lines +281 to +285
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Variable casing is inconsistent—$Response vs $response. Unifying on one spelling improves readability and reduces potential confusion.

Copilot uses AI. Check for mistakes.

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)"
Expand Down
Loading