Changed default behavior
parent
584f329213
commit
416988e568
24
src/index.js
24
src/index.js
|
@ -3,7 +3,7 @@ const request = require('superagent');
|
||||||
const {default: PQueue} = require('p-queue');
|
const {default: PQueue} = require('p-queue');
|
||||||
|
|
||||||
|
|
||||||
async function getGithubRepositories(username, token) {
|
async function getGithubRepositories(username, token, mirrorPrivateRepositories) {
|
||||||
const octokit = new Octokit({
|
const octokit = new Octokit({
|
||||||
auth: token || null,
|
auth: token || null,
|
||||||
});
|
});
|
||||||
|
@ -11,10 +11,17 @@ async function getGithubRepositories(username, token) {
|
||||||
const publicRepositoriesWithForks = await octokit.paginate('GET /users/:username/repos', { username: username })
|
const publicRepositoriesWithForks = await octokit.paginate('GET /users/:username/repos', { username: username })
|
||||||
.then(repositories => toRepositoryList(repositories));
|
.then(repositories => toRepositoryList(repositories));
|
||||||
|
|
||||||
const allRepositoriesWithoutForks = await octokit.paginate('GET /search/repositories?q=user:{username}', { username : username })
|
let allRepositoriesWithoutForks;
|
||||||
|
if(mirrorPrivateRepositories === 'true'){
|
||||||
|
allRepositoriesWithoutForks = await octokit.paginate('GET /search/repositories?q=user:{username}', { username : username })
|
||||||
.then(repositories => toRepositoryList(repositories));
|
.then(repositories => toRepositoryList(repositories));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mirrorPrivateRepositories === 'true'){
|
||||||
return filterDuplicates(allRepositoriesWithoutForks.concat(publicRepositoriesWithForks));
|
return filterDuplicates(allRepositoriesWithoutForks.concat(publicRepositoriesWithForks));
|
||||||
|
}else{
|
||||||
|
return publicRepositoriesWithForks;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toRepositoryList(repositories) {
|
function toRepositoryList(repositories) {
|
||||||
|
@ -57,7 +64,7 @@ function mirrorOnGitea(repository, gitea, giteaUser, githubToken) {
|
||||||
request.post(`${gitea.url}/api/v1/repos/migrate`)
|
request.post(`${gitea.url}/api/v1/repos/migrate`)
|
||||||
.set('Authorization', 'token ' + gitea.token)
|
.set('Authorization', 'token ' + gitea.token)
|
||||||
.send({
|
.send({
|
||||||
auth_token: githubToken,
|
auth_token: githubToken || null,
|
||||||
clone_addr: repository.url,
|
clone_addr: repository.url,
|
||||||
mirror: true,
|
mirror: true,
|
||||||
repo_name: repository.name,
|
repo_name: repository.name,
|
||||||
|
@ -91,19 +98,26 @@ async function main() {
|
||||||
}
|
}
|
||||||
const githubToken = process.env.GITHUB_TOKEN;
|
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..');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const giteaToken = process.env.GITEA_TOKEN;
|
const giteaToken = process.env.GITEA_TOKE;
|
||||||
if (!giteaToken) {
|
if (!giteaToken) {
|
||||||
console.error('No GITEA_TOKEN specified, please specify! Exiting..');
|
console.error('No GITEA_TOKEN specified, please specify! Exiting..');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mirrorPrivateRepositories = process.env.MIRROR_PRIVATE_REPOSITORIES;
|
||||||
|
if(mirrorPrivateRepositories === 'true' && !githubToken){
|
||||||
|
console.error('MIRROR_PRIVATE_REPOSITORIES was set to true but no GITHUB_TOKEN was specified, please specify! Exiting..')
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const githubRepositories = await getGithubRepositories(githubUsername, githubToken);
|
|
||||||
|
const githubRepositories = await getGithubRepositories(githubUsername, githubToken, mirrorPrivateRepositories);
|
||||||
console.log(`Found ${githubRepositories.length} repositories on github`);
|
console.log(`Found ${githubRepositories.length} repositories on github`);
|
||||||
|
|
||||||
const gitea = {
|
const gitea = {
|
||||||
|
|
Loading…
Reference in New Issue