mirror of
https://github.com/arnaucube/mirror-to-gitea.git
synced 2026-02-07 03:26:45 +01:00
Merge pull request #2 from derhuerst/master
use GitHub access token, rate-limit Gitea requests
This commit is contained in:
@@ -43,6 +43,7 @@ This will a spin up a docker container running infinite which will try to mirror
|
|||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `GITHUB_USERNAME` name of user or organization which public repos should be mirrored
|
- `GITHUB_USERNAME` name of user or organization which public repos should be mirrored
|
||||||
|
- `GITHUB_TOKEN` [GitHub personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) (optional)
|
||||||
- `GITEA_URL` url of your gitea server
|
- `GITEA_URL` url of your gitea server
|
||||||
- `GITEA_TOKEN` token for your gitea user
|
- `GITEA_TOKEN` token for your gitea user
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
22
src/index.js
22
src/index.js
@@ -1,8 +1,12 @@
|
|||||||
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) {
|
async function getGithubRepositories(username, token) {
|
||||||
|
const octokit = new Octokit({
|
||||||
|
auth: token || null,
|
||||||
|
});
|
||||||
return octokit.paginate('GET /users/:username/repos', { username: username })
|
return octokit.paginate('GET /users/:username/repos', { username: username })
|
||||||
.then(repositories => toRepositoryList(repositories));
|
.then(repositories => toRepositoryList(repositories));
|
||||||
}
|
}
|
||||||
@@ -66,6 +70,7 @@ async function main() {
|
|||||||
console.error('No GITHUB_USERNAME specified, please specify! Exiting..');
|
console.error('No GITHUB_USERNAME specified, please specify! Exiting..');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const githubToken = process.env.GITHUB_TOKEN;
|
||||||
const giteaUrl = process.env.GITEA_URL;
|
const giteaUrl = process.env.GITEA_URL;
|
||||||
if (!giteaUrl) {
|
if (!giteaUrl) {
|
||||||
console.error('No GITEA_URL specified, please specify! Exiting..');
|
console.error('No GITEA_URL specified, please specify! Exiting..');
|
||||||
@@ -79,20 +84,21 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const githubRepositories = await getGithubRepositories(githubUsername);
|
const githubRepositories = await getGithubRepositories(githubUsername, githubToken);
|
||||||
console.log(`Found ${githubRepositories.length} repositories on github`);
|
console.log(`Found ${githubRepositories.length} repositories on github`);
|
||||||
|
|
||||||
const gitea = {
|
const gitea = {
|
||||||
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();
|
||||||
|
|||||||
Reference in New Issue
Block a user