Visitar URL original
initial · Xyroh/github-csv-tools@7ee1dec · GitHub
Skip to content

Commit 7ee1dec

Browse files
committed
initial
1 parent 6933d3b commit 7ee1dec

7 files changed

Lines changed: 167 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
This project adheres to [Semantic Versioning](http://semver.org/).
4+
5+
## [Unreleased]
6+
7+
## 0.1.0 - 2016-07-04
8+
### Added
9+
- Basic CSV import functionality.
10+
- A few basic tests
11+
12+
[Unreleased]: https://github.com/gavinr/github-csv-tools/compare/v0.1.0...HEAD

‎README.md‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
11
# github-csv-tools
2-
Tools for importing and exporting GitHub Issues via CSV.
2+
Tools for importing GitHub Issues via CSV. (Exporting to come soon?)
3+
4+
Currently imports title, description, and labels.
5+
6+
## Usage
7+
8+
1. `npm install -g github-csv-tools`
9+
2. `githubCsvTools myFile.csv`
10+
11+
`githubCsvTools --help` for info on how to use the command line tool
12+
13+
## Development
14+
15+
1. Clone the repo.
16+
2. Browse to repo, then run `npm install -g`
17+
18+
## Changelog
19+
20+
See [CHANGELOG.md](https://github.com/gavinr/github-csv-tools/blob/master/CHANGELOG.md)
21+
22+
## Thanks
23+
24+
- [github package](https://www.npmjs.com/package/github)
25+
- [nodeCSV](https://www.npmjs.com/package/csv)
26+
- [commander](https://www.npmjs.com/package/commander)
27+
- [co](https://www.npmjs.com/package/co)
28+
- [Tim Patterson's Post on Atlassian.com](https://developer.atlassian.com/blog/2015/11/scripting-with-node/)

‎index.js‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env node
2+
3+
const program = require('commander');
4+
const co = require('co');
5+
const prompt = require('co-prompt');
6+
const GitHubApi = require('github');
7+
const csv = require('csv');
8+
const fs = require('fs');
9+
10+
program
11+
.version('0.1.0')
12+
.arguments('<file>')
13+
.option('-t, --token <token>', 'The GitHub token. https://github.com/settings/tokens')
14+
.action(function(file) {
15+
co(function*() {
16+
var retObject = {};
17+
retObject.token = yield prompt('token (get from https://github.com/settings/tokens): ');
18+
retObject.userOrOrganization = yield prompt('user or organization: ');
19+
retObject.repo = yield prompt('repo: ');
20+
return retObject;
21+
}).then(function(values) {
22+
var github = new GitHubApi({
23+
// required
24+
version: '3.0.0',
25+
// optional
26+
debug: true,
27+
protocol: 'https',
28+
host: 'api.github.com',
29+
timeout: 5000,
30+
headers: {
31+
'user-agent': 'My-Cool-GitHub-App' // GitHub is happy with a unique user agent
32+
}
33+
});
34+
// OAuth2
35+
github.authenticate({
36+
type: "oauth",
37+
token: values.token
38+
});
39+
40+
fs.readFile(file, 'utf8', (err, data) => {
41+
if (err) {
42+
console.error('Error reading file.');
43+
process.exit(1);
44+
}
45+
csv.parse(data, {
46+
trim: true
47+
}, (err, csvRows) => {
48+
if (err) throw err;
49+
var cols = csvRows[0];
50+
csvRows.shift();
51+
52+
// get indexes of the fields we need
53+
var titleIndex = cols.indexOf('title');
54+
var bodyIndex = cols.indexOf('description');
55+
var labelsIndex = cols.indexOf('labels');
56+
57+
if (titleIndex === -1) {
58+
console.error('Title required by GitHub, but not found in CSV.');
59+
process.exit(1);
60+
}
61+
csvRows.forEach((row) => {
62+
var sendObj = {
63+
user: values.userOrOrganization,
64+
repo: values.repo,
65+
title: row[titleIndex]
66+
};
67+
68+
// if we have a body column, pass that.
69+
if (bodyIndex > -1) {
70+
sendObj.body = row[bodyIndex];
71+
}
72+
73+
// if we have a labels column, pass that.
74+
if (labelsIndex > -1) {
75+
sendObj.labels = row[labelsIndex].split(',');
76+
}
77+
78+
github.issues.create(sendObj, function(err, res)
79+
{
80+
// debugging: console.log(JSON.stringify(res));
81+
process.exit(0);
82+
});
83+
});
84+
});
85+
});
86+
87+
}, function(err) {
88+
console.error('ERROR', err);
89+
});
90+
})
91+
.parse(process.argv);

‎package.json‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "github-csv-tools",
3+
"version": "0.1.0",
4+
"description": "Tools to import and export, via CSV, from GitHub.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"bin": {
10+
"githubCsvTools": "./index.js"
11+
},
12+
"keywords": [
13+
"github",
14+
"csv",
15+
"import",
16+
"export"
17+
],
18+
"repository": "https://github.com/gavinr/github-csv-tools.git",
19+
"author": "Gavin Rehkemper <gavin@gavinr.com> (http://gavinr.com/)",
20+
"license": "MIT",
21+
"dependencies": {
22+
"co": "^4.6.0",
23+
"co-prompt": "^1.0.0",
24+
"commander": "^2.9.0",
25+
"csv": "^0.4.6",
26+
"github": "^0.2.4"
27+
}
28+
}

‎test/1.csv‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
title,description,labels
2+
Test 1, This is the test1 desc, bug
3+
Test 2, This is the test2 desc, question

‎test/2.csv‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
title,description,labels
2+
Test 1, This is the test1 desc, bug
3+
Test 2, This is the test2 desc, "question,bug"

‎test/noTitle.csv‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description,labels
2+
This is the test1 desc, bug
3+
This is the test2 desc, question

0 commit comments

Comments
 (0)