damus-github-export

Damus issue data exported from github
git clone git://jb55.com/damus-github-export
Log | Files | Refs | README | LICENSE

commit 17a155aa61e518c96587860430b6a20a646c09d8
parent 930a48274c2f8b7c53e7cfa42a485bdd3598c92c
Author: Gavin Rehkemper <gavinr@users.noreply.github.com>
Date:   Tue, 16 Aug 2022 21:52:17 -0500

Rate limit fix (#82)

* Use endpoint /import/issues to avoid rate limit errors
* added large import CSV

Co-authored-by: Cyrille MANSARD <cyrille.mansard_ext@euromaster.com>
Diffstat:
M.gitignore | 6++++--
Mbanner.png | 0
Mhelpers.js | 28++++------------------------
Mimport.js | 29++++++++++++++---------------
Mpackage-lock.json | 2+-
Atest/5.csv | 50++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -36,4 +36,6 @@ jspm_packages # Optional REPL history .node_repl_history -.vscode- \ No newline at end of file +.vscode + +.idea+ \ No newline at end of file diff --git a/banner.png b/banner.png Binary files differ. diff --git a/helpers.js b/helpers.js @@ -1,31 +1,11 @@ -const createIssue = (octokit, issueInfo, state = false) => { +const createIssue = (octokit, issueInfo, organization, repository) => { return new Promise((resolve, reject) => { - octokit.issues.create(issueInfo).then( + octokit.request("POST /repos/" + organization + "/" + repository + "/import/issues", issueInfo).then( (res) => { // console.log("res", res); - if (res.status === 201) { - if (state === false) { - // Success creating the issue and we do not have to close the issue, so we're done. + if (res.status === 202) { + console.log(`Imported issue: ${issueInfo.issue.title}`); resolve(res); - } else { - // need to close the issue! - const issueNumber = res.data.number; - octokit.issues - .update({ - owner: issueInfo.owner, - repo: issueInfo.repo, - issue_number: issueNumber, - state, - }) - .then( - (editRes) => { - resolve(editRes); - }, - (err) => { - reject(err); - } - ); - } } else { // error creating the issue reject(res); diff --git a/import.js b/import.js @@ -33,46 +33,44 @@ const importFile = (octokit, file, values) => { } const createPromises = csvRows.map((row) => { const sendObj = { - owner: values.userOrOrganization, - repo: values.repo, - title: row[titleIndex], + issue : {} }; + sendObj.issue.title = row[titleIndex]; + // if we have a body column, pass that. - if (bodyIndex > -1) { - sendObj.body = row[bodyIndex]; + if (bodyIndex > -1 && row[bodyIndex] !== "") { + sendObj.issue.body = row[bodyIndex]; } // if we have a labels column, pass that. if (labelsIndex > -1 && row[labelsIndex] !== "") { - sendObj.labels = row[labelsIndex].split(","); + sendObj.issue.labels = row[labelsIndex].split(","); } // if we have a milestone column, pass that. if (milestoneIndex > -1 && row[milestoneIndex] !== "") { - sendObj.milestone = row[milestoneIndex]; + sendObj.issue.milestone = row[milestoneIndex]; } // if we have an assignee column, pass that. if (assigneeIndex > -1 && row[assigneeIndex] !== "") { - sendObj.assignees = row[assigneeIndex].replace(/ /g, "").split(","); + sendObj.issue.assignee = row[assigneeIndex]; } - // console.log("sendObj", sendObj); - let state = false; - if (stateIndex > -1 && row[stateIndex] === "closed") { - state = row[stateIndex]; + if (stateIndex > -1 && row[stateIndex].toLowerCase() === "closed") { + sendObj.issue.closed = true; } - return createIssue(octokit, sendObj, state); + return createIssue(octokit, sendObj, values.userOrOrganization, values.repo); }); Promise.all(createPromises).then( (res) => { const successes = res.filter((cr) => { - return cr.status === 200 || cr.status === 201; + return cr.status === 200 || cr.status === 201 || cr.status === 202; }); const fails = res.filter((cr) => { - return cr.status !== 200 && cr.status !== 201; + return cr.status !== 200 && cr.status !== 201 && cr.status !== 202; }); console.log( @@ -83,6 +81,7 @@ const importFile = (octokit, file, values) => { ); if (fails.length > 0) { + console.error('ERROR - some of the imports have failed'); console.log(fails); } diff --git a/package-lock.json b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "github-csv-tools", - "version": "3.1.2", + "version": "3.1.3", "license": "MIT", "dependencies": { "@octokit/plugin-throttling": "^3.5.2", diff --git a/test/5.csv b/test/5.csv @@ -0,0 +1,50 @@ +title,body,labels,assignee +Test 1,This is a placeholder description.,bug, +Test 2,This is a placeholder description.,"question,bug", +Test 3,This is a placeholder description.,, +Test 4,This is a placeholder description.,bug, +Test 5,This is a placeholder description.,"question,bug", +Test 6,This is a placeholder description.,, +Test 7,This is a placeholder description.,bug, +Test 8,This is a placeholder description.,"question,bug", +Test 9,This is a placeholder description.,, +Test 10,This is a placeholder description.,bug, +Test 11,This is a placeholder description.,"question,bug", +Test 12,This is a placeholder description.,, +Test 13,This is a placeholder description.,bug, +Test 14,This is a placeholder description.,"question,bug", +Test 15,This is a placeholder description.,, +Test 16,This is a placeholder description.,bug, +Test 17,This is a placeholder description.,"question,bug", +Test 18,This is a placeholder description.,, +Test 19,This is a placeholder description.,bug, +Test 20,This is a placeholder description.,"question,bug", +Test 21,This is a placeholder description.,, +Test 22,This is a placeholder description.,bug, +Test 23,This is a placeholder description.,"question,bug", +Test 24,This is a placeholder description.,, +Test 25,This is a placeholder description.,bug, +Test 26,This is a placeholder description.,"question,bug", +Test 27,This is a placeholder description.,, +Test 28,This is a placeholder description.,bug, +Test 29,This is a placeholder description.,"question,bug", +Test 30,This is a placeholder description.,, +Test 31,This is a placeholder description.,bug, +Test 32,This is a placeholder description.,"question,bug", +Test 33,This is a placeholder description.,, +Test 34,This is a placeholder description.,bug, +Test 35,This is a placeholder description.,"question,bug", +Test 36,This is a placeholder description.,, +Test 37,This is a placeholder description.,bug, +Test 38,This is a placeholder description.,"question,bug", +Test 39,This is a placeholder description.,, +Test 40,This is a placeholder description.,bug, +Test 41,This is a placeholder description.,"question,bug", +Test 42,This is a placeholder description.,, +Test 43,This is a placeholder description.,bug, +Test 44,This is a placeholder description.,"question,bug", +Test 45,This is a placeholder description.,, +Test 46,This is a placeholder description.,bug, +Test 47,This is a placeholder description.,"question,bug", +Test 48,This is a placeholder description.,, +Test 49,This is a placeholder description.,bug,