This repository has been archived on 2025-04-03. You can view files and clone it, but cannot push or open issues or pull requests.
linux-bash-scripts/gitlab2gitea
2024-07-18 12:49:34 +02:00
..
gitlab2gitea.py Added README and requirements.txt 2024-07-18 12:49:34 +02:00
README.md Added README and requirements.txt 2024-07-18 12:49:34 +02:00
requirements.txt Added README and requirements.txt 2024-07-18 12:49:34 +02:00

GitLab to Gitea Migration Script

Note: This script is still work in progess!

Description

This script is designed to migrate repositories from GitLab to Gitea.

Author(s)

License

MIT License. For more details, refer to the LICENSE file.

Precedence of Settings

Settings will be applied in the following order:

  1. Command-line arguments
  2. .env file
  3. Environment variables
  4. Default values

Usage

python3 gitlab2gitea.py [options]

Options

Option Description
--help Show help message and exit.
--gitlab-token <GITLAB_TOKEN> GitLab access token.
--gitlab-url <GITLAB_URL> GitLab URL.
--gitlab-api-version <GITLAB_API_VERSION> GitLab API version (default: v4).
--gitea-token <GITEA_TOKEN> Gitea access token.
--gitea-url <GITEA_URL> Gitea URL.
--gitea-api-version <GITEA_API_VERSION> Gitea API version (default: v1).
--no-create-missing-groups Do not create missing groups on Gitea (default: False).
--no-create-missing-users Do not create missing users on Gitea (default: False).
--no-create-missing-projects Do not create missing projects on Gitea (default: False).
--no-update-existing-groups Do not update existing groups on Gitea (default: False).
--no-update-existing-users Do not update existing users on Gitea (default: False).
--no-update-existing-projects Do not update existing projects on Gitea (default: False).
--only-groups Migrate only groups (default: False).
--only-users Migrate only users (default: False).
--only-projects Migrate only projects (default: False).
--quiet Enable quiet mode (default: False).
--debug Enable debug mode (default: False).
--trace Enable trace mode (default: False).
--dry-run Enable dry-run mode (default: False).
--log-file <LOG_FILE> Log file (default: gitlab2gitea.log). If not set, logs will be only printed to stdout.
--append-log Append to log file instead of overwriting (default: False).

Example

python3 gitlab2gitea.py \
  --gitlab-url <GITLAB_URL> \
  --gitlab-token <GITLAB_TOKEN> \
  --gitea-url <GITEA_URL> \
  --gitea-token <GITEA_TOKEN>

Environment Variables

Option Description
GITLAB_URL The full URL to your Gitlab instance (e.g. https://gitlab.myhost.com)
GITLAB_TOKEN The access token from your Gitlab instance (see here)
GITLAB_API_VERSION The API version to be used (default: v4) - do not change unless you know, what you do.
GITEA_URL The full URL to your Gitea instance (e.g. https://gitea.myhost.com)
GITEA_TOKEN The access token from your Gitea instance (example URL to find the settings: https://gitea.myhost.com/user/settings/applications)
GITEA_API_VERSION The API version to be used (default: v1) - do not change unless you know, what you do.
NO_CREATE_MISSING_GROUPS Set to prevent creation of groups in Gitea (default: 0, allowed: 0 or 1)
NO_CREATE_MISSING_USERS Set to prevent creation of users in Gitea (default: 0, allowed: 0 or 1)
NO_CREATE_MISSING_PROJECTS Set to prevent creation of projects in Gitea (default: 0, allowed: 0 or 1)
NO_UPDATE_EXISTING_GROUPS Set to prevent updating of existing groups in Gitea (default: 0, allowed: 0 or 1)
NO_UPDATE_EXISTING_USERS Set to prevent updating of existing users in Gitea (default: 0, allowed: 0 or 1)
NO_UPDATE_EXISTING_PROJECTS Set to prevent updating of existing projects in Gitea (default: 0, allowed: 0 or 1)
ONLY_GROUPS Set to only migrate groups to Gitea (default: 0, allowed: 0 or 1)
ONLY_USERS Set to only migrate users to Gitea (default: 0, allowed: 0 or 1)
ONLY_PROJECTS Set to only migrate projects to Gitea (default: 0, allowed: 0 or 1)
DEBUG Enable or disable debug output (default: 0, allowed: 0 or 1)
TRACE Enable or disable trace (or verbose) output (default: 0, allowed: 0 or 1)
DRY_RUN Only do a dry run, no actual migration will be performed and no data will be changed (default: 0, allowed: 0 or 1)
LOG_FILE Path to the log file (default: gitlab2gitea.log, allowed: a valid file path or "" to disable file logging)
APPEND_LOG Enable or disable appending log output to the specified log file (default: 0, allowed: 0 or 1)
QUIET Enable or disable quiet mode (default: 0, allowed: 0 or 1)

Notes & Caveats

  • Mutually Exclusive Options: Some options cannot be used together, such as:

    • --only-groups and --only-users
    • --only-groups and --only-projects
    • --only-users and --only-projects
  • Reserved Usernames: Gitea has reserved usernames like "ghost" and "notifications"; these should be avoided.

Script Overview

The script performs the following actions:

  1. Reading Configuration: Fetch configuration from environment variables, .env file, and command-line arguments.
  2. Check Endpoints: Validates access to GitLab and Gitea endpoints.
  3. Migration:
    • Groups: Compares, creates, and updates groups between GitLab and Gitea.
    • Users: Compares, creates, and updates users between GitLab and Gitea.
    • Projects: (Implementation pending for creating and updating projects).

Note: For complete usage, ensure you have the required Python packages by running:

pip install -r requirements.txt

For any issues, please refer to the contact details provided in the author's contact information section.