Modules Documentation

CLI

Main Package File, parses CLI arguments and calls functions.

badges_gitlab.cli.main() None

Main Function for calling arg parser and executing functions.

badges_gitlab.cli.parse_args(args) Namespace

Create arguments and parse them returning already parsed arguments.

Args:

args: arguments to parse

Returns:

argparse.Namespace: arparse object with parser arguments

Badges API

This module uses the Gitlab API Functions to create json files for badges.

badges_gitlab.badges_api.create_api_badges(directory_path: Any, private_token: str) None

Authenticates to API and call the json creation functions.

Main function in the module.

Args:

directory_path (Any): destination path to the json files. private_token (str): user token with api access for getting project data.

badges_gitlab.badges_api.general_data(project_ref: Any, directory_path: Any) None

Retrieves General Data from project.

Licences may not be found, therefore the Try function

Args:

project_ref (Any): project referece from gitlab directory_path (Any): path where json file will be written

badges_gitlab.badges_api.issues(project_ref: Any, directory_path: Any) None

Retrieve project issues data from the project dict.

Format : {‘statistics’: {‘counts’: {‘all’: 30, ‘closed’: 13, ‘opened’: 7}}}

Args:

project_ref (Any): project referece from gitlab directory_path (Any): path where json file will be written

badges_gitlab.badges_api.releases_commits(project_ref: Any, directory_path: Any) None

Retrieves Releases, Tags and Commits related data.

Args:

project_ref (Any): project referece from gitlab directory_path (Any): path where json file will be written

badges_gitlab.badges_api.validate_path(directory_path: Any) None

Validates destination path, if not found, creates it.

Args:

directory_path (Any): path to validate.

Badges JSON

This modules has functions to manipulate and generate standardized json files.

badges_gitlab.badges_json.json_badge(directory_path, filename: str, json_string: dict) None

Write to JSON file to disk to the specified directory.

Args:

directory_path (_type_): destination directory filename (str): destination json filename json_string (dict): dictionary to be converted to json

badges_gitlab.badges_json.print_json(label: str, message: str, color: str) dict

Returns a JSON (Dict) in the format used by shields.io to create badges.

Args:

label (str): label for the badge message (str): message in the badge color (str): color of the badge

Returns:

dict: final dictionary version with all fields.

badges_gitlab.badges_json.validate_json_path(directory_path: Any) None

Validate destination path if there are any json files.

Args:

directory_path (Any): destination path to check

Badges Static

This module handles generation of static badges.

It reads from pyproject.toml or from command line parameters

badges_gitlab.badges_static.convert_list_json_badge(badges_list: list) list

Converts the list of badges list to json format to be printed in the json file.

Args:

badges_list (list): _description_

Raises:

TypeError: if it is no a list.

Returns:

list: list of json dicts

badges_gitlab.badges_static.download_badges(directory: str, badges_urls: list)

Get the badges from websites and save it locally.

Now this was written specifically for shields.io but it must be studied to use other websites.

Args:

directory (str): destination directory badges_urls (list): list of badges url to be used

badges_gitlab.badges_static.extract_svg_title(xml_svg) str

Get the raw SVG (XML), convert to dict and retrieve the title.

Args:

xml_svg: svg in xml format

Returns:

str: returns the label as snake case

badges_gitlab.badges_static.print_static_badges(directory: str, badges_list: list)

Call functions in order to write a file with json badge information.

Args:

directory (str): destination for the file badges_list (list): list of badges (dict) to be used

badges_gitlab.badges_static.to_snake_case(value: str) str

Convert the label from a badge to snake case.

Args:

value (_type_): string to evaluate.

Returns:

str: string in snake in case

Badges SVG

Creates standardized badges files using anybadge package.

This function creates the badge svg file from json file with the shields.io (https://shields.io/endpoint) json format badge format = {“schemaVersion”:1,”label”:”hello”,”message”:”sweet world”,”color”:”orange”}

badges_gitlab.badges_svg.print_badges(directory_path: Any) None

Print badges from json files.

Iterates within the directory finding json files and then use anybadge pkg to generate them.

Args:

directory_path (Any): _description_

badges_gitlab.badges_svg.replace_space(string: str) str

Replaces any spaces to make it easier to use later as url in badges linking.

Args:

string (str): string to evaluate

Returns:

str: string without space

badges_gitlab.badges_svg.validate_json_path(directory_path: Any) bool

Check if there is any json files or the directory is valid.

Args:

directory_path (Any): destination path to evaluate.

Returns:

bool: validation result

Badges Test

Generate Tests Badges related by parsing JUnit XML files.

badges_gitlab.badges_test.create_badges_test(json_directory, file_path: str) str

Parses a JUnit XML file to extract general information about the unit tests.

Args:

json_directory: file where the json file will be saved file_path (str): junit xml file path

Returns:

str: string with the operation result

badges_gitlab.badges_test.create_test_json_badges(json_directory, test_results: list) str

Create badges from a test results list.

This function returns parses a list with the test summary to json format. The list order must be: total tests, total failures, total errors, total_skipped, total_time

Args:

json_directory: directory where json will be saved. test_results (list): list of the test results

Returns:

str: string with the result of the operation

badges_gitlab.badges_test.tests_statistics(stats_tests_dict: dict, testsuite) dict

Returns the Test Statistics Dictionary with added values from the testsuite.

Args:

stats_tests_dict (dict): dictionary with listed tests testsuite ([junitparser.junitparser.TestSuite]): a testsuite xml node needed for filling the stats tests dicitionary

Returns:

dict: returns the stats_tests_dict with the new values.

Read pyproject.toml

Read pyproject.toml and import the parameters to be used in the function.

badges_gitlab.read_pyproject.load_pyproject(file_path: str) dict

Load the tool.badges_gitlab section from the toml file.

Most of the cases it is pyproject.toml because it is hardcoded into main function

Args:

file_path (str): path for the pyproject.toml

Returns:

dict: dictionary with the configuration

badges_gitlab.read_pyproject.pyproject_config(file_path: str) dict

Load pyproject.toml and return the content as dict.

Args:

file_path (str): file path for the pyproject

Returns:

dict: dictionary with the configuration for the badges_gitlab tool

badges_gitlab.read_pyproject.pyproject_exists(file_path: str) bool

Verify if the file exists, used internally.

Args:

file_path (str): file path for the pyproject file

Returns:

bool: true or false for the operation.