-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Undo-TfsWorkItemQuery[Folder]Removal (#196)
* Fix retrieval of deleted items * Add new cmdlets * Update release notes +semver: minor
- Loading branch information
Showing
7 changed files
with
179 additions
and
12 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
CSharp/TfsCmdlets/Cmdlets/WorkItem/Query/Folder/UndoWorkItemQueryFolderRemoval.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Management.Automation; | ||
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; | ||
|
||
namespace TfsCmdlets.Cmdlets.WorkItem.Query | ||
{ | ||
/// <summary> | ||
/// Restores a deleted work item query folder. | ||
/// </summary> | ||
[TfsCmdlet(CmdletScope.Project, SupportsShouldProcess = true, OutputType = typeof(QueryHierarchyItem))] | ||
partial class UndoWorkItemQueryFolderRemoval | ||
{ | ||
/// <summary> | ||
/// Specifies one or more query folders to restore. Wildcards supported. | ||
/// </summary> | ||
[Parameter(Position = 0, ValueFromPipeline = true, Mandatory = true)] | ||
[ValidateNotNull()] | ||
[SupportsWildcards()] | ||
[Alias("Path")] | ||
public object Folder { get; set; } | ||
|
||
/// <summary> | ||
/// Specifies the scope of the item to restore. Personal refers to the | ||
/// "My Queries" folder", whereas Shared refers to the "Shared Queries" | ||
/// folder. When omitted defaults to "Both", effectively searching for items | ||
/// in both scopes. | ||
/// </summary> | ||
[Parameter] | ||
public QueryItemScope Scope { get; set; } = QueryItemScope.Both; | ||
|
||
/// <summary> | ||
/// Restores the specified query folder and all its descendants. | ||
/// When omitted, the specified folder is restored but not its contents (queries and/or sub-folders). | ||
/// </summary> | ||
[Parameter] | ||
public SwitchParameter Recursive {get;set;} | ||
|
||
[Parameter] | ||
internal bool Deleted => true; | ||
|
||
[Parameter] | ||
internal string ItemType => "Folder"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
CSharp/TfsCmdlets/Cmdlets/WorkItem/Query/UndoWorkItemQueryRemoval.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Management.Automation; | ||
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; | ||
|
||
namespace TfsCmdlets.Cmdlets.WorkItem.Query | ||
{ | ||
/// <summary> | ||
/// Restores a deleted work item query. | ||
/// </summary> | ||
[TfsCmdlet(CmdletScope.Project, SupportsShouldProcess = true, OutputType = typeof(QueryHierarchyItem))] | ||
partial class UndoWorkItemQueryRemoval | ||
{ | ||
/// <summary> | ||
/// Specifies one or more saved queries to restore. Wildcards supported. | ||
/// </summary> | ||
[Parameter(Position = 0, ValueFromPipeline = true, Mandatory = true)] | ||
[ValidateNotNull()] | ||
[SupportsWildcards()] | ||
[Alias("Path")] | ||
public object Query { get; set; } | ||
|
||
/// <summary> | ||
/// Specifies the scope of the item to restore. Personal refers to the | ||
/// "My Queries" folder", whereas Shared refers to the "Shared Queries" | ||
/// folder. When omitted defaults to "Both", effectively searching for items | ||
/// in both scopes. | ||
/// </summary> | ||
[Parameter] | ||
public QueryItemScope Scope { get; set; } = QueryItemScope.Both; | ||
|
||
[Parameter] | ||
internal SwitchParameter Recursive => false; | ||
|
||
[Parameter] | ||
internal bool Deleted => true; | ||
|
||
[Parameter] | ||
internal string ItemType => "Query"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
CSharp/TfsCmdlets/Controllers/WorkItem/Query/UndoWorkItemQueryItemRemovalController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Xml.Linq; | ||
using Microsoft.TeamFoundation.WorkItemTracking.WebApi; | ||
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; | ||
using TfsCmdlets.Cmdlets.WorkItem.Query; | ||
|
||
namespace TfsCmdlets.Controllers.WorkItem.Query | ||
{ | ||
[CmdletController(typeof(QueryHierarchyItem))] | ||
partial class UndoWorkItemQueryRemovalController | ||
{ | ||
protected override IEnumerable Run() | ||
{ | ||
var client = GetClient<WorkItemTrackingHttpClient>(); | ||
|
||
foreach(var item in Items) | ||
{ | ||
if(!PowerShell.ShouldProcess(Project, $"Restore {ItemType} '{item.Path}'")) continue; | ||
|
||
yield return client.UpdateQueryAsync(new QueryHierarchyItem(){IsDeleted=false}, Project.Id, item.Id.ToString(), undeleteDescendants: Recursive) | ||
.GetResult($"Error restoring {ItemType} '{item.Path}'"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# TfsCmdlets Release Notes | ||
|
||
## Version 2.6.0 (_30/Sep/2022_) | ||
|
||
This release fixes a bug in `Get-TfsWorkItemQuery` and `Get-TfsWorkItemQueryFolder`, and adds two new cmdlets. | ||
|
||
## New cmdlets | ||
|
||
* `Undo-TfsWorkItemQueryRemoval` and `Undo-TfsWorkItemQueryFolderRemoval` allow you to undo the deletion of a query or query folder. This is useful when you accidentally delete a query or query folder and want to restore it. | ||
|
||
To restore a deleted query: | ||
|
||
```powershell | ||
# You can either pipe the deleted query from Get-TfsWorkItemQuery to Undo-TfsWorkItemQueryRemoval... | ||
Get-TfsWorkItemQuery 'My Deleted Query' -Scope Personal -Deleted | Undo-TfsWorkItemQueryRemoval | ||
# ... or you can specify the query directly when calling Undo-TfsWorkItemQueryRemoval | ||
Undo-TfsWorkItemQueryRemoval 'My Deleted Query' -Scope Personal | ||
``` | ||
|
||
The same applies to query folders - with the distinction that folder can be restored recursively by specifying the `-Recursive` switch. When `-Recursive` is omitted, only the folder itself is restored, without any of its contents. You can then restore its contents by issuing further calls to `Undo-TfsWorkItemQueryRemoval` and/or `Undo-TfsWorkItemQueryFolderRemoval`. | ||
|
||
```powershell | ||
# You can either pipe the deleted folder from Get-TfsWorkItemQueryFolder to Undo-TfsWorkItemQueryFolderRemoval... | ||
Get-TfsWorkItemQueryFolder 'My Deleted Folder' -Scope Personal -Deleted | Undo-TfsWorkItemQueryRemoval -Recursive | ||
# ... or you can specify the folder directly when calling Undo-TfsWorkItemQueryFolderRemoval | ||
Undo-TfsWorkItemQueryFolderRemoval 'My Deleted Folder' -Scope Personal -Recursive | ||
``` | ||
|
||
## Fixes | ||
|
||
* Fixes a bug in `Get-TfsWorkItemQuery` and `Get-TfsWorkItemQueryFolder` where the `-Deleted` switch was not respected and deleted items would not be returned. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters