Fix: Starred Repos Organization Bug | Organization Repos Routing

This commit is contained in:
Arunavo Ray
2025-07-21 10:39:48 +05:30
parent 6ea5e9efb0
commit 0244133e7b
5 changed files with 14 additions and 12 deletions

View File

@@ -7,7 +7,7 @@ export const userSchema = z.object({
id: z.string(),
username: z.string(),
password: z.string(),
email: z.string().email(),
email: z.email(),
emailVerified: z.boolean().default(false),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
@@ -29,7 +29,7 @@ export const githubConfigSchema = z.object({
});
export const giteaConfigSchema = z.object({
url: z.string().url(),
url: z.url(),
token: z.string(),
defaultOwner: z.string(),
mirrorInterval: z.string().default("8h"),
@@ -79,6 +79,7 @@ export const scheduleConfigSchema = z.object({
export const cleanupConfigSchema = z.object({
enabled: z.boolean().default(false),
retentionDays: z.number().default(604800), // 7 days in seconds
deleteFromGitea: z.boolean().default(false),
deleteIfNotInGitHub: z.boolean().default(true),
protectedRepos: z.array(z.string()).default([]),
@@ -111,8 +112,8 @@ export const repositorySchema = z.object({
configId: z.string(),
name: z.string(),
fullName: z.string(),
url: z.string().url(),
cloneUrl: z.string().url(),
url: z.url(),
cloneUrl: z.url(),
owner: z.string(),
organization: z.string().optional().nullable(),
mirroredLocation: z.string().default(""),

View File

@@ -74,7 +74,7 @@ export const getGiteaRepoOwnerAsync = async ({
// Check if repository is starred - starred repos always go to starredReposOrg (highest priority)
if (repository.isStarred) {
return config.giteaConfig.starredReposOrg || "starred";
return config.githubConfig.starredReposOrg || "starred";
}
// Check for repository-specific override (second highest priority)
@@ -119,11 +119,11 @@ export const getGiteaRepoOwner = ({
// Check if repository is starred - starred repos always go to starredReposOrg
if (repository.isStarred) {
return config.giteaConfig.starredReposOrg || "starred";
return config.githubConfig.starredReposOrg || "starred";
}
// Get the mirror strategy - use preserveOrgStructure for backward compatibility
const mirrorStrategy = config.giteaConfig.mirrorStrategy ||
const mirrorStrategy = config.githubConfig.mirrorStrategy ||
(config.giteaConfig.preserveOrgStructure ? "preserve" : "flat-user");
switch (mirrorStrategy) {
@@ -897,7 +897,7 @@ export async function mirrorGitHubOrgToGitea({
});
// Get the mirror strategy - use preserveOrgStructure for backward compatibility
const mirrorStrategy = config.giteaConfig?.mirrorStrategy ||
const mirrorStrategy = config.githubConfig?.mirrorStrategy ||
(config.giteaConfig?.preserveOrgStructure ? "preserve" : "flat-user");
let giteaOrgId: number;
@@ -906,7 +906,7 @@ export async function mirrorGitHubOrgToGitea({
// Determine the target organization based on strategy
if (mirrorStrategy === "single-org" && config.giteaConfig?.organization) {
// For single-org strategy, use the configured destination organization
targetOrgName = config.giteaConfig.defaultOrg || config.giteaConfig.defaultOwner;
targetOrgName = config.giteaConfig.organization || config.giteaConfig.defaultOwner;
giteaOrgId = await getOrCreateGiteaOrg({
orgId: organization.id,
orgName: targetOrgName,

View File

@@ -202,6 +202,7 @@ export function mapDbScheduleToUi(dbSchedule: DbScheduleConfig): any {
export function mapUiCleanupToDb(uiCleanup: any): DbCleanupConfig {
return {
enabled: uiCleanup.enabled || false,
retentionDays: uiCleanup.retentionDays || 604800, // Default to 7 days
deleteFromGitea: false,
deleteIfNotInGitHub: true,
protectedRepos: [],
@@ -218,6 +219,6 @@ export function mapUiCleanupToDb(uiCleanup: any): DbCleanupConfig {
export function mapDbCleanupToUi(dbCleanup: DbCleanupConfig): any {
return {
enabled: dbCleanup.enabled,
retentionDays: 604800, // 7 days in seconds (kept for compatibility)
retentionDays: dbCleanup.retentionDays || 604800, // Use actual value from DB or default to 7 days
};
}

View File

@@ -109,7 +109,7 @@ export const POST: APIRoute = async ({ request }) => {
// For single-org and starred repos strategies, or when mirroring to an org,
// always use the org mirroring function to ensure proper organization handling
const mirrorStrategy = config.giteaConfig?.mirrorStrategy ||
const mirrorStrategy = config.githubConfig?.mirrorStrategy ||
(config.githubConfig?.preserveOrgStructure ? "preserve" : "flat-user");
const shouldUseOrgMirror =

View File

@@ -143,7 +143,7 @@ export const POST: APIRoute = async ({ request }) => {
// For single-org and starred repos strategies, or when mirroring to an org,
// always use the org mirroring function to ensure proper organization handling
const mirrorStrategy = config.giteaConfig?.mirrorStrategy ||
const mirrorStrategy = config.githubConfig?.mirrorStrategy ||
(config.githubConfig?.preserveOrgStructure ? "preserve" : "flat-user");
const shouldUseOrgMirror =