forked from gavinr/github-csv-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (81 loc) · 2.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
/* jshint esversion: 6 */
const program = require("commander");
const co = require("co");
const prompt = require("co-prompt");
const { Octokit } = require("@octokit/rest");
const { throttling } = require("@octokit/plugin-throttling");
const { importFile } = require("./import.js");
const { exportIssues } = require("./export.js");
program
.version("1.0.0")
.arguments("[file]")
.option(
"-g, --github_enterprise [https://api.github.my-company.com]",
"Your GitHub Enterprise URL."
)
.option(
"-t, --token [token]",
"The GitHub token. https://github.com/settings/tokens"
)
.option(
"-f, --exportFileName [export.csv]",
"The name of the CSV you'd like to export to."
)
.option("-c, --exportComments", "Include comments in the export.")
.action(function (file, options) {
co(function* () {
var retObject = {};
retObject.githubUrl =
options.github_enterprise || "https://api.github.com";
retObject.token = options.token || "";
if (retObject.token === "") {
retObject.token = yield prompt(
"token (get from https://github.com/settings/tokens): "
);
}
retObject.exportFileName = options.exportFileName || false;
retObject.exportComments = options.exportComments || false;
retObject.userOrOrganization = yield prompt("user or organization: ");
retObject.repo = yield prompt("repo: ");
return retObject;
}).then(
function (values) {
const ThrottledOctokit = Octokit.plugin(throttling);
const octokit = new ThrottledOctokit({
auth: values.token,
userAgent: "github-csv-tools",
baseUrl: values.githubUrl,
throttle: {
onRateLimit: (retryAfter, options) => {
console.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
);
if (options.request.retryCount === 0) {
// only retries once
console.log(`Retrying after ${retryAfter} seconds!`);
return true;
}
},
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
console.warn(
`Abuse detected for request ${options.method} ${options.url}`
);
},
},
});
if (file) {
// This is an import!
importFile(octokit, file, values);
} else {
// this is an export!
exportIssues(octokit, values);
}
},
function (err) {
console.error("ERROR", err);
}
);
})
.parse(process.argv);