Changed default behavior

pull/1/head
MasterEvarior 2021-05-16 12:20:07 +02:00
parent 584f329213
commit 416988e568
1 changed files with 21 additions and 7 deletions

View File

@ -3,7 +3,7 @@ const request = require('superagent');
const {default: PQueue} = require('p-queue');
async function getGithubRepositories(username, token) {
async function getGithubRepositories(username, token, mirrorPrivateRepositories) {
const octokit = new Octokit({
auth: token || null,
});
@ -11,10 +11,17 @@ async function getGithubRepositories(username, token) {
const publicRepositoriesWithForks = await octokit.paginate('GET /users/:username/repos', { username: username })
.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));
}
if(mirrorPrivateRepositories === 'true'){
return filterDuplicates(allRepositoriesWithoutForks.concat(publicRepositoriesWithForks));
}else{
return publicRepositoriesWithForks;
}
}
function toRepositoryList(repositories) {
@ -57,7 +64,7 @@ function mirrorOnGitea(repository, gitea, giteaUser, githubToken) {
request.post(`${gitea.url}/api/v1/repos/migrate`)
.set('Authorization', 'token ' + gitea.token)
.send({
auth_token: githubToken,
auth_token: githubToken || null,
clone_addr: repository.url,
mirror: true,
repo_name: repository.name,
@ -91,19 +98,26 @@ async function main() {
}
const githubToken = process.env.GITHUB_TOKEN;
const giteaUrl = process.env.GITEA_URL;
if (!giteaUrl) {
console.error('No GITEA_URL specified, please specify! Exiting..');
return;
}
const giteaToken = process.env.GITEA_TOKEN;
const giteaToken = process.env.GITEA_TOKE;
if (!giteaToken) {
console.error('No GITEA_TOKEN specified, please specify! Exiting..');
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`);
const gitea = {