Commit 6f7f91ed authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch 'enhancements' into 'main'

enhancements

See merge request to-be-continuous/tools/gitlab-cp!7
parents 8b6a51d1 21114841
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
include:
  # $TBC_NAMESPACE is a group variable; can be globally overridden
  # Docker template
  - component: "gitlab.com/$TBC_NAMESPACE/docker/gitlab-ci-docker@5.9"
  - component: "gitlab.com/$TBC_NAMESPACE/docker/gitlab-ci-docker@5"
    inputs:
      healthcheck-disabled: true
      sbom-disabled: true
@@ -9,9 +9,10 @@ include:
      prod-publish-strategy: "auto"
      release-extra-tags: "latest \\g<major>.\\g<minor>\\g<build> \\g<major>\\g<build>"
  # Python template
  - component: "gitlab.com/$TBC_NAMESPACE/python/gitlab-ci-python@6.7"
  - component: "gitlab.com/$TBC_NAMESPACE/python/gitlab-ci-python@6"
    inputs:
      image: "registry.hub.docker.com/library/python:3.12"
      ruff-enabled: true
      sbom-disabled: true
      package-enabled: true
      release-enabled: true
@@ -24,3 +25,21 @@ include:
py-release:
  rules:
    - when: never

dry-run-test:
  extends: .python-base
  stage: test
  variables:
    SRC_GITLAB_API: https://gitlab.com/api/v4
    SRC_SYNC_PATH: to-be-continuous
    DEST_GITLAB_API: https://gitlab.com/api/v4
    DEST_SYNC_PATH: tbc-offtracks/to-be-continuous
    MAX_VISIBILITY: private
    EXCLUDE: samples
    # DEST_TOKEN is declared as a project secret variable
  script:
    - install_requirements
    - poetry run gitlab-cp --dry-run
  rules:
    # run only on original project on gitlab.com
    - if: '$CI_SERVER_HOST == "gitlab.com" && $CI_PROJECT_PATH == "to-be-continuous/tools/gitlab-cp"'
+11 −8
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@ 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] [--max-visibility {public,internal,private}]
                 [--exclude EXCLUDE] [--insecure] [--update-release] [--update-avatar] [--no-group-description] [--no-project-description] [--dry-run] [--halt-on-error]
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] [--max-visibility {public,internal,private}] [--exclude EXCLUDE] [--insecure]
                 [--update-release] [--update-avatar] [--no-group-description] [--no-project-description] [--dry-run] [--halt-on-error] [--cache-dir CACHE_DIR]

This tool recursively copies/synchronizes a GitLab group from one GitLab server to another.

@@ -37,33 +37,36 @@ options:
                        maximum visibility of projects in destination group
  --exclude EXCLUDE     project/group path to exclude from processing (relative to --src-sync-path)
  --insecure            skip SSL verification
  --update-release      force update the releases even when they exist
  --update-release      force the update of the latest release
  --update-avatar       force update the avatar images even when they exist and look the same
  --no-group-description
                        don't synchronize group description
  --no_project-description
  --no-project-description
                        don't synchronize project description
  --dry-run             dry run (don't execute any write action)
  --halt-on-error       halt synchronizing whenever an error occurs
  --cache-dir CACHE_DIR
                        cache directory (used to download resources such as images and Git repositories)
```

| CLI option                 | Env. Variable                   | Description                                                                                                           |
| -------------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `--src-api`                | `$SRC_GITLAB_API`               | GitLab source API url                                                                                                 |
| `--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                                                                          |
| `--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`)                                     |
| `--max-visibility`         | `$MAX_VISIBILITY`               | maximum visibility of projects in destination group (default to `public`)                                             |
| `--max-visibility`         | `$MAX_VISIBILITY`               | maximum visibility of projects in destination group (defaults to `public`)                                            |
| `--exclude`                | `$EXCLUDE`                      | project/group path(s) to exclude (multiple CLI option; env. variable is a coma separated list)                        |
| `--insecure`               | `$INSECURE`                     | skip SSL verification                                                                                                 |
| `--update-release`         | `$UPDATE_RELEASE`               | set to update the releases even if they exists                                                                        |
| `--update-release`         | `$UPDATE_RELEASE`               | set to force the update of the latest release (in order to trigger GitLab CI/CD catalog publication)                  |
| `--update-avatar`          | `$UPDATE_AVATAR`                | force update the avatar images even when they exist and look the same                                                 |
| `--no-group-description`   | `$GROUP_DESCRIPTION_DISABLED`   | don't synchronize group description                                                                                   |
| `--no-project-description` | `$PROJECT_DESCRIPTION_DISABLED` | don't synchronize project description                                                                                 |
| `--dry-run`                | _none_                          | dry run (don't execute any write action)                                                                              |
| `--halt-on-error`          | _none_                          | halt synchronizing when an error occurs                                                                               |
| `--cache-dir`              | `$CACHE_DIR`                    | cache directory (used to download resources such as images and Git repositories) (defaults to `.work`)                |

## Developers

+310 −292

File changed.

Preview size limit exceeded, changes collapsed.

+85 −358

File changed.

Preview size limit exceeded, changes collapsed.

+17 −8
Original line number Diff line number Diff line
@@ -25,8 +25,7 @@ pytest = "^7.0.0"
pytest-cov = "^4.0.0"
pytest-env = "^0.8.0"
mypy = "^1.0.0"
pylint = "^2.17.5"
black = "^24.1.1"
ruff = "^0.4.1"

[tool.pytest.ini_options]
# this project uses "pytest" for unit testing
@@ -35,12 +34,22 @@ testpaths = [
    "tests",
]

[tool.black]
# this project uses "Black" as code formatter
# see: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#usage
line-length = 88
target-version = ['py312']
include = '\.pyi?$'
[tool.ruff.lint]
extend-select = ["I"] # isort
ignore = ["F841"]

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

[tool.mypy]
# this project uses "mypy" as a static type checker