This commit is contained in:
Morten Olsen
2025-10-01 23:00:03 +02:00
commit f9e8456cf9
5 changed files with 451 additions and 0 deletions

62
migrate.ts Normal file
View File

@@ -0,0 +1,62 @@
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));
}
}
}