github-csv-tools icon indicating copy to clipboard operation
github-csv-tools copied to clipboard

--exportAttributes labels

Open dev0zzz opened this issue 4 years ago • 3 comments

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

dev0zzz avatar Aug 27 '20 12:08 dev0zzz

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!

gavinr avatar Aug 27 '20 23:08 gavinr

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?

94rain avatar Mar 03 '22 06:03 94rain

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

kalanchan avatar Jan 16 '23 01:01 kalanchan