mirror of
https://github.com/amalgamated-tools/mirror-to-gitea.git
synced 2025-12-23 22:18:05 -05:00
add support for mirroring starred repositories to a dedicated Gitea organization and skip issues for starred repos
This commit is contained in:
20
README.md
20
README.md
@@ -60,6 +60,8 @@ All configuration is performed through environment variables. Flags are consider
|
||||
| SINGLE_REPO | no | string | - | URL of a single GitHub repository to mirror (e.g., https://github.com/username/repo or username/repo). When specified, only this repository will be mirrored. Requires `GITHUB_TOKEN`. |
|
||||
| GITEA_ORGANIZATION | no | string | - | Name of a Gitea organization to mirror repositories to. If doesn't exist, will be created. |
|
||||
| GITEA_ORG_VISIBILITY | no | string | public | Visibility of the Gitea organization to create. Can be "public" or "private". |
|
||||
| GITEA_STARRED_ORGANIZATION | no | string | github | Name of a Gitea organization to mirror starred repositories to. If doesn't exist, will be created. Defaults to "github". |
|
||||
| SKIP_STARRED_ISSUES | no | bool | FALSE | If set to `true` will not mirror issues for starred repositories, even if `MIRROR_ISSUES` is enabled. |
|
||||
| SKIP_FORKS | no | bool | FALSE | If set to `true` will disable the mirroring of forks from your GitHub User / Organisation. |
|
||||
| DELAY | no | int | 3600 | Number of seconds between program executions. Setting this will only affect how soon after a new repo was created a mirror may appear on Gitea, but has no affect on the ongoing replication. |
|
||||
| DRY_RUN | no | bool | FALSE | If set to `true` will perform no writing changes to your Gitea instance, but log the planned actions. |
|
||||
@@ -143,6 +145,24 @@ docker container run \
|
||||
jaedle/mirror-to-gitea:latest
|
||||
```
|
||||
|
||||
### Mirror Starred Repositories to a Dedicated Organization
|
||||
|
||||
```sh
|
||||
docker container run \
|
||||
-d \
|
||||
--restart always \
|
||||
-e GITHUB_USERNAME=github-user \
|
||||
-e GITEA_URL=https://your-gitea.url \
|
||||
-e GITEA_TOKEN=please-exchange-with-token \
|
||||
-e GITHUB_TOKEN=your-github-token \
|
||||
-e MIRROR_STARRED=true \
|
||||
-e GITEA_STARRED_ORGANIZATION=github \
|
||||
-e SKIP_STARRED_ISSUES=true \
|
||||
jaedle/mirror-to-gitea:latest
|
||||
```
|
||||
|
||||
This configuration will mirror all starred repositories to a Gitea organization named "github" and will not mirror issues for these starred repositories.
|
||||
|
||||
### Docker Compose
|
||||
|
||||
```yaml
|
||||
|
||||
@@ -26,5 +26,7 @@ docker container run \
|
||||
-e INCLUDE_ORGS="$INCLUDE_ORGS" \
|
||||
-e EXCLUDE_ORGS="$EXCLUDE_ORGS" \
|
||||
-e PRESERVE_ORG_STRUCTURE="$PRESERVE_ORG_STRUCTURE" \
|
||||
-e GITEA_STARRED_ORGANIZATION="$GITEA_STARRED_ORGANIZATION" \
|
||||
-e SKIP_STARRED_ISSUES="$SKIP_STARRED_ISSUES" \
|
||||
-e DRY_RUN="true" \
|
||||
jaedle/mirror-to-gitea:development
|
||||
|
||||
@@ -49,12 +49,14 @@ export function configuration() {
|
||||
.map((o) => o.trim())
|
||||
.filter((o) => o.length > 0),
|
||||
preserveOrgStructure: readBoolean("PRESERVE_ORG_STRUCTURE"),
|
||||
skipStarredIssues: readBoolean("SKIP_STARRED_ISSUES"),
|
||||
},
|
||||
gitea: {
|
||||
url: mustReadEnv("GITEA_URL"),
|
||||
token: mustReadEnv("GITEA_TOKEN"),
|
||||
organization: readEnv("GITEA_ORGANIZATION"),
|
||||
visibility: readEnv("GITEA_ORG_VISIBILITY") || "public",
|
||||
starredReposOrg: readEnv("GITEA_STARRED_ORGANIZATION") || "github",
|
||||
},
|
||||
dryRun: readBoolean("DRY_RUN"),
|
||||
delay: readInt("DELAY") ?? defaultDelay,
|
||||
|
||||
@@ -30,6 +30,19 @@ async function main() {
|
||||
config.dryRun
|
||||
);
|
||||
}
|
||||
|
||||
// Create the starred repositories organization if mirror starred is enabled
|
||||
if (config.github.mirrorStarred && config.gitea.starredReposOrg) {
|
||||
await createGiteaOrganization(
|
||||
{
|
||||
url: config.gitea.url,
|
||||
token: config.gitea.token,
|
||||
},
|
||||
config.gitea.starredReposOrg,
|
||||
config.gitea.visibility,
|
||||
config.dryRun
|
||||
);
|
||||
}
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: config.github.token || null,
|
||||
@@ -127,7 +140,12 @@ async function main() {
|
||||
|
||||
await mirror(
|
||||
repository,
|
||||
gitea,
|
||||
{
|
||||
url: config.gitea.url,
|
||||
token: config.gitea.token,
|
||||
skipStarredIssues: config.github.skipStarredIssues,
|
||||
starredReposOrg: config.gitea.starredReposOrg
|
||||
},
|
||||
giteaTarget,
|
||||
config.github.token,
|
||||
config.github.mirrorIssues,
|
||||
@@ -365,6 +383,18 @@ async function mirrorIssues(repository, gitea, giteaTarget, githubToken, dryRun)
|
||||
|
||||
// Mirror a repository
|
||||
async function mirror(repository, gitea, giteaTarget, githubToken, mirrorIssuesFlag, dryRun) {
|
||||
// For starred repositories, use the starred repos organization if configured
|
||||
if (repository.starred && gitea.starredReposOrg) {
|
||||
// Get the starred repos organization
|
||||
const starredOrg = await getGiteaOrganization(gitea, gitea.starredReposOrg);
|
||||
if (starredOrg) {
|
||||
console.log(`Using organization "${gitea.starredReposOrg}" for starred repository: ${repository.name}`);
|
||||
giteaTarget = starredOrg;
|
||||
} else {
|
||||
console.log(`Could not find organization "${gitea.starredReposOrg}" for starred repositories, using default target`);
|
||||
}
|
||||
}
|
||||
|
||||
const isAlreadyMirrored = await isAlreadyMirroredOnGitea(repository, gitea, giteaTarget);
|
||||
|
||||
// Special handling for starred repositories
|
||||
@@ -395,8 +425,14 @@ async function mirror(repository, gitea, giteaTarget, githubToken, mirrorIssuesF
|
||||
}
|
||||
|
||||
// Mirror issues if requested and not in dry run mode
|
||||
if (mirrorIssuesFlag && !dryRun) {
|
||||
// Skip issues for starred repos if the skipStarredIssues option is enabled
|
||||
const shouldMirrorIssues = mirrorIssuesFlag &&
|
||||
!(repository.starred && gitea.skipStarredIssues);
|
||||
|
||||
if (shouldMirrorIssues && !dryRun) {
|
||||
await mirrorIssues(repository, gitea, giteaTarget, githubToken, dryRun);
|
||||
} else if (repository.starred && gitea.skipStarredIssues) {
|
||||
console.log(`Skipping issues for starred repository: ${repository.name}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error during mirroring of ${repository.name}:`, error.message);
|
||||
|
||||
Reference in New Issue
Block a user