import 'dotenv/config'; import { Octokit } from 'octokit'; import { giteaApi } from 'gitea-js'; const mapping = { 'morten-olsen': 'morten', 'morten-olsen-archive': 'archive', 'morten-olsen-env': 'env', }; const giteaOrgs = ['morten', 'archive'] const github = new Octokit({ auth: process.env.GITHUB_TOKEN, }); const headers = { Authorization: `Bearer ${process.env.GITEA_TOKEN}`, 'Content-Type': 'application/json' } const giteaBaseUrl = 'https://gitea.olsen.cloud/api/v1/'; const iterator = github.paginate.iterator(github.rest.repos.listForAuthenticatedUser, { per_page: 10, }); for await (const { data: repos } of iterator) { for (const repo of repos) { const mappedOwner = mapping[repo.owner.login] || repo.owner.login; const url = new URL('repos/migrate', giteaBaseUrl); console.log('start', mappedOwner, repo.name) // url.searchParams.set('access_token', process.env.GITEA_TOKEN); const payload = { 'clone_addr': repo.clone_url, 'repo_name': repo.name, 'repo_owner': mappedOwner, 'service': 'github', 'auth_token': process.env.GITHUB_TOKEN, 'private': repo.private, 'description': repo.description || '', 'issues': true, 'labels': true, 'milestones': true, 'pull_requests': true, 'releases': true, 'wiki': true, 'mirror': true, }; const response = await fetch(url, { method: 'post', headers, body: JSON.stringify(payload) }); console.log(response.status, mappedOwner, repo.name) if (response.status !== 201) { console.log('a', await response.text()); } else { await new Promise((resolve) => setTimeout(resolve, 3000)); } } }