damus-github-export

Damus issue data exported from github
git clone git://jb55.com/damus-github-export
Log | Files | Refs | README | LICENSE

commit 2c1091a132f6989728be2d0719ace3cf19ddf201
parent fffb9b41c663dcc78a0009e230c6e805cfaf03aa
Author: Gavin Rehkemper <gavinr@users.noreply.github.com>
Date:   Tue, 28 Apr 2020 22:34:00 -0500

Merge pull request #15 from gavinr/export-attributes

exportAttributes option
Diffstat:
MREADME.md | 17+++++++++++++++++
Mexport.js | 46+++++++++++++++++-----------------------------
Mindex.js | 12+++++++++++-
Mpackage-lock.json | 2+-
Mpackage.json | 6+++---
5 files changed, 49 insertions(+), 34 deletions(-)

diff --git a/README.md b/README.md @@ -28,6 +28,14 @@ githubCsvTools myFile.csv githubCsvTools ``` +| Option | Default | Notes | +| ---------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | +| -f, --exportFileName | YYYY-MM-DD-hh-mm-ss-issues.csv | The name of the CSV you'd like to export to. | +| -a, --exportAttributes | number,title,labels,state,assignees,milestone,comments,created_at,updated_at,closed_at,body | Comma-separated list of attributes (columns) in the export**. | +| -c, --exportComments | n/a | Include comments in the export. | + +** List of all possible options for `exportAttributes`: `url`, `repository_url`, `labels_url`, `comments_url`, `events_url`, `html_url`, `id`, `node_id`, `number`, `title`, `user`, `labels`, `state`, `locked`, `assignee`, `assignees`, `milestone`, `comments`, `created_at`, `updated_at`, `closed_at`, `author_association`, `body` + ### Tokens For all actions, the tool will ask you to input a GitHub token. To obtain this token: @@ -37,6 +45,15 @@ For all actions, the tool will ask you to input a GitHub token. To obtain this t 3. Check on `repo` 4. Copy/paste the token provided when the tool asks for it. +## Other Options + +| Option | Notes | +| ----------------------- | ---------------------------------------------------- | +| -V, --version | output the version number | +| -g, --github_enterprise | Your GitHub Enterprise URL. | +| -t, --token | The GitHub token. https://github.com/settings/tokens | +| -h, --help | See all the options and help. | + ## Development 1. Clone the repo. diff --git a/export.js b/export.js @@ -85,40 +85,28 @@ const exportIssues = (octokit, values, includeComments = false) => { }); // Data from the API that we're removing: - const columnsToRemove = [ - "url", - "repository_url", - "labels_url", - "comments_url", - "events_url", - "html_url", - "id", - "node_id", - // "number", - // "title", - - // "labels", - // "state", - "locked", - "assignee", - // "assignees", - // "milestone", - // "comments", - // "created_at", - // "updated_at", - // "closed_at", - "author_association", - "body", - "pull_request", + const defaultColumns = values.exportAttributes || [ + "number", + "title", + "labels", + "state", + "assignees", "milestone", + "comments", + "created_at", + "updated_at", + "closed_at", + "body", ]; - data.forEach((issueObject) => { - columnsToRemove.forEach((param) => { - delete issueObject[param]; + const filteredData = data.map((issueObject) => { + const tempObject = {}; + defaultColumns.forEach((propertyName) => { + tempObject[propertyName] = issueObject[propertyName]; }); + return tempObject; }); - let csvData = data; + let csvData = filteredData; if (values.exportComments === true) { // If we want comments, replace the data that will get pushed into // the CSV with our full comments data: diff --git a/index.js b/index.js @@ -11,7 +11,7 @@ const { importFile } = require("./import.js"); const { exportIssues } = require("./export.js"); program - .version("1.0.0") + .version("1.0.2") .arguments("[file]") .option( "-g, --github_enterprise [https://api.github.my-company.com]", @@ -25,6 +25,10 @@ program "-f, --exportFileName [export.csv]", "The name of the CSV you'd like to export to." ) + .option( + "-a, --exportAttributes [attributes]", + "Comma-separated list of attributes (columns) in the export." + ) .option("-c, --exportComments", "Include comments in the export.") .action(function (file, options) { co(function* () { @@ -38,6 +42,12 @@ program ); } retObject.exportFileName = options.exportFileName || false; + retObject.exportAttributes = options.exportAttributes || false; + if (retObject.exportAttributes) { + retObject.exportAttributes = retObject.exportAttributes + .split(",") + .map((i) => i.trim()); + } retObject.exportComments = options.exportComments || false; retObject.userOrOrganization = yield prompt("user or organization: "); retObject.repo = yield prompt("repo: "); diff --git a/package-lock.json b/package-lock.json @@ -1,6 +1,6 @@ { "name": "github-csv-tools", - "version": "0.4.0", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json @@ -1,6 +1,6 @@ { "name": "github-csv-tools", - "version": "1.0.1", + "version": "1.0.2", "description": "Tools to import and export, via CSV, from GitHub.", "main": "index.js", "scripts": { @@ -19,8 +19,8 @@ "author": "Gavin Rehkemper <gavin@gavinr.com> (http://gavinr.com/)", "license": "MIT", "funding": { - "type" : "individual", - "url" : "https://gavinr.com/contribute" + "type": "individual", + "url": "https://gavinr.com/contribute" }, "dependencies": { "@octokit/plugin-throttling": "^3.2.0",