Skip to content

Commit

Permalink
More tweaks to output and sleep to reduce rate-limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonjs committed May 28, 2024
1 parent 7e3abd8 commit d7d8c33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 6 additions & 8 deletions shared/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ async function createIssue(repo: string, issue: GhIssue, client: any, jiraUserna
return await createIssue(repo, issue, client, jiraUsername, jiraPassword, retry + 1);
} else if (resp.status < 210) {
const issueNumber = resp.data.number;
console.log(`* ${issue.JiraKey} maps to ${owner}:${repo}#${issueNumber}`);
if (!issue.Assignable && issue.Assignee) {
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.`);
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);
Expand All @@ -175,11 +174,10 @@ async function createIssue(repo: string, issue: GhIssue, client: any, jiraUserna
throw new Error(`Failed to create issue: ${issue.Title} with status code: ${resp.status}. Full response: ${resp}`);
}
} catch (ex) {
console.log(`Failed to create issue for ${issue.JiraKey} with error: ${ex}`);
console.log(`* Failed to create issue for ${issue.JiraKey} with error: ${ex}`);
const backoffSeconds = 60 * (2 ** (retry));
console.log(`Sleeping ${backoffSeconds} seconds before retrying...`);
console.log(` Sleeping ${backoffSeconds} seconds before retrying...`);
await sleep(backoffSeconds);
console.log("Trying again");
return await createIssue(repo, issue, client, jiraUsername, jiraPassword, retry + 1);
}
}
Expand All @@ -197,12 +195,12 @@ export async function createIssues(issues: GhIssue[], repo: string, token: strin
for (const issue of issues) {
if (alreadyCreated.indexOf(issue.JiraKey) >= 0) continue;

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

if (alreadyCreated.length % 20 == 0) {
console.log(`* Created ${alreadyCreated.length} of ${issues.length} issues in ${owner}:${repo}`);
}
// Try not to get rate-limited
await sleep(1);
}
}
8 changes: 6 additions & 2 deletions shared/jira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ const batchSize = 90; // Size of the batch of Jira tickets we'll get at once (da
function formatDate(d: Date) {
let month = `${d.getMonth() + 1}`;
if (d.getMonth() + 1 < 10) {
month = `0${d.getMonth() + 1}`;
month = `0${month}`;
}
return `${d.getFullYear()}-${month}-${d.getDate()}`;
let day = String(d.getDate());
if (d.getDate() < 10) {
day = `0${day}`;
}
return `${d.getFullYear()}-${month}-${day}`;
}

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

0 comments on commit d7d8c33

Please sign in to comment.