go-jira / jira

simple jira command line client in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing values into the list template?

rvl opened this issue · comments

Hi, I really appreciate go-jira, but am having trouble passing external data into templates.
The only way I have found is through the env template function, but this is a bit clumsy to use.

Here is an example of what I'm currently doing:

# config.yml
custom-commands:
  - name: active-sprint
    help: Information about active sprint
    options:
      - name: testOpt
    args:
      - name: testArg
    script: |-
      # Get ID of first agile board in project
      board_id=$({{jira}} req "/rest/agile/1.0/board?projectKeyOrId=$JIRA_PROJECT" --gjq 'values.0.id')

      # Put sprint info into environment variables
      eval $( {{jira}} req "/rest/agile/1.0/board/$board_id/sprint?state=active" --gjq 'values.#[name%"*Week*"]' | jq '{ sprint_id: .id, board_id: .originBoardId, sprint_name: .name, sprint_start_date: .startDate|sub("T.*"; ""), sprint_end_date: .endDate|sub("T.*";"") }' | jq -r 'to_entries|map("export \(.key)=\(.value|@sh)")|.[]' )

      # List sprint issues
      {{jira}} list --template active-sprint --query "project=$JIRA_PROJECT AND sprint=$sprint_id AND type != epic ORDER BY rank ASC, created"

The list template file templates/active-sprint:

testOpt: {{/* options.testOpt */}}
testArg: {{/* args.testArg */}}

+---------+---------------+
| Sprint  | {{ env.sprint_name }}
| Start   | {{ env.sprint_start_date }}
| End     | {{ env.sprint_end_date }}
+---------+---------------+

{{ headers "Issue" "Summary" -}}
{{- range .issues -}}
  {{- row -}}
  {{- cell .key -}}
  {{- cell .fields.summary -}}
{{- end -}}

Is there some jira list command-line option which can pass structured data (JSON perhaps) into the list template?
Also, is it possible to get args and options from inside the list template?

Thanks!

I'm also very curious about accessing options from inside templates. This would be extremely powerful.