From 160e3b9f88b480051fa06a5fab9aa7b8a74d57c7 Mon Sep 17 00:00:00 2001 From: Enrico Ludwig Date: Thu, 18 Jul 2024 12:49:34 +0200 Subject: [PATCH] Added README and requirements.txt --- gitlab2gitea/README.md | 111 ++++++++++++++++++++++++++++++++++ gitlab2gitea/gitlab2gitea.py | 5 +- gitlab2gitea/requirements.txt | 1 + 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 gitlab2gitea/README.md create mode 100644 gitlab2gitea/requirements.txt diff --git a/gitlab2gitea/README.md b/gitlab2gitea/README.md new file mode 100644 index 0000000..83c555f --- /dev/null +++ b/gitlab2gitea/README.md @@ -0,0 +1,111 @@ +# 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) +- [Enrico Ludwig](https://git.zion-networks.de/eludwig) <[enrico.ludwig@zion-networks.de](mailto:enrico.ludwig@zion-networks.de?subject=Gitlab%20to%20Gitea%20migration%20script)> + +## License +MIT License. For more details, refer to the [LICENSE](https://git.zion-networks.de/ZionNetworks/linux-bash-scripts/src/branch/main/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 +```sh +python3 gitlab2gitea.py [options] +``` + +## Options +| Option | Description | +| ------------------------------------------- | -------------------------------------------------------------------------------------- | +| `--help` | Show help message and exit. | +| `--gitlab-token ` | GitLab access token. | +| `--gitlab-url ` | GitLab URL. | +| `--gitlab-api-version ` | GitLab API version (default: v4). | +| `--gitea-token ` | Gitea access token. | +| `--gitea-url ` | Gitea URL. | +| `--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 (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 +```sh +python3 gitlab2gitea.py \ + --gitlab-url \ + --gitlab-token \ + --gitea-url \ + --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](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#create-a-personal-access-token)) | +| `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: +```sh +pip install -r requirements.txt +``` + +For any issues, please refer to the contact details provided in the author's contact information section. \ No newline at end of file diff --git a/gitlab2gitea/gitlab2gitea.py b/gitlab2gitea/gitlab2gitea.py index 32611ac..b3fe7ae 100644 --- a/gitlab2gitea/gitlab2gitea.py +++ b/gitlab2gitea/gitlab2gitea.py @@ -1,7 +1,7 @@ # Description: Script to migrate repositories from GitLab to Gitea # Author: Enrico Ludwig # Version: 1.0 -# Date: 2024-07-14 +# Date: 2024-07-18 # License: MIT (see https://git.zion-networks.de/ZionNetworks/linux-bash-scripts/src/branch/main/LICENSE) # # Precedence of settings: arguments > .env file > environment variables > default values @@ -29,6 +29,9 @@ # --override-users Override existing users on Gitea (default: False) - not implemented yet # --override-projects Override existing projects on Gitea (default: False) - not implemented yet # +# --skip-empty-groups Skip empty groups (default: False) - not implemented yet +# --skip-empty-projects Skip empty projects (default: False) - not implemented yet +# # --only-groups Migrate only groups (default: False) # --only-users Migrate only users (default: False) # --only-projects Migrate only projects (default: False) diff --git a/gitlab2gitea/requirements.txt b/gitlab2gitea/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/gitlab2gitea/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file