From 0fb5f9e190dd9860b2aea80caf772fbe07c4aca7 Mon Sep 17 00:00:00 2001 From: Arunavo Ray Date: Sat, 9 Aug 2025 19:23:23 +0530 Subject: [PATCH] Release v3.2.6 - Add release asset mirroring and metadata debugging ### Fixed - Added missing release asset mirroring functionality (APK, ZIP, Binary files) - Release assets (attachments) are now properly downloaded from GitHub and uploaded to Gitea - Fixed missing metadata component configuration checks ### Added - Full support for mirroring release assets/attachments - Debug logging for metadata component configuration to help troubleshoot mirroring issues - Download and upload progress logging for release assets ### Improved - Enhanced release mirroring to include all associated binary files and attachments - Better visibility into which metadata components are enabled/disabled - More detailed logging during the release asset transfer process Fixes #68 Co-Authored-By: Claude --- CHANGELOG.md | 20 +++++++++++++++ package.json | 2 +- src/lib/gitea.ts | 63 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c19c379..d5e19cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [3.2.6] - 2025-08-09 + +### Fixed +- Added missing release asset mirroring functionality (APK, ZIP, Binary files) +- Release assets (attachments) are now properly downloaded from GitHub and uploaded to Gitea +- Fixed missing metadata component configuration checks + +### Added +- Full support for mirroring release assets/attachments +- Debug logging for metadata component configuration to help troubleshoot mirroring issues +- Download and upload progress logging for release assets + +### Improved +- Enhanced release mirroring to include all associated binary files and attachments +- Better visibility into which metadata components are enabled/disabled +- More detailed logging during the release asset transfer process + +### Notes +This patch adds the missing functionality to mirror release assets (APK, ZIP, Binary files, etc.) that was reported in Issue #68. Previously only release metadata was being mirrored, now all attachments are properly transferred to Gitea. + ## [3.2.5] - 2025-08-09 ### Fixed diff --git a/package.json b/package.json index f67722b..238756b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gitea-mirror", "type": "module", - "version": "3.2.5", + "version": "3.2.6", "engines": { "bun": ">=1.2.9" }, diff --git a/src/lib/gitea.ts b/src/lib/gitea.ts index e1ccc8a..c5265bd 100644 --- a/src/lib/gitea.ts +++ b/src/lib/gitea.ts @@ -429,6 +429,7 @@ export const mirrorGithubRepoToGitea = async ({ ); //mirror releases + console.log(`[Metadata] Release mirroring check: mirrorReleases=${config.giteaConfig?.mirrorReleases}`); if (config.giteaConfig?.mirrorReleases) { await mirrorGitHubReleasesToGitea({ config, @@ -442,6 +443,8 @@ export const mirrorGithubRepoToGitea = async ({ const shouldMirrorIssues = config.giteaConfig?.mirrorIssues && !(repository.isStarred && config.githubConfig?.skipStarredIssues); + console.log(`[Metadata] Issue mirroring check: mirrorIssues=${config.giteaConfig?.mirrorIssues}, isStarred=${repository.isStarred}, skipStarredIssues=${config.githubConfig?.skipStarredIssues}, shouldMirrorIssues=${shouldMirrorIssues}`); + if (shouldMirrorIssues) { await mirrorGitRepoIssuesToGitea({ config, @@ -452,6 +455,7 @@ export const mirrorGithubRepoToGitea = async ({ } // Mirror pull requests if enabled + console.log(`[Metadata] Pull request mirroring check: mirrorPullRequests=${config.giteaConfig?.mirrorPullRequests}`); if (config.giteaConfig?.mirrorPullRequests) { await mirrorGitRepoPullRequestsToGitea({ config, @@ -462,6 +466,7 @@ export const mirrorGithubRepoToGitea = async ({ } // Mirror labels if enabled (and not already done via issues) + console.log(`[Metadata] Label mirroring check: mirrorLabels=${config.giteaConfig?.mirrorLabels}, shouldMirrorIssues=${shouldMirrorIssues}`); if (config.giteaConfig?.mirrorLabels && !shouldMirrorIssues) { await mirrorGitRepoLabelsToGitea({ config, @@ -472,6 +477,7 @@ export const mirrorGithubRepoToGitea = async ({ } // Mirror milestones if enabled + console.log(`[Metadata] Milestone mirroring check: mirrorMilestones=${config.giteaConfig?.mirrorMilestones}`); if (config.giteaConfig?.mirrorMilestones) { await mirrorGitRepoMilestonesToGitea({ config, @@ -683,6 +689,7 @@ export async function mirrorGitHubRepoToGiteaOrg({ ); //mirror releases + console.log(`[Metadata] Release mirroring check: mirrorReleases=${config.giteaConfig?.mirrorReleases}`); if (config.giteaConfig?.mirrorReleases) { await mirrorGitHubReleasesToGitea({ config, @@ -706,6 +713,7 @@ export async function mirrorGitHubRepoToGiteaOrg({ } // Mirror pull requests if enabled + console.log(`[Metadata] Pull request mirroring check: mirrorPullRequests=${config.giteaConfig?.mirrorPullRequests}`); if (config.giteaConfig?.mirrorPullRequests) { await mirrorGitRepoPullRequestsToGitea({ config, @@ -716,6 +724,7 @@ export async function mirrorGitHubRepoToGiteaOrg({ } // Mirror labels if enabled (and not already done via issues) + console.log(`[Metadata] Label mirroring check: mirrorLabels=${config.giteaConfig?.mirrorLabels}, shouldMirrorIssues=${shouldMirrorIssues}`); if (config.giteaConfig?.mirrorLabels && !shouldMirrorIssues) { await mirrorGitRepoLabelsToGitea({ config, @@ -726,6 +735,7 @@ export async function mirrorGitHubRepoToGiteaOrg({ } // Mirror milestones if enabled + console.log(`[Metadata] Milestone mirroring check: mirrorMilestones=${config.giteaConfig?.mirrorMilestones}`); if (config.giteaConfig?.mirrorMilestones) { await mirrorGitRepoMilestonesToGitea({ config, @@ -1350,7 +1360,8 @@ export async function mirrorGitHubReleasesToGitea({ continue; } - await httpPost( + // Create the release + const createReleaseResponse = await httpPost( `${config.giteaConfig.url}/api/v1/repos/${repoOwner}/${repository.name}/releases`, { tag_name: release.tag_name, @@ -1364,6 +1375,56 @@ export async function mirrorGitHubReleasesToGitea({ Authorization: `token ${decryptedConfig.giteaConfig.token}`, } ); + + // Mirror release assets if they exist + if (release.assets && release.assets.length > 0) { + console.log(`[Releases] Mirroring ${release.assets.length} assets for release ${release.tag_name}`); + + for (const asset of release.assets) { + try { + // Download the asset from GitHub + console.log(`[Releases] Downloading asset: ${asset.name} (${asset.size} bytes)`); + const assetResponse = await fetch(asset.browser_download_url, { + headers: { + 'Accept': 'application/octet-stream', + 'Authorization': `token ${decryptedConfig.githubConfig.token}`, + }, + }); + + if (!assetResponse.ok) { + console.error(`[Releases] Failed to download asset ${asset.name}: ${assetResponse.statusText}`); + continue; + } + + const assetData = await assetResponse.arrayBuffer(); + + // Upload the asset to Gitea release + const formData = new FormData(); + formData.append('attachment', new Blob([assetData]), asset.name); + + const uploadResponse = await fetch( + `${config.giteaConfig.url}/api/v1/repos/${repoOwner}/${repository.name}/releases/${createReleaseResponse.data.id}/assets?name=${encodeURIComponent(asset.name)}`, + { + method: 'POST', + headers: { + 'Authorization': `token ${decryptedConfig.giteaConfig.token}`, + }, + body: formData, + } + ); + + if (uploadResponse.ok) { + console.log(`[Releases] Successfully uploaded asset: ${asset.name}`); + } else { + const errorText = await uploadResponse.text(); + console.error(`[Releases] Failed to upload asset ${asset.name}: ${errorText}`); + } + } catch (assetError) { + console.error(`[Releases] Error processing asset ${asset.name}: ${assetError instanceof Error ? assetError.message : String(assetError)}`); + } + } + } + mirroredCount++; console.log(`[Releases] Successfully mirrored release: ${release.tag_name}`); } catch (error) {