Skip to content

fake-api-server.ci.surveillance.model.config.github_action

This module provides functionality to manage and retrieve GitHub Actions environment variables. It includes a dataclass GitHubActionEnvironmentVariable for deserialization and accessing relevant environment variables that control repository configuration and authentication in GitHub Actions workflows.

GitHubActionEnvironmentVariable(github_actions=False, repository=str(), repository_owner_name=str(), repository_name=str(), base_branch=str(), head_branch=str(), github_token=str()) dataclass

Bases: _BaseModel

Represents environment variables specific to a GitHub Action execution context.

This class is used to define and process the environment variables related to GitHub Actions. It includes attributes to store details about the repository, branches, and authentication token. The purpose of this class is to manage and deserialize the environment data provided by GitHub Actions into a usable data object.

ATTRIBUTE DESCRIPTION
github_actions

Indicates if the environment corresponds to a GitHub Action execution.

TYPE: bool

repository

The full repository name in the format 'owner/repo'.

TYPE: str

repository_owner_name

The owner name of the repository.

TYPE: str

repository_name

The name of the repository.

TYPE: str

base_branch

The name of the base branch of the repository.

TYPE: str

head_branch

The name of the head branch of the repository.

TYPE: str

github_token

The authentication token provided for GitHub Actions.

TYPE: str

get_github_action_env()

Gets the global GitHub action environment variable. This method ensures a singleton pattern for the GitHub action environment variable by reusing the previously deserialized value or deserializing the current operating system environment variables if it hasn't been initialized yet.

RETURNS DESCRIPTION
GitHubActionEnvironmentVariable

The GitHub action environment variable.

RAISES DESCRIPTION
GitHubActionEnvironmentVariableError

If deserialization encounters an issue while processing the operating system's environment variables.

Source code in fake_api_server_plugin/ci/surveillance/model/config/github_action.py
def get_github_action_env() -> GitHubActionEnvironmentVariable:
    """
    Gets the global GitHub action environment variable. This method ensures a
    singleton pattern for the GitHub action environment variable by reusing the
    previously deserialized value or deserializing the current operating system
    environment variables if it hasn't been initialized yet.

    :raises GitHubActionEnvironmentVariableError: If deserialization encounters an
        issue while processing the operating system's environment variables.
    :return: The GitHub action environment variable.
    :rtype: GitHubActionEnvironmentVariable
    """
    global _Global_Environment_Var
    if _Global_Environment_Var is None:
        _Global_Environment_Var = GitHubActionEnvironmentVariable.deserialize(os.environ)
    return _Global_Environment_Var