Skip to content

Commit

Permalink
Rate limit fix (#82)
Browse files Browse the repository at this point in the history
* Use endpoint /import/issues to avoid rate limit errors
* added large import CSV

Co-authored-by: Cyrille MANSARD <cyrille.mansard_ext@euromaster.com>
  • Loading branch information
gavinr and Cyrille MANSARD committed Aug 17, 2022
1 parent 930a482 commit 17a155a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 41 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ jspm_packages
# Optional REPL history
.node_repl_history

.vscode
.vscode

.idea
Binary file modified banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 4 additions & 24 deletions helpers.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
29 changes: 14 additions & 15 deletions import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions test/5.csv
Original file line number Diff line number Diff line change
@@ -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,

0 comments on commit 17a155a

Please sign in to comment.