Skip to content

Commit 17a155a

Browse files
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>
1 parent 930a482 commit 17a155a

6 files changed

Lines changed: 72 additions & 41 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ jspm_packages
3636
# Optional REPL history
3737
.node_repl_history
3838

39-
.vscode
39+
.vscode
40+
41+
.idea

banner.png

-2 Bytes
Loading

helpers.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
1-
const createIssue = (octokit, issueInfo, state = false) => {
1+
const createIssue = (octokit, issueInfo, organization, repository) => {
22
return new Promise((resolve, reject) => {
3-
octokit.issues.create(issueInfo).then(
3+
octokit.request("POST /repos/" + organization + "/" + repository + "/import/issues", issueInfo).then(
44
(res) => {
55
// console.log("res", res);
6-
if (res.status === 201) {
7-
if (state === false) {
8-
// Success creating the issue and we do not have to close the issue, so we're done.
6+
if (res.status === 202) {
7+
console.log(`Imported issue: ${issueInfo.issue.title}`);
98
resolve(res);
10-
} else {
11-
// need to close the issue!
12-
const issueNumber = res.data.number;
13-
octokit.issues
14-
.update({
15-
owner: issueInfo.owner,
16-
repo: issueInfo.repo,
17-
issue_number: issueNumber,
18-
state,
19-
})
20-
.then(
21-
(editRes) => {
22-
resolve(editRes);
23-
},
24-
(err) => {
25-
reject(err);
26-
}
27-
);
28-
}
299
} else {
3010
// error creating the issue
3111
reject(res);

import.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,44 @@ const importFile = (octokit, file, values) => {
3333
}
3434
const createPromises = csvRows.map((row) => {
3535
const sendObj = {
36-
owner: values.userOrOrganization,
37-
repo: values.repo,
38-
title: row[titleIndex],
36+
issue : {}
3937
};
4038

39+
sendObj.issue.title = row[titleIndex];
40+
4141
// if we have a body column, pass that.
42-
if (bodyIndex > -1) {
43-
sendObj.body = row[bodyIndex];
42+
if (bodyIndex > -1 && row[bodyIndex] !== "") {
43+
sendObj.issue.body = row[bodyIndex];
4444
}
4545

4646
// if we have a labels column, pass that.
4747
if (labelsIndex > -1 && row[labelsIndex] !== "") {
48-
sendObj.labels = row[labelsIndex].split(",");
48+
sendObj.issue.labels = row[labelsIndex].split(",");
4949
}
5050

5151
// if we have a milestone column, pass that.
5252
if (milestoneIndex > -1 && row[milestoneIndex] !== "") {
53-
sendObj.milestone = row[milestoneIndex];
53+
sendObj.issue.milestone = row[milestoneIndex];
5454
}
5555

5656
// if we have an assignee column, pass that.
5757
if (assigneeIndex > -1 && row[assigneeIndex] !== "") {
58-
sendObj.assignees = row[assigneeIndex].replace(/ /g, "").split(",");
58+
sendObj.issue.assignee = row[assigneeIndex];
5959
}
6060

61-
// console.log("sendObj", sendObj);
62-
let state = false;
63-
if (stateIndex > -1 && row[stateIndex] === "closed") {
64-
state = row[stateIndex];
61+
if (stateIndex > -1 && row[stateIndex].toLowerCase() === "closed") {
62+
sendObj.issue.closed = true;
6563
}
66-
return createIssue(octokit, sendObj, state);
64+
return createIssue(octokit, sendObj, values.userOrOrganization, values.repo);
6765
});
6866

6967
Promise.all(createPromises).then(
7068
(res) => {
7169
const successes = res.filter((cr) => {
72-
return cr.status === 200 || cr.status === 201;
70+
return cr.status === 200 || cr.status === 201 || cr.status === 202;
7371
});
7472
const fails = res.filter((cr) => {
75-
return cr.status !== 200 && cr.status !== 201;
73+
return cr.status !== 200 && cr.status !== 201 && cr.status !== 202;
7674
});
7775

7876
console.log(
@@ -83,6 +81,7 @@ const importFile = (octokit, file, values) => {
8381
);
8482

8583
if (fails.length > 0) {
84+
console.error('ERROR - some of the imports have failed');
8685
console.log(fails);
8786
}
8887

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/5.csv

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
title,body,labels,assignee
2+
Test 1,This is a placeholder description.,bug,
3+
Test 2,This is a placeholder description.,"question,bug",
4+
Test 3,This is a placeholder description.,,
5+
Test 4,This is a placeholder description.,bug,
6+
Test 5,This is a placeholder description.,"question,bug",
7+
Test 6,This is a placeholder description.,,
8+
Test 7,This is a placeholder description.,bug,
9+
Test 8,This is a placeholder description.,"question,bug",
10+
Test 9,This is a placeholder description.,,
11+
Test 10,This is a placeholder description.,bug,
12+
Test 11,This is a placeholder description.,"question,bug",
13+
Test 12,This is a placeholder description.,,
14+
Test 13,This is a placeholder description.,bug,
15+
Test 14,This is a placeholder description.,"question,bug",
16+
Test 15,This is a placeholder description.,,
17+
Test 16,This is a placeholder description.,bug,
18+
Test 17,This is a placeholder description.,"question,bug",
19+
Test 18,This is a placeholder description.,,
20+
Test 19,This is a placeholder description.,bug,
21+
Test 20,This is a placeholder description.,"question,bug",
22+
Test 21,This is a placeholder description.,,
23+
Test 22,This is a placeholder description.,bug,
24+
Test 23,This is a placeholder description.,"question,bug",
25+
Test 24,This is a placeholder description.,,
26+
Test 25,This is a placeholder description.,bug,
27+
Test 26,This is a placeholder description.,"question,bug",
28+
Test 27,This is a placeholder description.,,
29+
Test 28,This is a placeholder description.,bug,
30+
Test 29,This is a placeholder description.,"question,bug",
31+
Test 30,This is a placeholder description.,,
32+
Test 31,This is a placeholder description.,bug,
33+
Test 32,This is a placeholder description.,"question,bug",
34+
Test 33,This is a placeholder description.,,
35+
Test 34,This is a placeholder description.,bug,
36+
Test 35,This is a placeholder description.,"question,bug",
37+
Test 36,This is a placeholder description.,,
38+
Test 37,This is a placeholder description.,bug,
39+
Test 38,This is a placeholder description.,"question,bug",
40+
Test 39,This is a placeholder description.,,
41+
Test 40,This is a placeholder description.,bug,
42+
Test 41,This is a placeholder description.,"question,bug",
43+
Test 42,This is a placeholder description.,,
44+
Test 43,This is a placeholder description.,bug,
45+
Test 44,This is a placeholder description.,"question,bug",
46+
Test 45,This is a placeholder description.,,
47+
Test 46,This is a placeholder description.,bug,
48+
Test 47,This is a placeholder description.,"question,bug",
49+
Test 48,This is a placeholder description.,,
50+
Test 49,This is a placeholder description.,bug,

0 commit comments

Comments
 (0)