Skip to content

Commit 45543a3

Browse files
committed
Stop for an extra 60 secs after abuse limit errors
1 parent 7572017 commit 45543a3

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"dependencies": {
2828
"@gitbeaker/node": "^23.1.0",
2929
"@octokit/rest": "^18.0.0",
30+
"@octokit/plugin-throttling": "^3.4.3",
3031
"aws-sdk": "^2.712.0",
3132
"axios": "^0.21.1",
3233
"mime-types": "^2.1.27",

src/index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import GitlabHelper from './gitlabHelper';
33
import settings from '../settings';
44

55
import {Octokit as GitHubApi} from '@octokit/rest';
6+
import {throttling} from '@octokit/plugin-throttling';
67
import { Gitlab } from '@gitbeaker/node'
78

89
import * as fs from 'fs';
910

1011
import AWS from 'aws-sdk';
11-
12+
import { sleep } from './utils';
1213

1314
const issueCounters = {
1415
nrOfPlaceholderIssues: 0,
@@ -51,8 +52,10 @@ const gitlabApi = new Gitlab({
5152
token: settings.gitlab.token,
5253
});
5354

55+
const MyOctokit = GitHubApi.plugin(throttling);
56+
5457
// Create a GitHub API object
55-
const githubApi = new GitHubApi({
58+
const githubApi = new MyOctokit({
5659
debug: false,
5760
baseUrl: settings.github.baseUrl
5861
? settings.github.baseUrl
@@ -63,6 +66,22 @@ const githubApi = new GitHubApi({
6366
accept: 'application/vnd.github.v3+json',
6467
},
6568
auth: 'token ' + settings.github.token,
69+
throttle: {
70+
onRateLimit: async (retryAfter, options) => {
71+
console.log(
72+
`Request quota exhausted for request ${options.method} ${options.url}`
73+
);
74+
await sleep(60000);
75+
return true;
76+
},
77+
onAbuseLimit: async (retryAfter, options) => {
78+
console.log(
79+
`Abuse detected for request ${options.method} ${options.url}`
80+
);
81+
await sleep(60000);
82+
return true;
83+
},
84+
},
6685
});
6786

6887
const gitlabHelper = new GitlabHelper(gitlabApi, settings.gitlab);

0 commit comments

Comments
 (0)