damus-github-export

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

commit 2a895dff1ab02e0b0c6ef4238a936625506fb52a
parent 962a39af2c837ea50c1b2c5f0760d5aa30d68f77
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 17 Mar 2024 12:39:18 +0000

move to src to cleanup root a bit

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
MREADME.md | 25++-----------------------
Dindex.js | 116-------------------------------------------------------------------------------
Rexport.js -> src/export.js | 0
Rhelpers.js -> src/helpers.js | 0
Rimport.js -> src/import.js | 0
Asrc/index.js | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 118 insertions(+), 139 deletions(-)

diff --git a/README.md b/README.md @@ -1,5 +1,4 @@ -<div align="center"><img src="https://github.com/gavinr/github-csv-tools/blob/master/banner.jpg?raw=true" alt="GitHub CSV Tools banner" title="GitHub CSV Tools" /> -<h3 align="center">Import and export GitHub issues via CSV</h3> +<h3 align="center">Import and export GitHub issues via JSON</h3> </div> <p align="center"> @@ -20,28 +19,8 @@ ## Usage -Prerequisite: [Install Node.js](https://nodejs.org/en/), then run this to install: - -```bash -npm install -g github-csv-tools -``` - -After install, `githubCsvTools --help` for info on how to use, or see below. - -Instructions for exporting or importing: - -### To Import Issues - -Currently imports title, body, labels, status (closed or open) and milestones. See the [test](/test) folder for example input formats. - -```bash -githubCsvTools myFile.csv -``` - -### To Export Issues - ```bash -githubCsvTools +node index.js -t github_token -o organization -r repository ``` | Option | Default | Notes | diff --git a/index.js b/index.js @@ -1,116 +0,0 @@ -#!/usr/bin/env node -/* jshint esversion: 6 */ - -const program = require("commander"); -const co = require("co"); -const prompt = require("co-prompt"); -const { Octokit } = require("@octokit/rest"); -const { throttling } = require("@octokit/plugin-throttling"); -const { importFile } = require("./import.js"); -const { exportIssues } = require("./export.js"); - -program - .version(require("./package.json").version) - .arguments("[file]") - .option( - "-g, --github_enterprise [https://api.github.my-company.com]", - "Your GitHub Enterprise URL." - ) - .option( - "-t, --token [token]", - "The GitHub token. https://github.com/settings/tokens" - ) - .option( - "-o, --organization [organization]", - "The User or Organization slug that the repo lives under." - ) - .option("-r, --repository [repository]", "The repository name (slug).") - .option( - "-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.") - .option("-e, --exportAll", "Include all data in the export.") - .option( - "--csvDelimiter [csvDelimiter]", - "CSV delimiter character (defaults to ',')" - ) .option("-v, --verbose", "Include additional logging information.") - .action(function (file, options) { - co(function* () { - const retObject = {}; - retObject.githubUrl = - options.github_enterprise || "https://api.github.com"; - retObject.token = options.token || ""; - if (retObject.token === "") { - retObject.token = yield prompt( - "Token (get from https://github.com/settings/tokens): " - ); - } - 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.exportAll = options.exportAll || false; - retObject.csvDelimiter = options.csvDelimiter || ','; - retObject.verbose = options.verbose || false; - - retObject.userOrOrganization = options.organization || ""; - if (retObject.userOrOrganization === "") { - retObject.userOrOrganization = yield prompt("User or organization: "); - } - - retObject.repo = options.repository || ""; - if (retObject.repo === "") { - retObject.repo = yield prompt("Repository: "); - } - return retObject; - }).then( - function (values) { - const ThrottledOctokit = Octokit.plugin(throttling); - const octokit = new ThrottledOctokit({ - auth: values.token, - userAgent: "github-csv-tools", - baseUrl: values.githubUrl, - throttle: { - onRateLimit: (retryAfter, options) => { - console.warn( - `Request quota exhausted for request ${options.method} ${options.url}` - ); - - if (options.request.retryCount === 0) { - // only retries once - console.log(`Retrying after ${retryAfter} seconds!`); - return true; - } - }, - onAbuseLimit: (retryAfter, options) => { - // does not retry, only logs a warning - console.warn( - `Abuse detected for request ${options.method} ${options.url}` - ); - }, - }, - }); - - if (file) { - // This is an import! - importFile(octokit, file, values); - } else { - // this is an export! - exportIssues(octokit, values); - } - }, - function (err) { - console.error("ERROR", err); - } - ); - }) - .parse(process.argv); diff --git a/export.js b/src/export.js diff --git a/helpers.js b/src/helpers.js diff --git a/import.js b/src/import.js diff --git a/src/index.js b/src/index.js @@ -0,0 +1,116 @@ +#!/usr/bin/env node +/* jshint esversion: 6 */ + +const program = require("commander"); +const co = require("co"); +const prompt = require("co-prompt"); +const { Octokit } = require("@octokit/rest"); +const { throttling } = require("@octokit/plugin-throttling"); +const { importFile } = require("./import.js"); +const { exportIssues } = require("./export.js"); + +program + .version(require("../package.json").version) + .arguments("[file]") + .option( + "-g, --github_enterprise [https://api.github.my-company.com]", + "Your GitHub Enterprise URL." + ) + .option( + "-t, --token [token]", + "The GitHub token. https://github.com/settings/tokens" + ) + .option( + "-o, --organization [organization]", + "The User or Organization slug that the repo lives under." + ) + .option("-r, --repository [repository]", "The repository name (slug).") + .option( + "-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.") + .option("-e, --exportAll", "Include all data in the export.") + .option( + "--csvDelimiter [csvDelimiter]", + "CSV delimiter character (defaults to ',')" + ) .option("-v, --verbose", "Include additional logging information.") + .action(function (file, options) { + co(function* () { + const retObject = {}; + retObject.githubUrl = + options.github_enterprise || "https://api.github.com"; + retObject.token = options.token || ""; + if (retObject.token === "") { + retObject.token = yield prompt( + "Token (get from https://github.com/settings/tokens): " + ); + } + 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.exportAll = options.exportAll || false; + retObject.csvDelimiter = options.csvDelimiter || ','; + retObject.verbose = options.verbose || false; + + retObject.userOrOrganization = options.organization || ""; + if (retObject.userOrOrganization === "") { + retObject.userOrOrganization = yield prompt("User or organization: "); + } + + retObject.repo = options.repository || ""; + if (retObject.repo === "") { + retObject.repo = yield prompt("Repository: "); + } + return retObject; + }).then( + function (values) { + const ThrottledOctokit = Octokit.plugin(throttling); + const octokit = new ThrottledOctokit({ + auth: values.token, + userAgent: "github-csv-tools", + baseUrl: values.githubUrl, + throttle: { + onRateLimit: (retryAfter, options) => { + console.warn( + `Request quota exhausted for request ${options.method} ${options.url}` + ); + + if (options.request.retryCount === 0) { + // only retries once + console.log(`Retrying after ${retryAfter} seconds!`); + return true; + } + }, + onAbuseLimit: (retryAfter, options) => { + // does not retry, only logs a warning + console.warn( + `Abuse detected for request ${options.method} ${options.url}` + ); + }, + }, + }); + + if (file) { + // This is an import! + importFile(octokit, file, values); + } else { + // this is an export! + exportIssues(octokit, values); + } + }, + function (err) { + console.error("ERROR", err); + } + ); + }) + .parse(process.argv);