optionally use GitHub access token to prevent rate limiting
Jannis R mail@jannisr.de
Sun, 25 Oct 2020 21:10:59 +0100
2 files changed,
8 insertions(+),
3 deletions(-)
M
README.md
→
README.md
@@ -43,6 +43,7 @@
### Parameters - `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_TOKEN` token for your gitea user
M
src/index.js
→
src/index.js
@@ -1,8 +1,11 @@
-const octokit = require('@octokit/rest')(); +const {Octokit} = require('@octokit/rest'); const request = require('superagent'); -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 }) .then(repositories => toRepositoryList(repositories)); }@@ -66,6 +69,7 @@ if (!githubUsername) {
console.error('No GITHUB_USERNAME specified, please specify! Exiting..'); return; } + const githubToken = process.env.GITHUB_TOKEN; const giteaUrl = process.env.GITEA_URL; if (!giteaUrl) { console.error('No GITEA_URL specified, please specify! Exiting..');@@ -79,7 +83,7 @@ return;
} - const githubRepositories = await getGithubRepositories(githubUsername); + const githubRepositories = await getGithubRepositories(githubUsername, githubToken); console.log(`Found ${githubRepositories.length} repositories on github`); const gitea = {