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

Allow to Update-VSTeamWorkItem to add relations with other work items #518

Open
mnieto opened this issue Apr 26, 2023 · 7 comments
Open
Labels
enhancement Improvements that do not include new features feature request for new feature requests that do not just improve things

Comments

@mnieto
Copy link
Contributor

mnieto commented Apr 26, 2023

Proposal

Add a similar parameter as existing AdditionalFields, for example -Relations. This parameter can be a hashtable like this:

$rel = @(
 [pscustomobject]@{
   Relation = "Parent"
   Id = 193812
   Operation = "Add"
 },
 [pscustomobject]@{
   Relation = "Related"
   Id = 123
   Operation = "Add"
 }
)
Update-VSTeamWorkItem -id 555 -Relations $rel

Solved Problem

This will allow to simplify the process to udpate work items with related ones

Additional info / code snippets?

There is a basic example of this in the Add-VSTeamWorkItem cmdlet using the -ParentId parameter. But this feature will allow to define additional relationships for a work item

@mnieto mnieto added enhancement Improvements that do not include new features feature request for new feature requests that do not just improve things labels Apr 26, 2023
@mnieto
Copy link
Contributor Author

mnieto commented May 14, 2023

dup of (or related to) #228

@SebastianSchuetze
Copy link
Collaborator

@mnieto what do you think is
Making it better I'm regards to complexity, maintainibility and usability you solution to include it in an existing cmdlet or new ones?

@mnieto
Copy link
Contributor Author

mnieto commented May 22, 2023

@SebastianSchuetze
On the one hand, implementing all together in the same cmdlet allows to do not perform additional calls to the REST API, for example when we want to update a field and also a relation for the same workitem. Also the command Get-VSTeamWorkItem -Id number -Expand All is returning the relations. For consistency, Update-VSTeamWorkItem should update both fields and relations.

On the other hand, implementing in separated cmdlets simplify the logic. In fact the az devops CLI implement the relations management in a separated command set.

In both cases, my idea is to implement an internal function to retrieve the different relationship types and then use it to both create a dynamic parameter (RelationType) and to expose a new cmdlet Get-VSTeamWorkItemRelationTypes

Then, I can implement a New-VSTeamWorkItemRelation cmdlet to generate a in-memory definition of the relation. In this way it's easier to validate the parameters and build the corresponding JsonPatchDocument. Also, with this only one cmdlet I expect to cover the use cases to add, remove or replace relations in the WorkItem. For eample:

$relations = @()
$relations += New-VSTeamWorkItemRelation -RelationType Parent -Id 1502 -RelatedWorkItemId 903 -Operation Add
Update-VSTeamWorkItem -Id 1502 -Relations $relations

But if you prefer implement the relationship management in a separate set of cmdlets (like in #228 proposal) it is fine also for me.

Please send me your advice on this

@SebastianSchuetze
Copy link
Collaborator

SebastianSchuetze commented May 24, 2023

@mnieto Internal function is a clever idea, and I would go with the consistent approach done in Get-VSTeamWorkItem. Meaning We can update relations with Update-VSTeamWorkItem.

But still, I would say that we expose cmdlets for doing relations stuff also with the same internal function.

Would you give it a try? Did I express myself clear enough?

@mnieto
Copy link
Contributor Author

mnieto commented May 24, 2023

It's clear.
This is my proposal of cmdlets to be added/updated
I have some doubts about replace operations. i.e. change a parent workitem. So expect minor changes during the implementation, but in general should be something like this:

  • Update-VSTeamWorkItem: add a -Relations parameter
  • Get-VSTeamWorkItemRelationTypes: list Relations types. Paramerters:
    • Usage: All|resourceLink|workItemLink. Default workItemLink
  • New-VSTeamWorkItemRelation: Helper cmdlet that creates an in-memory object to facilitate building the -Relations parameter in Update-VSTeamWorkIte. Parameters:
    • Id Work item to be modified
    • RelationType: Values got from dynamic parameter
    • RelatedWorkItemId Related work item id
    • Operation Add|Remove|Replace
  • Add-VSTeamWorkItemLink Parameters:
    • Id workitem to be modified
    • RelationType: Values get from dynamic parameter
    • RelatedWorkItemId Related work item id
  • Get-VSTeamWorkItemLink Parameters
    • Id workitem to be modified
    • RelationType Optional. If not specified, return all relations in -Id
  • Remove-VSTeamWorkItemLink Parameters
    • Id workitem to be modified
    • RelatedWorkItemId Related work item id

All the above cmdlets will work internally with a JsonPatchDocument or compatible object. Also, below cmdlets will return this object/collection of objects respectively. Using this aproach, the -Relations paramter in the Update-VSTeamWorkItem can be built with the help of New-VSTeamWorkItemRelation or directly as the example at the very beginning of this thread.

  • New-VSTeamWorkItemRelation
  • Get-VSTeamWorkItemLink

@SebastianSchuetze
Copy link
Collaborator

Yes start. Just not sure if I understood. The minor changes would they mean that older scripts would break?

@mnieto
Copy link
Contributor Author

mnieto commented May 25, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements that do not include new features feature request for new feature requests that do not just improve things
Projects
None yet
Development

No branches or pull requests

2 participants