Skip to content
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

Added CMDLET to delete workitem #209

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c0ebf04
added team name to _buildRequestURI and _callAPI
SebastianSchuetze Oct 3, 2019
17846e6
added Wiql types
SebastianSchuetze Oct 3, 2019
1d18f39
added format files
SebastianSchuetze Oct 3, 2019
64bc1dd
added new cmdlet for querying workitems by WIQL
SebastianSchuetze Oct 3, 2019
c2433b6
added unit tests for wiql cmdlet
SebastianSchuetze Oct 3, 2019
4769c10
bug fix for wiql cmdlet
SebastianSchuetze Oct 3, 2019
ad025ba
added documentation for wiql cdmlet
SebastianSchuetze Oct 3, 2019
bd20325
fixed include link
SebastianSchuetze Oct 3, 2019
5b2c97e
removed unsued variable
SebastianSchuetze Oct 3, 2019
5211cf5
commented debug logging
SebastianSchuetze Oct 3, 2019
ed3ba28
uncommented debugging
SebastianSchuetze Oct 3, 2019
13d6219
fixed unit test
SebastianSchuetze Oct 4, 2019
2d6ccd5
unit test fix
SebastianSchuetze Oct 6, 2019
fd8a743
Merge remote-tracking branch 'origin/master' into topic/GetWorkItemsB…
SebastianSchuetze Oct 18, 2019
9bcaac9
PERF: optimized merging of returned work items
SebastianSchuetze Oct 19, 2019
ceb0edc
added formats for workitem deletion cmdlet
SebastianSchuetze Oct 19, 2019
ee3ed91
added type for workitem deletion cmdlet
SebastianSchuetze Oct 19, 2019
e126a25
added documentation for workitem deletion cmdlet
SebastianSchuetze Oct 19, 2019
daae137
added type conversion for workitem deletion cmdlet
SebastianSchuetze Oct 19, 2019
b416321
added workitem deletion cmdlet
SebastianSchuetze Oct 19, 2019
1e64504
added missing headings in documentation
SebastianSchuetze Oct 19, 2019
ddce1e6
updated cmdlet synopsis
SebastianSchuetze Oct 20, 2019
a64de84
improved cmdlet to throw exceptions
SebastianSchuetze Oct 20, 2019
e93d98b
added unit tests for cmdlet
SebastianSchuetze Oct 20, 2019
9a9f0b0
updated changelog and module version
SebastianSchuetze Oct 20, 2019
c2329b3
Merge branch 'master' into topic/RemoveWorkItemsByIds
DarqueWarrior Nov 6, 2019
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
85 changes: 85 additions & 0 deletions .docs/Remove-VSTeamWorkItem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!-- #include "./common/header.md" -->

# Remove-VSTeamWorkItem

## SYNOPSIS

<!-- #include "./synopsis/Remove-VSTeamWorkItem.md" -->

## SYNTAX

## DESCRIPTION

<!-- #include "./synopsis/Remove-VSTeamWorkItem.md" -->

## EXAMPLES

### -------------------------- EXAMPLE 1 --------------------------

```PowerShell
PS C:\> Remove-VSTeamWorkItem -Ids 47,48
```

This command deletes work items with IDs 47 and 48 by using the IDs parameter.

### -------------------------- EXAMPLE 2 --------------------------

```PowerShell
PS C:\> Remove-VSTeamWorkItem -Id 47
```

This command deletes the work item with ID 47 by using the ID parameter.

### -------------------------- EXAMPLE 3 --------------------------

```PowerShell
PS C:\> Remove-VSTeamWorkItem -Ids 47 -Destroy
```

This command deletes work item with IDs 47 **permanently** by using the Destroy parameter.

## PARAMETERS

### -Id

The id of the work item.

```yaml
Type: Int32
Parameter Sets: ByID
Required: True
Accept pipeline input: true (ByPropertyName, ByValue)
```

### -Ids

The id of the work item.

```yaml
Type: Int32[]
Parameter Sets: List
Required: True
Accept pipeline input: true (ByPropertyName, ByValue)
```

### -Destroy

Optional parameter, if set to true, the work item is deleted permanently. **Please note: the destroy action is PERMANENT and cannot be undone.**

```yaml
Type: Switch
```

## INPUTS

### System.String

ProjectName

## OUTPUTS

## NOTES

If you do not set the default project by called Set-VSTeamDefaultProject before calling Get-VSTeamWorkItem you will have to type in the names.

## RELATED LINKS
1 change: 1 addition & 0 deletions .docs/synopsis/Remove-VSTeamWorkItem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deletes the specified work item and sends it to the Recycle Bin, so that it can be restored back, if required. Optionally, if the destroy parameter has been set to true, it destroys the work item permanently. WARNING: If the destroy parameter is set to true, work items deleted by this command will NOT go to recycle-bin and there is no way to restore/recover them after deletion. It is recommended NOT to use this parameter. If you do, please use this parameter with extreme caution.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 6.4.0

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/209) from [Sebastian Schütze](https://github.com/SebastianSchuetze) which included the following:

Added Remove-VSTeamWorkItem to delete work items

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/204) from [Jeroen Janssen](https://github.com/japj) which included the following:

add maxParallelism to Disable/Enable-VSTeamAgent
Expand Down
6 changes: 6 additions & 0 deletions Source/Private/applyTypes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function _applyTypesToWorkItem {
}
}

function _applyTypesToWorkItemDeleted {
param($item)
$item.PSObject.TypeNames.Insert(0, 'Team.WorkItemDeleted')
$item.resource.PSObject.TypeNames.Insert(0,'Team.WorkItem')
}

function _applyTypesToWiql {
param($item)
if ($item) {
Expand Down
50 changes: 50 additions & 0 deletions Source/Public/Remove-VSTeamWorkItem.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function Remove-VSTeamWorkItem {
[CmdletBinding(DefaultParameterSetName = 'ByID')]
param(
[Parameter(ParameterSetName = 'ByID', Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
[int] $Id,

[Parameter(ParameterSetName = 'List', Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
[int[]] $Ids,

[switch] $Destroy
)

Process {
# Call the REST API

$idsToDelete = @()

if ($PSCmdlet.ParameterSetName -eq "List") {

if($null -eq $Ids) {
throw "No Ids given, array was null"
}

$idsToDelete = $Ids
}
else {

# work item IDs in AzD cannot be lower than 1. First work item id is always 1.
if($Id -lt 1) {
throw "given work item Id has to be greater than 0"
}

$idsToDelete = @($id[0])
}

$deletedWorkItems = foreach ($wiId in $idsToDelete) {
$resp = _callAPI -Method "DELETE" -Area 'wit' -Resource 'workitems' `
-Version $([VSTeamVersions]::Core) -id "$wiId" `
-Querystring @{
destroy = $Destroy
}

_applyTypesToWorkItemDeleted -item $resp

$resp
}

return $deletedWorkItems
}
}
34 changes: 34 additions & 0 deletions Source/formats/Team.WorkItemDeleted.ListView.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>Team.WorkItemDeleted.ListView</Name>
<ViewSelectedBy>
<TypeName>Team.WorkItemDeleted</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<PropertyName>id</PropertyName>
</ListItem>
<ListItem>
<PropertyName>name</PropertyName>
</ListItem>
<ListItem>
<PropertyName>deletedBy</PropertyName>
</ListItem>
<ListItem>
<PropertyName>deletedDate</PropertyName>
</ListItem>
<ListItem>
<PropertyName>code</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
51 changes: 51 additions & 0 deletions Source/formats/Team.WorkItemDeleted.TableView.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>Team.WorkItemDeleted.TableView</Name>
<ViewSelectedBy>
<TypeName>Team.WorkItemDeleted</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>ID</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Name</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>DeletedBy</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>DeletedDate</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Code</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>deletedBy</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>deletedDate</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>code</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
2 changes: 2 additions & 0 deletions Source/formats/_formats.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
"Team.Wiql.ListView.ps1xml",
"Team.WorkItem.TableView.ps1xml",
"Team.WorkItem.ListView.ps1xml",
"Team.WorkItemDeleted.TableView.ps1xml",
"Team.WorkItemDeleted.ListView.ps1xml",
"Team.JobRequest.TableView.ps1xml"
]
}
59 changes: 59 additions & 0 deletions Source/types/Team.WorkItemDeleted.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>Team.WorkItemDeleted</Name>
<Members>
<ScriptProperty>
<Name>Name</Name>
<GetScriptBlock>$this.fields.PSObject.Properties['name'].Value</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Project</Name>
<GetScriptBlock>$this.fields.PSObject.Properties['project'].Value</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Type</Name>
<GetScriptBlock>$this.fields.PSObject.Properties['type'].Value</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Id</Name>
<GetScriptBlock>$this.fields.PSObject.Properties['id'].Value</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Resource</Name>
<GetScriptBlock>$this.fields.PSObject.Properties['resource'].Value</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>DeletedBy</Name>
<GetScriptBlock>$this.fields.PSObject.Properties['deletedBy'].Value</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>DeletedDate</Name>
<GetScriptBlock>$this.fields.PSObject.Properties['deletedDate'].Value</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Code</Name>
<GetScriptBlock>$this.fields.PSObject.Properties['code'].Value</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Url</Name>
<GetScriptBlock>$this.fields.PSObject.Properties['url'].Value</GetScriptBlock>
</ScriptProperty>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>id</Name>
<Name>name</Name>
<Name>deletedBy</Name>
<Name>deletedDate</Name>
<Name>code</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
</Members>
</Type>
</Types>
4 changes: 2 additions & 2 deletions unit/test/wiql.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ InModuleScope VSTeam {
asOf = "2019-10-03T18:35:09.117Z"
columns = @($column)
sortColumns = @($sortColumn)
workItems = @($workItem, $workItem)
workItems = @($workItem, $workItem)
}

$expandedWorkItems = @{
count = 1
value = @($workItem, $workItem)
value = @($workItem, $workItem)
}

Context 'Get-Wiql' {
Expand Down
Loading