stouputils.continuous_delivery.gitlab module#

This module contains utilities for continuous delivery on GitLab.

  • upload_to_gitlab: Upload the project to GitLab using the credentials and the configuration (make a release and upload the assets, handle existing tag, generate changelog, etc.)

validate_gitlab_credentials(
credentials: dict[str, dict[str, str]],
gitlab_url: str,
) tuple[str, dict[str, str]][source]#

Get and validate GitLab credentials.

Parameters:
  • credentials – Credentials dictionary with ‘gitlab’ key containing ‘api_key’

  • gitlab_url – Default GitLab instance URL

Returns:

(gitlab_url, headers dict)

Return type:

tuple

Raises:

ValueError – If required keys are missing

validate_gitlab_config(
gitlab_config: dict[str, Any],
) tuple[str, str, str, list[str]][source]#

Validate GitLab configuration.

Parameters:

gitlab_config – Configuration dictionary

Returns:

(project_path, version, build_folder, endswith list)

Return type:

tuple

Raises:

ValueError – If required keys are missing

build_gitlab_config(
gitlab_url: str,
headers: dict[str, str],
project_path: str,
version: str,
build_folder: str,
endswith: list[str],
) PlatformConfig[source]#

Build a PlatformConfig for GitLab.

Parameters:
  • gitlab_url – GitLab instance URL

  • headers – HTTP headers with authorization

  • project_path – Full project path (e.g., “namespace/project”)

  • version – Version to release

  • build_folder – Path to build assets

  • endswith – File suffixes to upload

Returns:

Configuration for GitLab release

Return type:

PlatformConfig

delete_gitlab_release(
config: PlatformConfig,
) None[source]#

Delete existing GitLab release for the configured version.

delete_gitlab_tag(
config: PlatformConfig,
) None[source]#

Delete existing GitLab tag for the configured version.

get_gitlab_sha(tag: dict[str, Any]) str[source]#

Extract SHA from a GitLab tag response.

get_gitlab_commit_date(
commit: dict[str, Any],
) str[source]#

Extract date from a GitLab commit response.

extract_gitlab_commit_data(
commits: list[dict[str, Any]],
) list[tuple[str, str]][source]#

Extract (sha, message) tuples from GitLab commits.

create_gitlab_tag(
config: PlatformConfig,
) None[source]#

Create a new tag on GitLab.

create_gitlab_release(
config: PlatformConfig,
changelog: str,
) None[source]#

Create a new GitLab release.

Parameters:
  • config – Platform configuration

  • changelog – Changelog text for the release description

upload_gitlab_assets(
config: PlatformConfig,
) None[source]#

Upload release assets to GitLab via Package Registry.

Parameters:

config – Platform configuration

upload_to_gitlab(
credentials: dict[str, Any],
gitlab_config: dict[str, Any],
gitlab_url: str = 'https://gitlab.com',
) str[source]#

Upload the project to GitLab using the credentials and the configuration.

Parameters:
  • credentials – Credentials for the GitLab API

  • gitlab_config – Configuration for the GitLab project

  • gitlab_url – GitLab instance URL (default: https://gitlab.com)

Returns:

Generated changelog text

Return type:

str

Examples:

> upload_to_gitlab(
        credentials={
                "gitlab": {
                        "api_key": "glpat-...",
                }
        },
        gitlab_config={
                "project_path": "DataScience/chestia",
                "version": "1.0.0",
                "build_folder": "dist",
                "endswith": [".tar.gz", ".whl"]
        },
        gitlab_url="https://gitlab.example.com"
)