JiraPS icon indicating copy to clipboard operation
JiraPS copied to clipboard

The output of Get-JiraUser should be suitable as input for Set-JiraIssue

Open aaronsb opened this issue 8 years ago • 0 comments

It is not possible to directly use the output of Get-JiraUser in Set-JiraIssue. Inline processing must be done before it can be used, which fails a simplicity test.

Expected Behavior

I expect a given custom field as an associative array to update a jira issue with user objects generated from Get-JiraUser:

Set-JiraIssue -Issue $IssueObject -Fields (@{"customfield_123456 = (Get-JiraUser User1,User2,User3)"})

I also expect it to work in a pipeline foreach:

@{"customfield_123456" = (Get-JiraUser User1,User2,User3)} | %{Set-JiraIssue -Issue $IssueObject -Fields $_}

I would expect that in both examples, the issue's customfield_123456 field should be populated with User1, User2, and User3.

Current Behavior

Executing these statements appears to be parsed without error, but no updates to the issue occurs.

The object returned from Get-JiraUser as it is now:

Get-JiraUser abockelie

Name                 DisplayName                          Active
----                 -----------                          ------
abockelie            Aaron Bockelie                       True

Possible Solution

The intermidate parsing solution I use works, but is not obvious to the casual user of the function. What is needed is to simplify the object into a new associative array, and ALSO reference the "Name" property returned from Get-JiraUser object as lower case.

This post-processed object from Get-JiraUser works as the data for a field associative array. Note the way the structure is configured. The object is of type System.Collections.Hashtable

Get-JiraUser abockelie | %{@{name= $_.Name}}

Name                           Value
----                           -----
name                           abockelie

Fixing Set-JiraIssue may require special handlers for varying types of outputs from other functions, or some other creative internal processing of objects. A starting suggestion may be using the TypeName emitted from a native Get-JiraUser object - JiraPS.User

If that object type is encountered from Set-JiraIssue, an object handling mapper may be selected. I'm not sure of the direction the code in Set-JiraIssue is supposed to go, but handlers for all functions in the JiraPS function set would be highly unifying.

A proposed Unit Test may be to execute all object Constructors against object Consumers, of which this scenario would be one. (Ok, done with being verbose!)

Steps to Reproduce (for bugs)

(Where customfield_123 is a user picker type custom field)

Set-JiraIssue -Issue (Get-JiraIssue proj-123) -Fields (@{"customfield_123"  = (Get-JiraUser Username)})

Context

I am building automation to programmatic update of issues with user picker custom fields, for both single user and multi user types.

Your Environment

Windows Server, MySQL, Jira 7.3, Crowd, Active Directory user objects

Get-Module JiraPS -ListAvailable | select version
Version
-------
2.4.0
$psversiontable                                     
                                                      
Name                           Value                  
----                           -----                  
PSVersion                      5.1.17025.1000         
PSEdition                      Desktop                
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17025.1000        
CLRVersion                     4.0.30319.42000        
WSManStackVersion              3.0                    
PSRemotingProtocolVersion      2.3                    
SerializationVersion           1.1.0.1

aaronsb avatar Nov 06 '17 22:11 aaronsb