[PR #345] [MERGED] fix: stop config saves from resetting env-configured GITEA_MIRROR_INTERVAL (#338) #8262

Closed
opened 2026-08-24 04:00:33 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/RayLabsHQ/gitea-mirror/pull/345
Author: @arunavo4
Created: 7/16/2026
Status: ✅ Merged
Merged: 7/16/2026
Merged by: @arunavo4

Base: main ← Head: fix/338-env-mirror-interval


📝 Commits (1)

  • 703c20e fix: stop config saves from resetting env-configured GITEA_MIRROR_INTERVAL (#338)

📊 Changes

3 files changed (+135 additions, -43 deletions)

View changed files

📝 src/lib/utils/config-mapper.test.ts (+66 -0)
📝 src/lib/utils/config-mapper.ts (+39 -23)
📝 src/pages/api/config/index.ts (+30 -20)

📄 Description

Summary

Fixes #338 — GITEA_MIRROR_INTERVAL (and every other env-only option) was silently reset to defaults whenever any setting was saved in the UI.

Root cause

  • mapUiToDbConfig() in src/lib/utils/config-mapper.ts hardcoded mirrorInterval: "8h". The Configuration form has no mirror-interval field, and the page auto-saves the full config on any field change (500ms debounce), so touching anything rewrote the DB value back to 8h.
  • The next repo sync then PATCHes each Gitea mirror's mirror_interval from the DB (syncGiteaRepoEnhanced), wiping out the env-configured interval.
  • Note: "Test Connection" itself never persists config — typing/pasting into a form field before clicking it fires the auto-save, which is why it appeared to be the trigger.

The same mapper also reset other env-configurable fields not exposed in the UI: GITEA_CREATE_ORG, GITEA_ADD_TOPICS, GITEA_TOPIC_PREFIX, GITEA_TEMPLATE_OWNER/REPO, GITEA_PRESERVE_VISIBILITY, GITEA_FORK_STRATEGY=full-copy, GITHUB_TYPE, INCLUDE_ARCHIVED, PUBLIC_REPOSITORIES.

Fix

  • mapUiToDbConfig() now takes the stored config (same pattern as mapUiScheduleToDb) and preserves every field the settings form doesn't manage, instead of resetting to constants. mirrorInterval falls back to the stored value, then "8h".
  • forkStrategy guarded: skipForks=true still forces "skip"; unchecked keeps a stored "full-copy" but resets a stale "skip" to "reference".
  • POST /api/config parses the stored configs once and passes them into the mapper (token preservation reuses the same parse).

Testing

  • bun test: 387 pass, 0 fail
  • 6 new regression tests in src/lib/utils/config-mapper.test.ts (env interval survives save, default without existing config, non-UI field preservation, forkStrategy interactions)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/RayLabsHQ/gitea-mirror/pull/345 **Author:** [@arunavo4](https://github.com/arunavo4) **Created:** 7/16/2026 **Status:** ✅ Merged **Merged:** 7/16/2026 **Merged by:** [@arunavo4](https://github.com/arunavo4) **Base:** `main` ← **Head:** `fix/338-env-mirror-interval` --- ### 📝 Commits (1) - [`703c20e`](https://github.com/RayLabsHQ/gitea-mirror/commit/703c20e7648ff019c44d339c2bdd8eb241442060) fix: stop config saves from resetting env-configured GITEA_MIRROR_INTERVAL (#338) ### 📊 Changes **3 files changed** (+135 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `src/lib/utils/config-mapper.test.ts` (+66 -0) 📝 `src/lib/utils/config-mapper.ts` (+39 -23) 📝 `src/pages/api/config/index.ts` (+30 -20) </details> ### 📄 Description ## Summary Fixes #338 — `GITEA_MIRROR_INTERVAL` (and every other env-only option) was silently reset to defaults whenever any setting was saved in the UI. ## Root cause - `mapUiToDbConfig()` in `src/lib/utils/config-mapper.ts` hardcoded `mirrorInterval: "8h"`. The Configuration form has no mirror-interval field, and the page auto-saves the full config on any field change (500ms debounce), so touching anything rewrote the DB value back to `8h`. - The next repo sync then PATCHes each Gitea mirror's `mirror_interval` from the DB (`syncGiteaRepoEnhanced`), wiping out the env-configured interval. - Note: "Test Connection" itself never persists config — typing/pasting into a form field before clicking it fires the auto-save, which is why it appeared to be the trigger. The same mapper also reset other env-configurable fields not exposed in the UI: `GITEA_CREATE_ORG`, `GITEA_ADD_TOPICS`, `GITEA_TOPIC_PREFIX`, `GITEA_TEMPLATE_OWNER/REPO`, `GITEA_PRESERVE_VISIBILITY`, `GITEA_FORK_STRATEGY=full-copy`, `GITHUB_TYPE`, `INCLUDE_ARCHIVED`, `PUBLIC_REPOSITORIES`. ## Fix - `mapUiToDbConfig()` now takes the stored config (same pattern as `mapUiScheduleToDb`) and preserves every field the settings form doesn't manage, instead of resetting to constants. `mirrorInterval` falls back to the stored value, then `"8h"`. - `forkStrategy` guarded: `skipForks=true` still forces `"skip"`; unchecked keeps a stored `"full-copy"` but resets a stale `"skip"` to `"reference"`. - `POST /api/config` parses the stored configs once and passes them into the mapper (token preservation reuses the same parse). ## Testing - `bun test`: 387 pass, 0 fail - 6 new regression tests in `src/lib/utils/config-mapper.test.ts` (env interval survives save, default without existing config, non-UI field preservation, forkStrategy interactions) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-08-24 04:00:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea-mirror#8262