Browse Source

send max 4 requests to Gitea concurrently

pull/1/head
Jannis R 4 years ago
parent
commit
463c1967b4
No known key found for this signature in database GPG Key ID: FE83946296A88A5
2 changed files with 8 additions and 5 deletions
  1. +1
    -0
      package.json
  2. +7
    -5
      src/index.js

+ 1
- 0
package.json

@ -19,6 +19,7 @@
"homepage": "https://github.com/jaedle/mirror-to-gitea#readme", "homepage": "https://github.com/jaedle/mirror-to-gitea#readme",
"dependencies": { "dependencies": {
"@octokit/rest": "^16.2.0", "@octokit/rest": "^16.2.0",
"p-queue": "^6.6.2",
"superagent": "^4.0.0" "superagent": "^4.0.0"
} }
} }

+ 7
- 5
src/index.js

@ -1,5 +1,6 @@
const {Octokit} = require('@octokit/rest'); const {Octokit} = require('@octokit/rest');
const request = require('superagent'); const request = require('superagent');
const {default: PQueue} = require('p-queue');
async function getGithubRepositories(username, token) { async function getGithubRepositories(username, token) {
@ -90,13 +91,14 @@ async function main() {
url: giteaUrl, url: giteaUrl,
token: giteaToken, token: giteaToken,
}; };
const giteaUser = await getGiteaUser(gitea); const giteaUser = await getGiteaUser(gitea);
githubRepositories.forEach(
async repository => {
const queue = new PQueue({ concurrency: 4 });
await queue.addAll(githubRepositories.map(repository => {
return async () => {
await mirror(repository, gitea, giteaUser); await mirror(repository, gitea, giteaUser);
}
);
};
}));
} }
main(); main();

Loading…
Cancel
Save