Feat: Sync repo visibility changes from GitHub to Gitea

This commit is contained in:
2026-02-17 17:40:52 -08:00
parent 3ff2412f37
commit a3abdb357d

View File

@@ -14,7 +14,7 @@ const req = async (url, h, m = 'GET', b = null) => {
} }
return res.ok ? (m === 'GET' ? res.json() : res) : null; return res.ok ? (m === 'GET' ? res.json() : res) : null;
} catch (e) { } catch (e) {
if (m !== 'GET') throw e; if (m !== 'GET') throw e;
return null; return null;
} }
}; };
@@ -30,7 +30,7 @@ const getPages = async (url) => {
(async () => { (async () => {
console.log('Starting Mirror Sync...'); console.log('Starting Mirror Sync...');
try { try {
const gUser = await req(`${G_API}/user`, headers.GT); const gUser = await req(`${G_API}/user`, headers.GT);
if (!gUser) throw new Error('Cannot auth with Gitea'); if (!gUser) throw new Error('Cannot auth with Gitea');
@@ -41,7 +41,7 @@ const getPages = async (url) => {
]); ]);
let allRepos = [...ghUserRepos]; let allRepos = [...ghUserRepos];
for (const org of ghOrgs) { for (const org of ghOrgs) {
console.log(`Checking Org: ${org.login}`); console.log(`Checking Org: ${org.login}`);
try { try {
@@ -53,7 +53,7 @@ const getPages = async (url) => {
console.log(`Updating Org Visibility: ${org.login}`); console.log(`Updating Org Visibility: ${org.login}`);
await req(`${G_API}/orgs/${org.login}`, headers.GT, 'PATCH', { visibility: 'public' }); await req(`${G_API}/orgs/${org.login}`, headers.GT, 'PATCH', { visibility: 'public' });
} }
const orgRepos = await getPages(`https://api.github.com/orgs/${org.login}/repos?type=all`); const orgRepos = await getPages(`https://api.github.com/orgs/${org.login}/repos?type=all`);
allRepos.push(...orgRepos); allRepos.push(...orgRepos);
} catch (e) { } catch (e) {
@@ -66,7 +66,7 @@ const getPages = async (url) => {
try { try {
const owner = r.owner.login; const owner = r.owner.login;
const exists = await req(`${G_API}/repos/${owner}/${r.name}`, headers.GT); const exists = await req(`${G_API}/repos/${owner}/${r.name}`, headers.GT);
if (!exists) { if (!exists) {
console.log(`Mirroring: ${owner}/${r.name}`); console.log(`Mirroring: ${owner}/${r.name}`);
const payload = { const payload = {
@@ -88,6 +88,9 @@ const getPages = async (url) => {
mirror_prune: true mirror_prune: true
}; };
await req(`${G_API}/repos/migrate`, headers.GT, 'POST', payload); await req(`${G_API}/repos/migrate`, headers.GT, 'POST', payload);
} else if (exists.private !== r.private) {
console.log(`Updating visibility: ${owner}/${r.name}${r.private ? 'private' : 'public'}`);
await req(`${G_API}/repos/${owner}/${r.name}`, headers.GT, 'PATCH', { private: r.private });
} }
} catch (e) { } catch (e) {
console.error(`Failed to mirror ${r.owner.login}/${r.name}:`, e.message); console.error(`Failed to mirror ${r.owner.login}/${r.name}:`, e.message);