Skip to content

Conversation

@azure-sdk
Copy link
Collaborator

Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#12891 See eng/common workflow

Copilot AI review requested due to automatic review settings November 13, 2025 23:36
@azure-sdk azure-sdk requested a review from a team as a code owner November 13, 2025 23:36
@azure-sdk azure-sdk requested a review from weshaggard November 13, 2025 23:36
@azure-sdk azure-sdk added EngSys This issue is impacting the engineering system. Central-EngSys This issue is owned by the Engineering System team. labels Nov 13, 2025
Copilot finished reviewing on behalf of azure-sdk November 13, 2025 23:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR syncs the eng/common directory with changes from azure-sdk-tools PR #12891, adding user validation and improving error handling in DevOps work item helper functions.

  • Enhanced error handling in Invoke-AzBoardsCmd to check command exit codes and log failures
  • Added CheckUser function to validate Azure DevOps users before work item assignment
  • Integrated user validation into CreateWorkItem and UpdateWorkItem to prevent assignment failures

$response = Invoke-Expression "$azCmdStr" | ConvertFrom-Json -AsHashtable

if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR command failed: $azCmdStr"
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The error handling in Invoke-AzBoardsCmd captures the response before checking $LASTEXITCODE, but still returns the response even when the command fails. This could lead to callers processing invalid or null responses. Consider either throwing an exception on failure or returning $null to make the error condition explicit to callers.

Suggested change
Write-Host "ERROR command failed: $azCmdStr"
Write-Host "ERROR command failed: $azCmdStr"
return $null

Copilot uses AI. Check for mistakes.
$response = Invoke-Expression "$azCmdStr" | ConvertFrom-Json -AsHashtable

if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR command failed: $azCmdStr"
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The error message "ERROR command failed: $azCmdStr" provides minimal context about why the command failed or what action to take. Consider enhancing this message to include the exit code and guidance, e.g., "ERROR: Azure DevOps command failed with exit code $LASTEXITCODE: $azCmdStr. Please check your Azure DevOps permissions and connection."

Suggested change
Write-Host "ERROR command failed: $azCmdStr"
Write-Host "ERROR: Azure DevOps command failed with exit code $LASTEXITCODE: $azCmdStr. Please check your Azure DevOps permissions and connection."

Copilot uses AI. Check for mistakes.
Comment on lines +368 to +378
function CheckUser($user)
{
$azCmdStr = "az devops user show --user ${user} $($ReleaseDevOpsCommonParameters -join ' ')"
Invoke-Expression "$azCmdStr" | Out-Null

if ($LASTEXITCODE -ne 0) {
return $false
}

return $true
}
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The CheckUser function lacks documentation explaining its purpose, parameters, and return values. Consider adding a comment block to document that this function validates whether a user exists in Azure DevOps, accepts a user identifier as a parameter, and returns a boolean indicating user existence. This would improve maintainability and help other developers understand when and how to use this function.

Copilot uses AI. Check for mistakes.
Comment on lines +370 to +371
$azCmdStr = "az devops user show --user ${user} $($ReleaseDevOpsCommonParameters -join ' ')"
Invoke-Expression "$azCmdStr" | Out-Null
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The $user parameter in the CheckUser function is directly interpolated into the command string without proper escaping or validation. If the user parameter contains special characters, spaces, or quotes, this could lead to command injection vulnerabilities or command execution failures. Consider either adding quotes around ${user} (e.g., --user "${user}") or using a parameter array approach similar to other functions in this file for safer command construction.

Suggested change
$azCmdStr = "az devops user show --user ${user} $($ReleaseDevOpsCommonParameters -join ' ')"
Invoke-Expression "$azCmdStr" | Out-Null
$parameters = $ReleaseDevOpsCommonParameters + @("--user", $user)
az devops user show @parameters | Out-Null

Copilot uses AI. Check for mistakes.
$azCmdStr = "az devops user show --user ${user} $($ReleaseDevOpsCommonParameters -join ' ')"
Invoke-Expression "$azCmdStr" | Out-Null

if ($LASTEXITCODE -ne 0) {
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The CheckUser function suppresses all output with Out-Null but then relies on checking $LASTEXITCODE. This pattern can be fragile because $LASTEXITCODE is a global variable that could be modified by other commands. Consider capturing the result or using PowerShell's $? automatic variable immediately after the Invoke-Expression to check success/failure more reliably, or restructure to use proper error handling with try-catch blocks.

Suggested change
if ($LASTEXITCODE -ne 0) {
if (-not $?) {

Copilot uses AI. Check for mistakes.
$parameters += "--area", "`"${area}`""
if ($assignedTo) {
if ($assignedTo -and (CheckUser $assignedTo)) {
$parameters += "--assigned-to", "`"${assignedTo}`""
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

When CheckUser returns false (user doesn't exist), the work item assignment is silently skipped without any warning or logging. This could lead to confusion when work items are created/updated without the expected assignee. Consider adding a Write-Warning or Write-Host message to inform the user that the assignment was skipped due to an invalid user, e.g., "Warning: User '$assignedTo' not found in Azure DevOps. Skipping assignment."

Suggested change
$parameters += "--assigned-to", "`"${assignedTo}`""
$parameters += "--assigned-to", "`"${assignedTo}`""
} elseif ($assignedTo) {
Write-Warning "Warning: User '$assignedTo' not found in Azure DevOps. Skipping assignment."

Copilot uses AI. Check for mistakes.
Comment on lines +444 to 446
if ($assignedTo -and (CheckUser $assignedTo)) {
$parameters += "--assigned-to", "`"${assignedTo}`""
}
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

When CheckUser returns false (user doesn't exist), the work item assignment is silently skipped without any warning or logging. This could lead to confusion when work items are updated without the expected assignee change. Consider adding a Write-Warning or Write-Host message to inform the user that the assignment was skipped due to an invalid user, e.g., "Warning: User '$assignedTo' not found in Azure DevOps. Skipping assignment."

Copilot uses AI. Check for mistakes.
Comment on lines +368 to +378
function CheckUser($user)
{
$azCmdStr = "az devops user show --user ${user} $($ReleaseDevOpsCommonParameters -join ' ')"
Invoke-Expression "$azCmdStr" | Out-Null

if ($LASTEXITCODE -ne 0) {
return $false
}

return $true
}
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The CheckUser function makes an Azure DevOps API call every time it's invoked. In scenarios where multiple work items are created or updated with the same assignee, this results in redundant API calls. Consider implementing a caching mechanism (e.g., a module-level hashtable) to store validated users and avoid repeated validation calls for the same user within a session, improving performance in bulk operations.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Central-EngSys This issue is owned by the Engineering System team. EngSys This issue is impacting the engineering system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants