|
||
---|---|---|
.. | ||
gitea | ||
github | ||
utils | ||
__init__.py | ||
__main__.py | ||
cli.py | ||
mirror.py | ||
README.md | ||
web.py |
GitHub to Gitea Mirror - Core Package
This is the core package for the GitHub to Gitea Mirror tool. It contains the main functionality for mirroring GitHub repositories to Gitea.
Package Structure
__init__.py
: Package initialization__main__.py
: Entry point for running the package as a modulecli.py
: Command-line interfacemirror.py
: Main mirroring logicweb.py
: Web UI
Subpackages
-
github/
: GitHub API interactionsapi.py
: GitHub API client
-
gitea/
: Gitea API interactionsrepository.py
: Repository managementrelease.py
: Release managementissue.py
: Issue managementpr.py
: Pull request managementcomment.py
: Comment managementwiki.py
: Wiki managementmetadata.py
: Labels, milestones, and other metadata
-
utils/
: Utility functionsconfig.py
: Configuration managementlogging.py
: Logging setup
Development
Adding New Features
When adding new features, follow these guidelines:
- Modular Design: Keep functionality in appropriate modules
- Error Handling: Use try/except blocks for API calls
- Logging: Log all significant actions and errors
- Configuration: Make features configurable where appropriate
Testing
Run tests with:
python -m unittest discover tests
API Documentation
Mirror Module
The mirror.py
module contains the main mirroring logic:
-
mirror_repository(github_token, gitea_token, gitea_url, github_repo, gitea_owner, gitea_repo, ...)
: Set up a repository as a pull mirror from GitHub to Gitea and sync releases -
process_all_repositories(github_token, gitea_token, gitea_url, ...)
: Process all mirrored repositories from Gitea
Web Module
The web.py
module contains the Flask web application:
- Routes:
/
: Home page/repos
: Repository list/repos/<owner>/<repo>
: Repository configuration/logs
: Log list/logs/<filename>
: View log/run
: Run mirror script/config
: Global configuration/add
: Add repository/health
: Health check endpoint
Utility Modules
-
config.py
: Configuration managementload_config()
: Load configuration from environment variablesget_repo_config(github_repo, gitea_owner, gitea_repo)
: Get repository-specific configurationsave_repo_config(github_repo, gitea_owner, gitea_repo, config)
: Save repository-specific configuration
-
logging.py
: Logging setupsetup_logging()
: Set up logging configurationget_current_log_filename(logger)
: Get the current log file name from logger handlers
Performance Considerations
- API calls are rate-limited, so be mindful of the number of calls made
- Large repositories with many issues/PRs may take a long time to mirror
- Consider using caching for frequently accessed data
- Log files can grow large, so log rotation is implemented
Usage
Command Line
# Run as a module
python -m gitmirror
# Mirror a specific repository
python -m gitmirror <github_repo> <gitea_owner> <gitea_repo>
# List mirrored repositories
python -m gitmirror --list-repos
# Force recreation of repositories
python -m gitmirror --force-recreate
# Skip mirroring metadata (issues, PRs, labels, milestones, wikis)
python -m gitmirror --skip-metadata
# Combine flags
python -m gitmirror <github_repo> <gitea_owner> <gitea_repo> --skip-metadata
Note: By default, metadata mirroring is enabled when using the CLI, but disabled in the repository configuration. Use the --skip-metadata
flag to disable metadata mirroring from the CLI.
Web UI
# Start the web UI
python -m gitmirror.web
Docker Usage
The recommended way to use this package is through Docker:
# Start the web UI
docker-compose up -d
# Run the mirror script
docker-compose run --rm mirror
See the main README.md for more details on Docker usage.