commit c3253635febf4cf9f27e10157284a0854e80525c
parent 7ee1decdaead90e49812d9b426740f45d13a2548
Author: Gavin Rehkemper <gavinr@users.noreply.github.com>
Date: Mon, 27 Mar 2017 15:44:36 -0500
Merge pull request #2 from kwhite/master
API Request Throttling (with milestones)
Diffstat:
3 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
@@ -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
@@ -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/)-
\ No newline at end of file
+- [Tim Patterson's Post on Atlassian.com](https://developer.atlassian.com/blog/2015/11/scripting-with-node/)
diff --git a/index.js b/index.js
@@ -1,4 +1,5 @@
#!/usr/bin/env node
+/* jshint esversion: 6 */
const program = require('commander');
const co = require('co');
@@ -6,6 +7,7 @@ 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')
@@ -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",
@@ -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.');
@@ -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);
+ }
});
});
});
diff --git a/package.json b/package.json
@@ -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",