AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
323 stars 131 forks source link

Cannot assign issue to a user using Set-JiraIssue #320

Open michalporeba opened 5 years ago

michalporeba commented 5 years ago

Description

Assigning JIRA issues to a user with Set-JiraIssue suddenly stopped working.

Steps To Reproduce

  1. start a new session with New-JiraSession
  2. Execute
    (Get-JiraIssue Issue-123) | Set-JiraIssue -Assignee (Get-JiraUser)
  3. The error is
    Invoke-JiraMethod : Can not deserialize instance of java.lang.String out of START_ARRAY token
    at [Source: org.apache.catalina.connector.CoyoteInputStream@184681e6; line: 2, column: 5] (through reference chain: com.atlassian.jira.rest.v2.issue.UserBean["name"])
    At C:\Program Files\WindowsPowerShell\Modules\jiraps\2.8.6\Public\Set-JiraIssue.ps1:206 char:21
    +                     Invoke-JiraMethod @parameter
    +                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Invoke-JiraMethod], RuntimeException
    + FullyQualifiedErrorId : InvalidResponse.Status400,Invoke-JiraMethod

Expected behavior

Up to recently this was assigning the issue to the signed user. Changing (Get-JiraUser) to a username string doesn't solve it.

Your Environment

JiraPS 2.8.6 PSVersion 5.1.16299.785

alexsuslin commented 5 years ago

Get-JiraUser having validation attribute [ValidateNotNullOrEmpty()] Weird but there is no any error when running this command without parameters

lipkau commented 5 years ago
  1. Running the command without parameters should return the information about the user that is logged on. As defined in the docs.

  2. The output of Get-JiraUser is currently not suitable for Set-JiraIssue. This was already reported in #200 . You can add a (Get-JiraUser).Name to work around it for now

michalporeba commented 5 years ago

I don't think this is a duplicat @lipkau. I have included (Get-JiraUser) in the example so I don't have to show my username, but it fails with the same exception regardless if you use -Assignee (Get-JiraUser), -Assignee (Get-JiraUser).Name or if you simply pass a string representing the user like so -Assignee myusername. So my problem, and this issue #320 is not about the Get-JiraUser but rather the Set-JiraIssue command.

lipkau commented 5 years ago

I am unable to replicate the behavior you described:

image

lipkau commented 5 years ago

Please show how you are running these commands and the output of them.

derekbartram commented 5 years ago

I too get this problem; if I run the commands as you have lipkau, I get

Invoke-JiraMethod : Can not deserialize instance of java.lang.String out of START_ARRAY token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@2dd22d10; line: 2, column: 5] (through reference chain: com.atlassian.jira.rest.v2.issue.UserBean["name"])
At C:\Program Files\WindowsPowerShell\Modules\JiraPS\2.9.0\JiraPS.psm1:5335 char:21
+                     Invoke-JiraMethod @parameter
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Invoke-JiraMethod], RuntimeException
    + FullyQualifiedErrorId : InvalidResponse.Status400,Invoke-JiraMethod`
lipkau commented 5 years ago

Please show me the payload of $Body and $splatParameters | Out-String when you run the command with -debug when you see this message: https://github.com/AtlassianPS/JiraPS/blob/a0e29a616fda283531d8d127dc031dc2efd9b5fd/JiraPS/Public/Invoke-JiraMethod.ps1#L157

michalporeba commented 5 years ago

image image @lipkau is that what you need?

lipkau commented 5 years ago

Almost. on the last message of the first screenshot, enter s and hit enter then you can see the content of the local variables. such as $Body

michalporeba commented 5 years ago

I'll do it tomorrow

On Tue, 8 Jan 2019, 11:58 Oliver Lipkau <notifications@github.com wrote:

Almost. on the last message of the first screenshot, enter s and hit enter then you can see the content of the local variables. such as $Body

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AtlassianPS/JiraPS/issues/320#issuecomment-452273743, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHYMEBt5eNV1NxCC6MaoQp1C2GGQ_pkks5vBIftgaJpZM4Y708H .

michalporeba commented 5 years ago

I have noticed two more things this morning when running the command with the -Debug option. First of all it fails only for some of the users, specifically so far I have only noticed that it fails only for my user, for other users I tried it works.

During execution of the Set-JiraIssue a call is made to rest/api/latest/user/search? and then 3 different calls to rest/api/2/user passing 3 different user names: mine and two other usernames that start with exact my username + and extra character at the end.

So I tried Get-JiraUser -UserName <myusername> and I got the same behaviour - 3 users not 1.

lipkau commented 5 years ago

This behavior is know (#49) and already planned to changed (#306). But as it's a breaking change, it will only be released with v3.0.

for now you will have to manage with something like

Get-JiraUser -UserName <myusername> | Where name -eq <myusername>
michalporeba commented 5 years ago

Please have a look at this merge request. It fixes the issue without breaking changes.

michalporeba commented 5 years ago

I have a unit test to cover the -Exact option and modified one to be more explicit how the Get-JiraUser should work when the -Exact is not used. I have also updated the Get-JiraUser documentations.