mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-08 20:46:44 +03:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
818ba77693 | ||
|
|
056970e577 | ||
|
|
65ea73e238 |
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [2.16.1] - 2025-06-17
|
||||||
|
|
||||||
|
### Improved
|
||||||
|
- Improved repository owner handling and mirror strategy in Gitea integration
|
||||||
|
- Updated label for starred repositories organization for consistency
|
||||||
|
|
||||||
## [2.16.0] - 2025-06-17
|
## [2.16.0] - 2025-06-17
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "gitea-mirror",
|
"name": "gitea-mirror",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "2.16.0",
|
"version": "2.16.1",
|
||||||
"engines": {
|
"engines": {
|
||||||
"bun": ">=1.2.9"
|
"bun": ">=1.2.9"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export const OrganizationConfiguration: React.FC<OrganizationConfigurationProps>
|
|||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label htmlFor="starredReposOrg" className="text-sm font-normal flex items-center gap-2">
|
<Label htmlFor="starredReposOrg" className="text-sm font-normal flex items-center gap-2">
|
||||||
<Star className="h-3.5 w-3.5" />
|
<Star className="h-3.5 w-3.5" />
|
||||||
Starred Repositories Organization
|
Starred Repos Organization
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger>
|
<TooltipTrigger>
|
||||||
|
|||||||
@@ -160,15 +160,18 @@ export const mirrorGithubRepoToGitea = async ({
|
|||||||
throw new Error("Gitea username is required.");
|
throw new Error("Gitea username is required.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the correct owner based on the strategy
|
||||||
|
const repoOwner = getGiteaRepoOwner({ config, repository });
|
||||||
|
|
||||||
const isExisting = await isRepoPresentInGitea({
|
const isExisting = await isRepoPresentInGitea({
|
||||||
config,
|
config,
|
||||||
owner: config.giteaConfig.username,
|
owner: repoOwner,
|
||||||
repoName: repository.name,
|
repoName: repository.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isExisting) {
|
if (isExisting) {
|
||||||
console.log(
|
console.log(
|
||||||
`Repository ${repository.name} already exists in Gitea. Updating database status.`
|
`Repository ${repository.name} already exists in Gitea under ${repoOwner}. Updating database status.`
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update database to reflect that the repository is already mirrored
|
// Update database to reflect that the repository is already mirrored
|
||||||
@@ -179,7 +182,7 @@ export const mirrorGithubRepoToGitea = async ({
|
|||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
lastMirrored: new Date(),
|
lastMirrored: new Date(),
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
mirroredLocation: `${config.giteaConfig.username}/${repository.name}`,
|
mirroredLocation: `${repoOwner}/${repository.name}`,
|
||||||
})
|
})
|
||||||
.where(eq(repositories.id, repository.id!));
|
.where(eq(repositories.id, repository.id!));
|
||||||
|
|
||||||
@@ -189,7 +192,7 @@ export const mirrorGithubRepoToGitea = async ({
|
|||||||
repositoryId: repository.id,
|
repositoryId: repository.id,
|
||||||
repositoryName: repository.name,
|
repositoryName: repository.name,
|
||||||
message: `Repository ${repository.name} already exists in Gitea`,
|
message: `Repository ${repository.name} already exists in Gitea`,
|
||||||
details: `Repository ${repository.name} was found to already exist in Gitea and database status was updated.`,
|
details: `Repository ${repository.name} was found to already exist in Gitea under ${repoOwner} and database status was updated.`,
|
||||||
status: "mirrored",
|
status: "mirrored",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -238,6 +241,15 @@ export const mirrorGithubRepoToGitea = async ({
|
|||||||
|
|
||||||
const apiUrl = `${config.giteaConfig.url}/api/v1/repos/migrate`;
|
const apiUrl = `${config.giteaConfig.url}/api/v1/repos/migrate`;
|
||||||
|
|
||||||
|
// Handle organization creation if needed for single-org or preserve strategies
|
||||||
|
if (repoOwner !== config.giteaConfig.username && !repository.isStarred) {
|
||||||
|
// Need to create the organization if it doesn't exist
|
||||||
|
await getOrCreateGiteaOrg({
|
||||||
|
orgName: repoOwner,
|
||||||
|
config,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const response = await httpPost(
|
const response = await httpPost(
|
||||||
apiUrl,
|
apiUrl,
|
||||||
{
|
{
|
||||||
@@ -246,7 +258,7 @@ export const mirrorGithubRepoToGitea = async ({
|
|||||||
mirror: true,
|
mirror: true,
|
||||||
wiki: config.githubConfig.mirrorWiki || false, // will mirror wiki if it exists
|
wiki: config.githubConfig.mirrorWiki || false, // will mirror wiki if it exists
|
||||||
private: repository.isPrivate,
|
private: repository.isPrivate,
|
||||||
repo_owner: config.giteaConfig.username,
|
repo_owner: repoOwner,
|
||||||
description: "",
|
description: "",
|
||||||
service: "git",
|
service: "git",
|
||||||
},
|
},
|
||||||
@@ -286,7 +298,7 @@ export const mirrorGithubRepoToGitea = async ({
|
|||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
lastMirrored: new Date(),
|
lastMirrored: new Date(),
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
mirroredLocation: `${config.giteaConfig.username}/${repository.name}`,
|
mirroredLocation: `${repoOwner}/${repository.name}`,
|
||||||
})
|
})
|
||||||
.where(eq(repositories.id, repository.id!));
|
.where(eq(repositories.id, repository.id!));
|
||||||
|
|
||||||
@@ -763,11 +775,37 @@ export async function mirrorGitHubOrgToGitea({
|
|||||||
status: repoStatusEnum.parse("mirroring"),
|
status: repoStatusEnum.parse("mirroring"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const giteaOrgId = await getOrCreateGiteaOrg({
|
// Get the mirror strategy - use preserveOrgStructure for backward compatibility
|
||||||
orgId: organization.id,
|
const mirrorStrategy = config.giteaConfig?.mirrorStrategy ||
|
||||||
orgName: organization.name,
|
(config.githubConfig?.preserveOrgStructure ? "preserve" : "flat-user");
|
||||||
config,
|
|
||||||
});
|
let giteaOrgId: number;
|
||||||
|
let targetOrgName: string;
|
||||||
|
|
||||||
|
// 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.organization;
|
||||||
|
giteaOrgId = await getOrCreateGiteaOrg({
|
||||||
|
orgId: organization.id,
|
||||||
|
orgName: targetOrgName,
|
||||||
|
config,
|
||||||
|
});
|
||||||
|
console.log(`Using single organization strategy: all repos will go to ${targetOrgName}`);
|
||||||
|
} else if (mirrorStrategy === "preserve") {
|
||||||
|
// For preserve strategy, create/use an org with the same name as GitHub
|
||||||
|
targetOrgName = organization.name;
|
||||||
|
giteaOrgId = await getOrCreateGiteaOrg({
|
||||||
|
orgId: organization.id,
|
||||||
|
orgName: targetOrgName,
|
||||||
|
config,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// For flat-user strategy, we shouldn't create organizations at all
|
||||||
|
// Skip organization creation and let individual repos be handled by getGiteaRepoOwner
|
||||||
|
console.log(`Using flat-user strategy: repos will be placed under user account`);
|
||||||
|
targetOrgName = config.giteaConfig?.username || "";
|
||||||
|
}
|
||||||
|
|
||||||
//query the db with the org name and get the repos
|
//query the db with the org name and get the repos
|
||||||
const orgRepos = await db
|
const orgRepos = await db
|
||||||
@@ -805,17 +843,27 @@ export async function mirrorGitHubOrgToGitea({
|
|||||||
|
|
||||||
// Log the start of mirroring
|
// Log the start of mirroring
|
||||||
console.log(
|
console.log(
|
||||||
`Starting mirror for repository: ${repo.name} in organization ${organization.name}`
|
`Starting mirror for repository: ${repo.name} from GitHub org ${organization.name}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// Mirror the repository
|
// Mirror the repository based on strategy
|
||||||
await mirrorGitHubRepoToGiteaOrg({
|
if (mirrorStrategy === "flat-user") {
|
||||||
octokit,
|
// For flat-user strategy, mirror directly to user account
|
||||||
config,
|
await mirrorGithubRepoToGitea({
|
||||||
repository: repoData,
|
octokit,
|
||||||
giteaOrgId,
|
repository: repoData,
|
||||||
orgName: organization.name,
|
config,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// For preserve and single-org strategies, use organization
|
||||||
|
await mirrorGitHubRepoToGiteaOrg({
|
||||||
|
octokit,
|
||||||
|
config,
|
||||||
|
repository: repoData,
|
||||||
|
giteaOrgId: giteaOrgId!,
|
||||||
|
orgName: targetOrgName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return repo;
|
return repo;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user