0

I am trying to extract issues from git issues. Expecting a csv with data in selected columns ( even mutilple values in each cell accepted )

ps:"labels" contains more than one categories .

gh issue list --limit 10000 --state all --json number,title,assignees,state,labels,url | jq -r '["number","title","assignees","state","labels","url"], (.[] | [.number, .title, (.assignees | if .|length==0 then "Unassigned" elif .|length>1 then map(.login)|join(",") else .[].login end) , .state, .labels, .url]) | @csv' > issues-$(date '+%Y-%m-%d').csv

getting

jq: error (at :1): object ({"id":"MDU6...) is not valid in a csv row

Edric
  • 24,639
  • 13
  • 81
  • 91
  • 2
    Include the `json` input in your question to help you build your answer. It may not be possible to run the `gh` command locally to get input for the `jq` command. – devang Jul 11 '22 at 21:15

1 Answers1

1

As .labels is an array of objects, you need to process it :

gh issue list --limit 10000 --state all --json number,title,assignees,state,labels,url |
jq -r '["number","title","assignees","state","labels","url"],
       (.[] | [.number, .title,
               (.assignees | if length==0 then "Unassigned" else map(.login)|join(",") end),
               .state,
               (.labels | map(.name)|join(",")),
               .url
              ]
       ) | @csv' > issues-$(date '+%Y-%m-%d').csv
Philippe
  • 20,025
  • 2
  • 23
  • 32