Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# github-csv-tools
Tools for importing GitHub Issues via CSV. (Exporting to come soon?)

Currently imports title, description, and labels.
Currently imports title, description, labels, and milestones.

## Usage

1. `npm install -g github-csv-tools`
2. `githubCsvTools myFile.csv`
2. `githubCsvTools myFile.csv`

`githubCsvTools --help` for info on how to use the command line tool

Expand All @@ -25,4 +25,4 @@ See [CHANGELOG.md](https://github.com/gavinr/github-csv-tools/blob/master/CHANGE
- [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/)
- [Tim Patterson's Post on Atlassian.com](https://developer.atlassian.com/blog/2015/11/scripting-with-node/)
23 changes: 19 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env node
/* jshint esversion: 6 */

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');
const Bottleneck = require("bottleneck");

program
.version('0.1.0')
Expand All @@ -31,6 +33,11 @@ program
'user-agent': 'My-Cool-GitHub-App' // GitHub is happy with a unique user agent
}
});

// abuse rate limits apply for concurrent content creation
// requests by a single GitHub user.
var limiter = new Bottleneck(20,200);

// OAuth2
github.authenticate({
type: "oauth",
Expand All @@ -53,6 +60,7 @@ program
var titleIndex = cols.indexOf('title');
var bodyIndex = cols.indexOf('description');
var labelsIndex = cols.indexOf('labels');
var milestoneIndex = cols.indexOf('milestone');

if (titleIndex === -1) {
console.error('Title required by GitHub, but not found in CSV.');
Expand All @@ -71,14 +79,21 @@ program
}

// if we have a labels column, pass that.
if (labelsIndex > -1) {
sendObj.labels = row[labelsIndex].split(',');
if (labelsIndex > -1 && row[labelsIndex] !== '') {
sendObj.labels = row[labelsIndex].split(',');
}

// if we have a milestone column, pass that.
if (milestoneIndex > -1 && row[milestoneIndex] !== '') {
sendObj.milestone = row[milestoneIndex];
}

github.issues.create(sendObj, function(err, res)
limiter.submit(github.issues.create,sendObj, function(err, res)
{
// debugging: console.log(JSON.stringify(res));
process.exit(0);
if (limiter.nbQueued() === 0) {
process.exit(0);
}
});
});
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"author": "Gavin Rehkemper <gavin@gavinr.com> (http://gavinr.com/)",
"license": "MIT",
"dependencies": {
"bottleneck": "^1.15.1",
"co": "^4.6.0",
"co-prompt": "^1.0.0",
"commander": "^2.9.0",
Expand Down