-
Notifications
You must be signed in to change notification settings - Fork 142
Sync eng/common directory with azure-sdk-tools for PR 12891 #6828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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-AzBoardsCmdto check command exit codes and log failures - Added
CheckUserfunction to validate Azure DevOps users before work item assignment - Integrated user validation into
CreateWorkItemandUpdateWorkItemto prevent assignment failures
| $response = Invoke-Expression "$azCmdStr" | ConvertFrom-Json -AsHashtable | ||
|
|
||
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Host "ERROR command failed: $azCmdStr" |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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.
| Write-Host "ERROR command failed: $azCmdStr" | |
| Write-Host "ERROR command failed: $azCmdStr" | |
| return $null |
| $response = Invoke-Expression "$azCmdStr" | ConvertFrom-Json -AsHashtable | ||
|
|
||
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Host "ERROR command failed: $azCmdStr" |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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."
| 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." |
| 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 | ||
| } |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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.
| $azCmdStr = "az devops user show --user ${user} $($ReleaseDevOpsCommonParameters -join ' ')" | ||
| Invoke-Expression "$azCmdStr" | Out-Null |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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.
| $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 |
| $azCmdStr = "az devops user show --user ${user} $($ReleaseDevOpsCommonParameters -join ' ')" | ||
| Invoke-Expression "$azCmdStr" | Out-Null | ||
|
|
||
| if ($LASTEXITCODE -ne 0) { |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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.
| if ($LASTEXITCODE -ne 0) { | |
| if (-not $?) { |
| $parameters += "--area", "`"${area}`"" | ||
| if ($assignedTo) { | ||
| if ($assignedTo -and (CheckUser $assignedTo)) { | ||
| $parameters += "--assigned-to", "`"${assignedTo}`"" |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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."
| $parameters += "--assigned-to", "`"${assignedTo}`"" | |
| $parameters += "--assigned-to", "`"${assignedTo}`"" | |
| } elseif ($assignedTo) { | |
| Write-Warning "Warning: User '$assignedTo' not found in Azure DevOps. Skipping assignment." |
| if ($assignedTo -and (CheckUser $assignedTo)) { | ||
| $parameters += "--assigned-to", "`"${assignedTo}`"" | ||
| } |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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."
| 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 | ||
| } |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
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.
Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#12891 See eng/common workflow