mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-12 22:46:46 +03:00
fix: preserve chronological issue mirroring
This commit is contained in:
@@ -54,6 +54,8 @@ export const giteaConfigSchema = z.object({
|
||||
.enum(["skip", "reference", "full-copy"])
|
||||
.default("reference"),
|
||||
// Mirror options
|
||||
issueConcurrency: z.number().int().min(1).default(3),
|
||||
pullRequestConcurrency: z.number().int().min(1).default(5),
|
||||
mirrorReleases: z.boolean().default(false),
|
||||
releaseLimit: z.number().default(10),
|
||||
mirrorMetadata: z.boolean().default(false),
|
||||
|
||||
@@ -49,6 +49,9 @@ interface EnvConfig {
|
||||
mirrorLabels?: boolean;
|
||||
mirrorMilestones?: boolean;
|
||||
mirrorMetadata?: boolean;
|
||||
releaseLimit?: number;
|
||||
issueConcurrency?: number;
|
||||
pullRequestConcurrency?: number;
|
||||
};
|
||||
schedule: {
|
||||
enabled?: boolean;
|
||||
@@ -136,6 +139,8 @@ function parseEnvConfig(): EnvConfig {
|
||||
mirrorMilestones: process.env.MIRROR_MILESTONES === 'true',
|
||||
mirrorMetadata: process.env.MIRROR_METADATA === 'true',
|
||||
releaseLimit: process.env.RELEASE_LIMIT ? parseInt(process.env.RELEASE_LIMIT, 10) : undefined,
|
||||
issueConcurrency: process.env.MIRROR_ISSUE_CONCURRENCY ? parseInt(process.env.MIRROR_ISSUE_CONCURRENCY, 10) : undefined,
|
||||
pullRequestConcurrency: process.env.MIRROR_PULL_REQUEST_CONCURRENCY ? parseInt(process.env.MIRROR_PULL_REQUEST_CONCURRENCY, 10) : undefined,
|
||||
},
|
||||
schedule: {
|
||||
enabled: process.env.SCHEDULE_ENABLED === 'true' ||
|
||||
@@ -277,6 +282,12 @@ export async function initializeConfigFromEnv(): Promise<void> {
|
||||
// Mirror metadata options
|
||||
mirrorReleases: envConfig.mirror.mirrorReleases ?? existingConfig?.[0]?.giteaConfig?.mirrorReleases ?? false,
|
||||
releaseLimit: envConfig.mirror.releaseLimit ?? existingConfig?.[0]?.giteaConfig?.releaseLimit ?? 10,
|
||||
issueConcurrency: envConfig.mirror.issueConcurrency && envConfig.mirror.issueConcurrency > 0
|
||||
? envConfig.mirror.issueConcurrency
|
||||
: existingConfig?.[0]?.giteaConfig?.issueConcurrency ?? 3,
|
||||
pullRequestConcurrency: envConfig.mirror.pullRequestConcurrency && envConfig.mirror.pullRequestConcurrency > 0
|
||||
? envConfig.mirror.pullRequestConcurrency
|
||||
: existingConfig?.[0]?.giteaConfig?.pullRequestConcurrency ?? 5,
|
||||
mirrorMetadata: envConfig.mirror.mirrorMetadata ?? (envConfig.mirror.mirrorIssues || envConfig.mirror.mirrorPullRequests || envConfig.mirror.mirrorLabels || envConfig.mirror.mirrorMilestones) ?? existingConfig?.[0]?.giteaConfig?.mirrorMetadata ?? false,
|
||||
mirrorIssues: envConfig.mirror.mirrorIssues ?? existingConfig?.[0]?.giteaConfig?.mirrorIssues ?? false,
|
||||
mirrorPullRequests: envConfig.mirror.mirrorPullRequests ?? existingConfig?.[0]?.giteaConfig?.mirrorPullRequests ?? false,
|
||||
|
||||
@@ -1558,6 +1558,8 @@ export const mirrorGitRepoIssuesToGitea = async ({
|
||||
repo,
|
||||
state: "all",
|
||||
per_page: 100,
|
||||
sort: "created",
|
||||
direction: "asc",
|
||||
},
|
||||
(res) => res.data
|
||||
);
|
||||
@@ -1590,6 +1592,12 @@ export const mirrorGitRepoIssuesToGitea = async ({
|
||||
// Import the processWithRetry function
|
||||
const { processWithRetry } = await import("@/lib/utils/concurrency");
|
||||
|
||||
const rawIssueConcurrency = config.giteaConfig?.issueConcurrency ?? 3;
|
||||
const issueConcurrencyLimit =
|
||||
Number.isFinite(rawIssueConcurrency)
|
||||
? Math.max(1, Math.floor(rawIssueConcurrency))
|
||||
: 3;
|
||||
|
||||
// Process issues in parallel with concurrency control
|
||||
await processWithRetry(
|
||||
filteredIssues,
|
||||
@@ -1694,7 +1702,7 @@ export const mirrorGitRepoIssuesToGitea = async ({
|
||||
return issue;
|
||||
},
|
||||
{
|
||||
concurrencyLimit: 3, // Process 3 issues at a time
|
||||
concurrencyLimit: issueConcurrencyLimit,
|
||||
maxRetries: 2,
|
||||
retryDelay: 2000,
|
||||
onProgress: (completed, total, result) => {
|
||||
@@ -1966,6 +1974,8 @@ export async function mirrorGitRepoPullRequestsToGitea({
|
||||
repo,
|
||||
state: "all",
|
||||
per_page: 100,
|
||||
sort: "created",
|
||||
direction: "asc",
|
||||
},
|
||||
(res) => res.data
|
||||
);
|
||||
@@ -2022,6 +2032,12 @@ export async function mirrorGitRepoPullRequestsToGitea({
|
||||
|
||||
const { processWithRetry } = await import("@/lib/utils/concurrency");
|
||||
|
||||
const rawPullConcurrency = config.giteaConfig?.pullRequestConcurrency ?? 5;
|
||||
const pullRequestConcurrencyLimit =
|
||||
Number.isFinite(rawPullConcurrency)
|
||||
? Math.max(1, Math.floor(rawPullConcurrency))
|
||||
: 5;
|
||||
|
||||
let successCount = 0;
|
||||
let failedCount = 0;
|
||||
|
||||
@@ -2144,7 +2160,7 @@ export async function mirrorGitRepoPullRequestsToGitea({
|
||||
}
|
||||
},
|
||||
{
|
||||
concurrencyLimit: 5,
|
||||
concurrencyLimit: pullRequestConcurrencyLimit,
|
||||
maxRetries: 3,
|
||||
retryDelay: 1000,
|
||||
}
|
||||
|
||||
@@ -86,6 +86,8 @@ export async function createDefaultConfig({ userId, envOverrides = {} }: Default
|
||||
addTopics: true,
|
||||
preserveVisibility: false,
|
||||
forkStrategy: "reference",
|
||||
issueConcurrency: 3,
|
||||
pullRequestConcurrency: 5,
|
||||
},
|
||||
include: [],
|
||||
exclude: [],
|
||||
|
||||
@@ -89,6 +89,8 @@ export function mapUiToDbConfig(
|
||||
forkStrategy: advancedOptions.skipForks ? "skip" : "reference",
|
||||
|
||||
// Mirror options from UI
|
||||
issueConcurrency: giteaConfig.issueConcurrency ?? 3,
|
||||
pullRequestConcurrency: giteaConfig.pullRequestConcurrency ?? 5,
|
||||
mirrorReleases: mirrorOptions.mirrorReleases,
|
||||
releaseLimit: mirrorOptions.releaseLimit || 10,
|
||||
mirrorMetadata: mirrorOptions.mirrorMetadata,
|
||||
@@ -132,6 +134,8 @@ export function mapDbToUiConfig(dbConfig: any): {
|
||||
preserveOrgStructure: dbConfig.giteaConfig?.preserveVisibility || false, // Map preserveVisibility
|
||||
mirrorStrategy: dbConfig.githubConfig?.mirrorStrategy || "preserve", // Get from GitHub config
|
||||
personalReposOrg: undefined, // Not stored in current schema
|
||||
issueConcurrency: dbConfig.giteaConfig?.issueConcurrency ?? 3,
|
||||
pullRequestConcurrency: dbConfig.giteaConfig?.pullRequestConcurrency ?? 5,
|
||||
};
|
||||
|
||||
// Map mirror options from various database fields
|
||||
|
||||
@@ -13,6 +13,8 @@ export interface GiteaConfig {
|
||||
preserveOrgStructure: boolean;
|
||||
mirrorStrategy?: MirrorStrategy; // New field for the strategy
|
||||
personalReposOrg?: string; // Override destination for personal repos
|
||||
issueConcurrency?: number;
|
||||
pullRequestConcurrency?: number;
|
||||
}
|
||||
|
||||
export interface ScheduleConfig {
|
||||
|
||||
Reference in New Issue
Block a user