gavinr / github-csv-tools

Import and export GitHub issues via CSV
https://npmjs.com/github-csv-tools
MIT License
661 stars 118 forks source link

--exportAttributes labels #28

Open dev0zzz opened 4 years ago

dev0zzz commented 4 years ago

When I write the command

githubCsvTools --exportAttributes state,created_at,labels,milestone.title,milestone.created_at,milestone.due_on,number,title,body

I get all the label attributes, I just want to have the labels.name

but if I type labels.name i get nothing

gavinr commented 4 years ago

Thanks for the report. Looks like a bug - right now the code handles the single-object items (user, assignee, milestone, closed_by), but we'll have to update it to handle the arrays (labels, assignees). PRs welcome!

94rain commented 2 years ago

It seems that the logics are already implemented in defaultExportColumns method, but not in specificAttributeColumns https://github.com/gavinr/github-csv-tools/blob/475a58f74269a3a51f7c86dc43f6e778b0e5b665/export.js#L108-L130

As a temporary workaround, a simple change to specificAttributeColumns can resolve the labels issue. (Adding the if-clause)

const specificAttributeColumns = (data, attributes) => {
  return data.map((issueObject) => {
    const ret = {};
    attributes.forEach((attribute) => {
      ret[attribute] = getDataAttribute(issueObject, attribute);
      if (attribute === "labels") {
        ret[attribute] = issueObject.labels
        .map((labelObject) => {
          return labelObject.name;
        })
        .join(",");
      }
    });
    return ret;
  });
};

But this could be a bit redundant. Maybe we can decompose export.js#L108-L130 to a single method that is invoked by both defaultExportColumns and specificAttributeColumns?

kalanchan commented 1 year ago

is this still being worked on? I get blanks when trying to export labels.name