commit 7ee1decdaead90e49812d9b426740f45d13a2548
parent 6933d3b6d334011e10c81746ac3e520eca59268f
Author: Gavin Rehkemper <gavreh@gmail.com>
Date: Mon, 4 Jul 2016 22:36:12 -0500
initial
Diffstat:
7 files changed, 171 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -0,0 +1,12 @@
+# Change Log
+All notable changes to this project will be documented in this file.
+This project adheres to [Semantic Versioning](http://semver.org/).
+
+## [Unreleased]
+
+## 0.1.0 - 2016-07-04
+### Added
+- Basic CSV import functionality.
+- A few basic tests
+
+[Unreleased]: https://github.com/gavinr/github-csv-tools/compare/v0.1.0...HEAD
diff --git a/README.md b/README.md
@@ -1,2 +1,28 @@
# github-csv-tools
-Tools for importing and exporting GitHub Issues via CSV.
+Tools for importing GitHub Issues via CSV. (Exporting to come soon?)
+
+Currently imports title, description, and labels.
+
+## Usage
+
+ 1. `npm install -g github-csv-tools`
+ 2. `githubCsvTools myFile.csv`
+
+`githubCsvTools --help` for info on how to use the command line tool
+
+## Development
+
+1. Clone the repo.
+2. Browse to repo, then run `npm install -g`
+
+## Changelog
+
+See [CHANGELOG.md](https://github.com/gavinr/github-csv-tools/blob/master/CHANGELOG.md)
+
+## Thanks
+
+- [github package](https://www.npmjs.com/package/github)
+- [nodeCSV](https://www.npmjs.com/package/csv)
+- [commander](https://www.npmjs.com/package/commander)
+- [co](https://www.npmjs.com/package/co)
+- [Tim Patterson's Post on Atlassian.com](https://developer.atlassian.com/blog/2015/11/scripting-with-node/)+
\ No newline at end of file
diff --git a/index.js b/index.js
@@ -0,0 +1,91 @@
+#!/usr/bin/env node
+
+const program = require('commander');
+const co = require('co');
+const prompt = require('co-prompt');
+const GitHubApi = require('github');
+const csv = require('csv');
+const fs = require('fs');
+
+program
+ .version('0.1.0')
+ .arguments('<file>')
+ .option('-t, --token <token>', 'The GitHub token. https://github.com/settings/tokens')
+ .action(function(file) {
+ co(function*() {
+ var retObject = {};
+ retObject.token = yield prompt('token (get from https://github.com/settings/tokens): ');
+ retObject.userOrOrganization = yield prompt('user or organization: ');
+ retObject.repo = yield prompt('repo: ');
+ return retObject;
+ }).then(function(values) {
+ var github = new GitHubApi({
+ // required
+ version: '3.0.0',
+ // optional
+ debug: true,
+ protocol: 'https',
+ host: 'api.github.com',
+ timeout: 5000,
+ headers: {
+ 'user-agent': 'My-Cool-GitHub-App' // GitHub is happy with a unique user agent
+ }
+ });
+ // OAuth2
+ github.authenticate({
+ type: "oauth",
+ token: values.token
+ });
+
+ fs.readFile(file, 'utf8', (err, data) => {
+ if (err) {
+ console.error('Error reading file.');
+ process.exit(1);
+ }
+ csv.parse(data, {
+ trim: true
+ }, (err, csvRows) => {
+ if (err) throw err;
+ var cols = csvRows[0];
+ csvRows.shift();
+
+ // get indexes of the fields we need
+ var titleIndex = cols.indexOf('title');
+ var bodyIndex = cols.indexOf('description');
+ var labelsIndex = cols.indexOf('labels');
+
+ if (titleIndex === -1) {
+ console.error('Title required by GitHub, but not found in CSV.');
+ process.exit(1);
+ }
+ csvRows.forEach((row) => {
+ var sendObj = {
+ user: values.userOrOrganization,
+ repo: values.repo,
+ title: row[titleIndex]
+ };
+
+ // if we have a body column, pass that.
+ if (bodyIndex > -1) {
+ sendObj.body = row[bodyIndex];
+ }
+
+ // if we have a labels column, pass that.
+ if (labelsIndex > -1) {
+ sendObj.labels = row[labelsIndex].split(',');
+ }
+
+ github.issues.create(sendObj, function(err, res)
+ {
+ // debugging: console.log(JSON.stringify(res));
+ process.exit(0);
+ });
+ });
+ });
+ });
+
+ }, function(err) {
+ console.error('ERROR', err);
+ });
+ })
+ .parse(process.argv);
diff --git a/package.json b/package.json
@@ -0,0 +1,28 @@
+{
+ "name": "github-csv-tools",
+ "version": "0.1.0",
+ "description": "Tools to import and export, via CSV, from GitHub.",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "bin": {
+ "githubCsvTools": "./index.js"
+ },
+ "keywords": [
+ "github",
+ "csv",
+ "import",
+ "export"
+ ],
+ "repository": "https://github.com/gavinr/github-csv-tools.git",
+ "author": "Gavin Rehkemper <gavin@gavinr.com> (http://gavinr.com/)",
+ "license": "MIT",
+ "dependencies": {
+ "co": "^4.6.0",
+ "co-prompt": "^1.0.0",
+ "commander": "^2.9.0",
+ "csv": "^0.4.6",
+ "github": "^0.2.4"
+ }
+}
diff --git a/test/1.csv b/test/1.csv
@@ -0,0 +1,3 @@
+title,description,labels
+Test 1, This is the test1 desc, bug
+Test 2, This is the test2 desc, question+
\ No newline at end of file
diff --git a/test/2.csv b/test/2.csv
@@ -0,0 +1,3 @@
+title,description,labels
+Test 1, This is the test1 desc, bug
+Test 2, This is the test2 desc, "question,bug"+
\ No newline at end of file
diff --git a/test/noTitle.csv b/test/noTitle.csv
@@ -0,0 +1,3 @@
+description,labels
+This is the test1 desc, bug
+This is the test2 desc, question+
\ No newline at end of file