go-jira / jira

simple jira command line client in Go
Apache License 2.0
2.68k stars 328 forks source link

Commands without output generate 'ERROR Invalid Usage: JSON Parse Error: EOF' #299

Open svenXY opened 5 years ago

svenXY commented 5 years ago

Hi,

I came across #135 and implemented the suggested custom-command. It works down to the last command where it tries to POST the issue/s to be added to the sprint.

It adds the issue to the sprint successfully, but I keep getting 'ERROR Invalid Usage: JSON Parse Error: EOF'.

Running this with curl seems to have worked though:

curl -D- -u user:password -X POST -d '{"issues":["MYPROJ-1638"]}' -H "Content-Type: application/json" https://jira.company.com/rest/agile/1.0/sprint/2356/issue
HTTP/1.1 204

The problem to me seems to be that no output is returned by this command, thus both templates, -t debug and -t request fail as they require some json to be piped into toJson in the template

Looks like a regression to #72

Is there any easy method to either not spit out the error, or - even better - take the HTTP code and create some output based on the http code

Thanks, Sven

hendrikmaus commented 4 years ago

As a quick workaround to get the command to exit with 0, I used:

- name: sprint-add
  help: add issue to active sprint for project
  args:
    - name: ISSUE
      required: true
  script: |
    board_id=$({{jira}} req "/rest/agile/1.0/board?projectKeyOrId=$JIRA_PROJECT" --gjq values.0.id)
    sprint_id=$({{jira}} req "/rest/agile/1.0/board/$board_id/sprint?state=active" --gjq values.0.id)
    {{jira}} req -M POST "/rest/agile/1.0/sprint/$sprint_id/issue" "{\"issues\":[\"{{args.ISSUE}}\"]}" > /dev/null 2>&1 || true

Where > /dev/null 2>&1 || true is not a pretty thing to do, but makes it work for now.

andrei-a-papou commented 4 years ago

I also had to do some ugly stderr redirection to work around this issue...

pylipp commented 4 years ago

I had the same issue when deleting an issue link via this resource:

jira req -M DELETE /rest/api/2/issueLink/47286

It shows the program usage, and the message

ERROR Invalid Usage: JSON Parse Error: EOF

However, the command is executed (i.e. the issue link is deleted). The JIRA Rest docs state that there is no available response representation for status 200.

voiski commented 4 years ago

The problem here is how go-jira handles the empty output. I had similar issues in the sprint/moveIssuesToSprint where it returns HTTP status 204 - empty response. The go-jira tries to handle the "" in the json parsers giving the EOF. The command runs successfully, but the client fails to handle its response.

https://github.com/go-jira/jira/blob/ff5decc114b297e9b393f8d4af72bbace0037c73/jiracmd/request.go#L78-L80

BTW, here is the pr to add the empty response support: https://github.com/go-jira/jira/pull/372