-
Notifications
You must be signed in to change notification settings - Fork 1
Enhanced Stop-Task with progress bar and array support #17
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -266,10 +266,29 @@ class TaskSingleTransformation : System.Management.Automation.ArgumentTransforma | |
| if ($item -is [string] -and $item -like "ServerTasks-*") { | ||
| $item = Get-Task -TaskID "$item" | ||
| } | ||
| elseif ($item -is [string]) { | ||
| $item = $null | ||
| elseif ($item -is [Octopus.Client.Model.TaskResource]) { | ||
| return $item | ||
| } | ||
| return ($item) | ||
| throw "Invalid Task input: $($item.toString())" | ||
| } | ||
| } | ||
|
|
||
| class TaskTransformation : System.Management.Automation.ArgumentTransformationAttribute { | ||
| [object] Transform([System.Management.Automation.EngineIntrinsics]$EngineIntrinsics, [object] $InputData) { | ||
| $result = @() | ||
| foreach ($item in $InputData) { | ||
| if ($item -is [string] -and $item -like "ServerTasks-*") { | ||
| $item = Get-Task -TaskID "$item" | ||
| } | ||
| elseif ($item -is [Octopus.Client.Model.TaskResource]) { | ||
| # Already a TaskResource, keep it | ||
| } | ||
|
Comment on lines
+283
to
+285
|
||
| else { | ||
| throw "Invalid Task input: $($item.toString())" | ||
| } | ||
| $result += ($item) | ||
| } | ||
| return ($result) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,10 +32,10 @@ function Stop-Task { | |||||
| [CmdletBinding()] | ||||||
| param ( | ||||||
| [Parameter(Mandatory = $false, | ||||||
| ValueFromPipelineByPropertyName = $true, | ||||||
| ValueFromPipeline = $true, | ||||||
| ParameterSetName = 'byTask')] | ||||||
| [TaskSingleTransformation()] | ||||||
| [Octopus.Client.Model.TaskResource] | ||||||
| [TaskTransformation()] | ||||||
| [Octopus.Client.Model.TaskResource[]] | ||||||
| $Task, | ||||||
|
|
||||||
| [Parameter(Mandatory = $false, | ||||||
|
|
@@ -57,7 +57,6 @@ function Stop-Task { | |||||
| $Environment, | ||||||
|
|
||||||
| [Parameter(Mandatory = $false, | ||||||
| ValueFromPipeline = $true, | ||||||
| ParameterSetName = 'byRegarding')] | ||||||
| [ValidateNotNullOrEmpty()] | ||||||
| [Octopus.Client.Model.Resource] | ||||||
|
|
@@ -77,35 +76,55 @@ function Stop-Task { | |||||
| $PSCmdlet.ThrowTerminatingError($_) | ||||||
| } | ||||||
|
|
||||||
| # Initialize counter for progress | ||||||
| $taskCounter = 0 | ||||||
| $allTasks = @() | ||||||
| } | ||||||
|
|
||||||
| process { | ||||||
| # Initialize an empty array to store tasks to cancel | ||||||
| $tasksToCancel = @() | ||||||
|
Comment on lines
85
to
86
|
||||||
|
|
||||||
| # Combine states into a regex pattern | ||||||
| $stateRegex = ($State -join '|') -replace ' ', '' | ||||||
|
Comment on lines
88
to
89
|
||||||
| } | ||||||
|
|
||||||
| process { | ||||||
|
|
||||||
| # Check the parameter set name to determine how to retrieve tasks | ||||||
| if ($PSCmdlet.ParameterSetName -eq 'byTask') { | ||||||
| # Cancel a specific task | ||||||
| $tasksToCancel += $Task | ||||||
| $tasksToCancel = $Task | ||||||
| } | ||||||
| elseif ($PSCmdlet.ParameterSetName -eq 'byRegarding') { | ||||||
| # Cancel tasks regarding a specific object | ||||||
| foreach ($r in $Regarding) { | ||||||
| $tasksToCancel += Get-Task -Regarding $r | Where-Object { $_.State -match $stateRegex } | ||||||
| $tasksToCancel = Get-Task -Regarding $r | Where-Object { $_.State -match $stateRegex } | ||||||
|
||||||
| $tasksToCancel = Get-Task -Regarding $r | Where-Object { $_.State -match $stateRegex } | |
| $tasksToCancel += Get-Task -Regarding $r | Where-Object { $_.State -match $stateRegex } |
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 TaskSingleTransformation class now throws an exception for string inputs that don't match the "ServerTasks-*" pattern, whereas the previous implementation returned
$null. This is a breaking change that could cause errors in existing code that previously handled null returns gracefully. Consider whether this breaking change is intentional and necessary.