go-jira / jira

simple jira command line client in Go
Apache License 2.0
2.66k stars 323 forks source link

stuck parsing jira null values #492

Closed kvaradhan3 closed 1 year ago

kvaradhan3 commented 1 year ago

Hi:

I am trying to parse a jira ticket json, using the go-jira templates and am stuck.

The output using -tdebug, pruned, shows the field as:

{
    "fields": {
        ...
        "assignee": null,
        ...
    },
    ...
}

I had the following incantation in my template:

{{ range .issues -}}
{{ and .fields.assignee .fields.assignee.displayName }}
{{ end }}

for which, I get: ERROR Invalid Usage: template: gojira:2:31: executing "gojira" at <.fields.assignee.displayName>: nil pointer evaluating interface {}.displayName

How would I get the templater to skip, if the value is not set or null?

FWIW: I also tried variations around {{ and .fields.assignee ( ne .fields.assignee nil ) .fields.assignee.displayName }}

kvaradhan3 commented 1 year ago

Changing this to something like this works for now:

{{ range .issues -}}
  {{ if .fields.assignee }}{{ .fields.assignee.displayName | fit 12 -}}
  {{ else }}{{ "  ---  " }}{{ end }}
{{ end }}

Closing this for now.