Sync GitHub organization avatars to Gitea

This commit is contained in:
2026-09-21 08:31:20 -07:00
parent a3abdb357d
commit 8f917d9ac6
2 changed files with 33 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
const syncOrgAvatar = async (org, giteaApi, headers) => {
if (!org.avatar_url) return false;
const avatar = await fetch(org.avatar_url, { signal: AbortSignal.timeout(30_000) });
if (!avatar.ok) throw new Error(`GitHub avatar download failed: ${avatar.status}`);
const image = Buffer.from(await avatar.arrayBuffer());
if (!image.length) throw new Error('GitHub avatar is empty');
const upload = await fetch(`${giteaApi}/orgs/${encodeURIComponent(org.login)}/avatar`, {
method: 'POST',
headers,
body: JSON.stringify({ image: image.toString('base64') }),
signal: AbortSignal.timeout(30_000)
});
if (!upload.ok) throw new Error(`Gitea avatar upload failed: ${upload.status} ${await upload.text()}`);
return true;
};
module.exports = syncOrgAvatar;