Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 48f866e

Browse files
committed
More tweaks to output and sleep to reduce rate-limiting
1 parent 7e3abd8 commit 48f866e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

shared/github.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ async function createIssue(repo: string, issue: GhIssue, client: any, jiraUserna
153153
return await createIssue(repo, issue, client, jiraUsername, jiraPassword, retry + 1);
154154
} else if (resp.status < 210) {
155155
const issueNumber = resp.data.number;
156-
console.log(`* ${issue.JiraKey} maps to ${owner}:${repo}#${issueNumber}`);
157156
if (!issue.Assignable && issue.Assignee) {
158157
console.log(`WARNING! Unable to assign ${repo}#${issueNumber} to @${issue.Assignee}. Please assign yourself and tag @samsonjs if it doesn't work. Due to GitHub's spam prevention system, you must be active in order to participate in this repo.`);
159158
await addComment(repo, issueNumber, client, `Unable to assign @${issue.Assignee}. Please assign yourself and tag @samsonjs if it doesn't work. Due to GitHub's spam prevention system, you must be active in order to participate in this repo.`, 0);
@@ -175,11 +174,10 @@ async function createIssue(repo: string, issue: GhIssue, client: any, jiraUserna
175174
throw new Error(`Failed to create issue: ${issue.Title} with status code: ${resp.status}. Full response: ${resp}`);
176175
}
177176
} catch (ex) {
178-
console.log(`Failed to create issue for ${issue.JiraKey} with error: ${ex}`);
177+
console.log(`* Failed to create issue for ${issue.JiraKey} with error: ${ex}`);
179178
const backoffSeconds = 60 * (2 ** (retry));
180-
console.log(`Sleeping ${backoffSeconds} seconds before retrying...`);
179+
console.log(` - Sleeping ${backoffSeconds} seconds before retrying...`);
181180
await sleep(backoffSeconds);
182-
console.log("Trying again");
183181
return await createIssue(repo, issue, client, jiraUsername, jiraPassword, retry + 1);
184182
}
185183
}
@@ -197,12 +195,12 @@ export async function createIssues(issues: GhIssue[], repo: string, token: strin
197195
for (const issue of issues) {
198196
if (alreadyCreated.indexOf(issue.JiraKey) >= 0) continue;
199197

200-
await createIssue(repo, issue, client, jiraUsername, jiraPassword);
198+
const issueNumber = await createIssue(repo, issue, client, jiraUsername, jiraPassword);
201199
alreadyCreated.push(issue.JiraKey);
202200
fs.writeFileSync(stateFile, alreadyCreated.join(','));
201+
console.log(`* (${alreadyCreated.length} of ${issues.length}) ${issue.JiraKey} maps to ${owner}:${repo}#${issueNumber}`);
203202

204-
if (alreadyCreated.length % 20 == 0) {
205-
console.log(`* Created ${alreadyCreated.length} of ${issues.length} issues in ${owner}:${repo}`);
206-
}
203+
// Try not to get rate-limited
204+
await sleep(1);
207205
}
208206
}

shared/jira.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ const batchSize = 90; // Size of the batch of Jira tickets we'll get at once (da
2121
function formatDate(d: Date) {
2222
let month = `${d.getMonth() + 1}`;
2323
if (d.getMonth() + 1 < 10) {
24-
month = `0${d.getMonth() + 1}`;
24+
month = `0${month}`;
2525
}
26-
return `${d.getFullYear()}-${month}-${d.getDate()}`;
26+
let day = String(d.getDate());
27+
if (d.getDate() < 10) {
28+
day = `0${day}`;
29+
}
30+
return `${d.getFullYear()}-${month}-${day}`;
2731
}
2832

2933
export async function fetchJiraTickets(username: string, password: string, project: string, label: string, startDate: Date, endDate: Date) {

0 commit comments

Comments
 (0)