Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinr committed Jul 5, 2016
1 parent 6933d3b commit 7ee1dec
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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/)
91 changes: 91 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> (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"
}
}
3 changes: 3 additions & 0 deletions test/1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title,description,labels
Test 1, This is the test1 desc, bug
Test 2, This is the test2 desc, question
3 changes: 3 additions & 0 deletions test/2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title,description,labels
Test 1, This is the test1 desc, bug
Test 2, This is the test2 desc, "question,bug"
3 changes: 3 additions & 0 deletions test/noTitle.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description,labels
This is the test1 desc, bug
This is the test2 desc, question

0 comments on commit 7ee1dec

Please sign in to comment.