Commit b02bbfc1 authored by Clement Bois's avatar Clement Bois
Browse files

Merge branch 'fix/DestKeepBaseURL' into 'main'

fix:  Added option to keep base URL for destination GitLab

Closes #11

See merge request to-be-continuous/tools/gitlab-cp!83
parents 290a7cf9 c92f9986
Loading
Loading
Loading
Loading
+33 −30
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ gitlab-cp --help
## Usage

```bash
usage: gitlab-cp [-h] [--src-api SRC_API] [--src-token SRC_TOKEN] [--src-sync-path SRC_SYNC_PATH] [--dest-api DEST_API] [--dest-token DEST_TOKEN] [--dest-sync-path DEST_SYNC_PATH]
usage: gitlab-cp [-h] [--src-api SRC_API] [--src-token SRC_TOKEN] [--src-sync-path SRC_SYNC_PATH] [--dest-api DEST_API] [--dest-token DEST_TOKEN] [--dest-sync-path DEST_SYNC_PATH] [--dest-keep-base-url DEST_KEEP_BASE_URL]
                 [--max-visibility {public,internal,private}] [--skip-visibility] [--exclude EXCLUDE] [--exclude-from EXCLUDE_FROM] [--include INCLUDE] [--include-from INCLUDE_FROM] [--insecure]
                 [--include-branch INCLUDE_BRANCH] [--exclude-branch EXCLUDE_BRANCH] [--update-release] [--deny-release-hash-change] [--update-avatar] [--no-group-description] [--no-project-description] [--new-group-options NEW_GROUP_OPTIONS]
                 [--new-group-options-from NEW_GROUP_OPTIONS_FROM] [--new-project-options NEW_PROJECT_OPTIONS] [--new-project-options-from NEW_PROJECT_OPTIONS_FROM] [--dry-run] [--halt-on-error]
@@ -38,6 +38,8 @@ options:
                        GitLab destination token with at least scopes `api,read_repository,write_repository` and `Owner` role
  --dest-sync-path DEST_SYNC_PATH
                        GitLab destination root group path to synchronize (defaults to --src-sync-path)
  --dest-keep-base-url DEST_KEEP_BASE_URL
                        Keep base URL for destination GitLab
  --max-visibility {public,internal,private}
                        maximum visibility of groups and projects in destination group
  --skip-visibility     skip updating the destination group or project visibility (when it exists already)
@@ -78,13 +80,14 @@ options:
```

| CLI option                   | Env. Variable                   | Description                                                                                                                                                                                                                                              |
| ---------------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| ---------------------------- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--src-api`                  | `$SRC_GITLAB_API`               | GitLab source API url (**mandatory**)                                                                                                                                                                                                                    |
| `--src-token`                | `$SRC_TOKEN`                    | GitLab source token (_optional_ if source GitLab group and sub projects have `public` visibility)                                                                                                                                                        |
| `--src-sync-path`            | `$SRC_SYNC_PATH`                | GitLab source root group path to synchronize (**mandatory**)                                                                                                                                                                                             |
| `--dest-api`                 | `$DEST_GITLAB_API`              | GitLab destination API url (**mandatory**)                                                                                                                                                                                                               |
| `--dest-token`               | `$DEST_TOKEN`                   | GitLab destination token with at least scopes `api,read_repository,write_repository` and `Owner` role (**mandatory**)                                                                                                                                    |
| `--dest-sync-path`           | `$DEST_SYNC_PATH`               | GitLab destination root group path to synchronize (defaults to `--src-sync-path`)                                                                                                                                                                        |
| `--dest-keep-base-url`       | `$DEST_KEEP_BASE_URL`           | Keep base URL for destination GitLab (defaults to `false`)                                                                                                                                                                                               |
| `--max-visibility`           | `$MAX_VISIBILITY`               | maximum visibility of projects in destination group (defaults to `public`)                                                                                                                                                                               |
| `--skip-visibility`          | `$SKIP_VISIBILITY`              | skip updating the destination group or project visibility (when it exists already)                                                                                                                                                                       |
| `--exclude`                  | `$EXCLUDE`                      | project/group path(s) to exclude (multiple CLI option; env. variable is a coma separated list; wins over `--include`)                                                                                                                                    |
+10 −0
Original line number Diff line number Diff line
@@ -988,6 +988,12 @@ def run() -> None:
        default=os.getenv("DEST_SYNC_PATH"),
        help="GitLab destination root group path to synchronize (defaults to --src-sync-path)",
    )
    parser.add_argument(
        "--dest-keep-base-url",
        default=trueish_env_var("DEST_KEEP_BASE_URL"),
        action="store_true",
        help="Keep base URL for destination GitLab",
    )
    parser.add_argument(
        "--max-visibility",
        default=os.getenv("MAX_VISIBILITY") or GlVisibility.public,
@@ -1221,6 +1227,9 @@ def run() -> None:
    print(
        f"- dest path   (--dest-sync-path) : {AnsiColors.CYAN}{dest_sync_path}{AnsiColors.RESET}"
    )
    print(
        f"- dest keep base url (--dest-keep-base-url) : {AnsiColors.CYAN}{args.dest_keep_base_url}{AnsiColors.RESET}"
    )
    print(
        f"- max visi.   (--max-visibility) : {AnsiColors.CYAN}{args.max_visibility}{AnsiColors.RESET}"
    )
@@ -1298,6 +1307,7 @@ def run() -> None:
                private_token=args.dest_token,
                ssl_verify=not args.insecure,
                per_page=100,
                keep_base_url=args.dest_keep_base_url,
            )
            if args.dest_api
            else None