Skip to content

Commit 51af9f2

Browse files
committed
Merge branch 'master' into feature/import-api
2 parents 0da7531 + 5740b8c commit 51af9f2

3 files changed

Lines changed: 71 additions & 23 deletions

File tree

package-lock.json

Lines changed: 48 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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: 22 additions & 4 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
previews: settings.useIssueImportAPI ? ["golden-comet"] : [],
5760
debug: false,
5861
baseUrl: settings.github.baseUrl
@@ -64,6 +67,22 @@ const githubApi = new GitHubApi({
6467
accept: 'application/vnd.github.v3+json',
6568
},
6669
auth: 'token ' + settings.github.token,
70+
throttle: {
71+
onRateLimit: async (retryAfter, options) => {
72+
console.log(
73+
`Request quota exhausted for request ${options.method} ${options.url}`
74+
);
75+
await sleep(60000);
76+
return true;
77+
},
78+
onAbuseLimit: async (retryAfter, options) => {
79+
console.log(
80+
`Abuse detected for request ${options.method} ${options.url}`
81+
);
82+
await sleep(60000);
83+
return true;
84+
},
85+
},
6786
});
6887

6988
const gitlabHelper = new GitlabHelper(gitlabApi, settings.gitlab);
@@ -127,6 +146,7 @@ async function migrate() {
127146
try {
128147

129148
await githubHelper.registerRepoId();
149+
await gitlabHelper.registerProjectPath(settings.gitlab.projectId);
130150

131151
// transfer GitLab milestones to GitHub
132152
if (settings.transfer.milestones) {
@@ -251,8 +271,6 @@ async function transferLabels(attachmentLabel = true, useLowerCase = true) {
251271
async function transferIssues() {
252272
inform('Transferring Issues');
253273

254-
await gitlabHelper. registerProjectPath(settings.gitlab.projectId);
255-
256274
// Because each
257275
let milestoneData = await githubHelper.getAllGithubMilestones();
258276

0 commit comments

Comments
 (0)