stouputils.continuous_delivery.release_common module#
This module contains shared utilities for release management on Git hosting platforms.
It provides common functionality used by both GitHub and GitLab modules.
- class PlatformConfig(
- base_url: str,
- project_identifier: str,
- headers: dict[str, str],
- version: str,
- build_folder: str,
- endswith: list[str],
- project_api_url: str,
- web_url: str,
- tag_api_path: str = '',
- commit_api_path: str = '',
- release_api_path: str = '/releases',
- commit_url_path: str = '',
- compare_url_path: str = '',
- platform_name: str = '',
Bases:
objectConfiguration for a Git hosting platform release.
- base_url: str#
//gitlab.com”)
- Type:
Base URL of the platform (e.g., “https
- Type:
//api.github.com” or “https
- project_identifier: str#
Project identifier (e.g., “owner/repo” for GitHub, “namespace/project” for GitLab)
- headers: dict[str, str]#
HTTP headers for API requests
- version: str#
Version to release
- build_folder: str#
Folder containing build assets
- endswith: list[str]#
File suffixes to upload
- project_api_url: str#
API URL for project operations
- web_url: str#
Web URL for user-facing links
- tag_api_path: str = ''#
API path for tags (e.g., “/repository/tags” or “/tags”)
- commit_api_path: str = ''#
API path for commits
- release_api_path: str = '/releases'#
API path for releases
- commit_url_path: str = ''#
URL path for commits in web UI (e.g., “/commit/” or “/-/commit/”)
- compare_url_path: str = ''#
URL path for compare in web UI
- platform_name: str = ''#
Platform name for logging (e.g., “GitHub”, “GitLab”)
- validate_required_keys(
- config: dict[str, Any],
- required_keys: list[str],
- config_name: str,
Validate that required keys exist in a configuration dictionary.
- Parameters:
config – Configuration dictionary to validate
required_keys – List of required key names
config_name – Name of the configuration (for error messages)
- Raises:
ValueError – If any required key is missing
- check_existing_tag(
- config: PlatformConfig,
- tag_url: str,
Check if a tag exists.
- Parameters:
config – Platform configuration
tag_url – URL to check for tag existence
- Returns:
True if tag exists
- Return type:
bool
- prompt_delete_existing(
- config: PlatformConfig,
- delete_release_func: Callable[[PlatformConfig], None],
- delete_tag_func: Callable[[PlatformConfig], None],
Prompt user to delete existing tag and release.
- Parameters:
config – Platform configuration
delete_release_func – Function to delete the release
delete_tag_func – Function to delete the tag
- Returns:
True if user chose to delete, False otherwise
- Return type:
bool
- handle_existing_tag(
- config: PlatformConfig,
- tag_url: str,
- delete_tag_func: Callable[[PlatformConfig], None],
- delete_release_func: Callable[[PlatformConfig], None],
Check if tag exists and handle deletion if needed.
- Parameters:
config – Platform configuration
tag_url – URL to check if tag exists
delete_tag_func – Function to delete the tag
delete_release_func – Function to delete the release
- Returns:
True if we can proceed with creating the release
- Return type:
bool
- get_latest_tag(
- config: PlatformConfig,
- sha_extractor: Callable[[dict[str, Any]], str],
Get latest tag information.
- Parameters:
config – Platform configuration
sha_extractor – Function to extract SHA from a tag dict
- Returns:
(sha, version) or (None, None)
- Return type:
tuple
- paginate_api(
- url: str,
- headers: dict[str, str],
- params: dict[str, str],
- per_page: int = 100,
Paginate through all results from an API endpoint.
- Parameters:
url – API URL
headers – HTTP headers
params – Query parameters
per_page – Number of items per page
- Returns:
All results from all pages
- Return type:
list
- get_commits_since_tag(
- config: PlatformConfig,
- latest_tag_sha: str | None,
- date_extractor: Callable[[dict[str, Any]], str],
Get commits since last tag.
- Parameters:
config – Platform configuration
latest_tag_sha – SHA of the latest tag commit (or None)
date_extractor – Function to extract date from a commit dict
- Returns:
List of commits since the tag
- Return type:
list
- generate_changelog(
- commits: list[tuple[str, str]],
- config: PlatformConfig,
- latest_tag_version: str | None,
Generate changelog from commits using platform-specific URL patterns.
- Parameters:
commits – List of (sha, message) tuples
config – Platform configuration
latest_tag_version – Previous version for comparison link
- Returns:
Generated changelog text
- Return type:
str
- upload_files(
- config: PlatformConfig,
- upload_func: Callable[[str, str], None],
Upload files matching the specified suffixes.
- Parameters:
config – Platform configuration
upload_func – Function to upload a single file (takes file path and file name)
- log_success(
- config: PlatformConfig,
Log a success message after upload.
- Parameters:
config – Platform configuration
- delete_resource(
- config: PlatformConfig,
- url: str,
- resource_name: str,
Delete a resource (release or tag) by its URL if it exists.
- Parameters:
config – Platform configuration
url – Full URL of the resource
resource_name – Name for logging (e.g., “release”, “tag”)
- delete_resource_unconditional(
- config: PlatformConfig,
- url: str,
- resource_name: str,
Delete a resource without checking if it exists first.
- Parameters:
config – Platform configuration
url – Full URL of the resource
resource_name – Name for logging (e.g., “release”, “tag”)
- create_tag_on_branch(
- config: PlatformConfig,
- tags_url: str,
- create_tag_data: Callable[[str], dict[str, str]],
- branches: list[str] | None = None,
Create a tag, trying multiple branch names if needed.
- Parameters:
config – Platform configuration
tags_url – API URL for creating tags
create_tag_data – Function to create tag request data given a branch name
branches – List of branch names to try (default: [“main”, “master”])
- create_release(
- config: PlatformConfig,
- release_data: dict[str, Any],
Create a release.
- Parameters:
config – Platform configuration
release_data – Release request data
- Returns:
Response JSON from the API
- Return type:
dict