rest_api

This base module holds abstractions common to using REST API. See other modules in rest_api subpackage for detailed derivatives.

class cpp_linter.rest_api.RateLimitHeaders(reset: str, remaining: str, retry: str)[source]

A collection of HTTP response header keys that describe a REST API’s rate limits. Each parameter corresponds to a instance attribute (see below).

reset : str

The header key of the rate limit’s reset time.

remaining : str

The header key of the rate limit’s remaining attempts.

retry : str

The header key of the rate limit’s “backoff” time interval.

class cpp_linter.rest_api.RestApiClient(rate_limit_headers: RateLimitHeaders)[source]

A class that describes the API used to interact with a git server’s REST API.

Parameters:
rate_limit_headers: RateLimitHeaders

See RateLimitHeaders class.

api_request(url: str, method: str | None = None, data: str | None = None, headers: dict[str, Any] | None = None, strict: bool = True) Response[source]

A helper function to streamline handling of HTTP requests’ responses.

Parameters:
url: str

The HTTP request URL.

method: str | None = None

The HTTP request method. The default value None means “GET” if data is None else “POST”

data: str | None = None

The HTTP request payload data.

headers: dict[str, Any] | None = None

The HTTP request headers to use. This can be used to override the default headers used.

strict: bool = True

If this is set True, then an HTTPError will be raised when the HTTP request responds with a status code greater than or equal to 400.

Returns:

The HTTP request’s response object.

set_exit_code(checks_failed: int, format_checks_failed: int | None = None, tidy_checks_failed: int | None = None)[source]

Set the action’s output values and shows them in the log output.

Parameters:
checks_failed: int

A int describing the total number of checks that failed.

format_checks_failed: int | None = None

A int describing the number of checks that failed only for clang-format.

tidy_checks_failed: int | None = None

A int describing the number of checks that failed only for clang-tidy.

Returns:

The checks_failed parameter was not passed.

make_headers(use_diff: bool = False) dict[str, str][source]

Create a dict for use in REST API headers.

Parameters:
use_diff: bool = False

A flag to indicate that the returned format should be in diff syntax.

Returns:

A dict to be used as headers in requests API calls.

get_list_of_changed_files(file_filter: FileFilter, lines_changed_only: int) list[FileObj][source]

Fetch a list of the event’s changed files.

Parameters:
file_filter: FileFilter

A FileFilter obj to filter files.

lines_changed_only: int

A value that dictates what file changes to focus on.

static make_comment(files: list[FileObj], format_checks_failed: int, tidy_checks_failed: int, clang_versions: ClangVersions, len_limit: int | None = None) str[source]

Make an MarkDown comment from the given advice. Also returns a count of checks failed for each tool (clang-format and clang-tidy)

Parameters:
files: list[FileObj]

A list of objects, each describing a file’s information.

format_checks_failed: int

The amount of clang-format checks that have failed.

tidy_checks_failed: int

The amount of clang-tidy checks that have failed.

clang_versions: ClangVersions

The versions of the clang tools used.

len_limit: int | None = None

The length limit of the comment generated.

Returns:

The markdown comment as a str

post_feedback(files: list[FileObj], args: Args, clang_versions: ClangVersions)[source]

Post action’s results using REST API.

Parameters:
files: list[FileObj]

A list of objects, each describing a file’s information.

args: Args

A namespace of arguments parsed from the CLI.

clang_versions: ClangVersions

The version of the clang tools used.

static has_more_pages(response: Response) str | None[source]

A helper function to parse a HTTP request’s response headers to determine if the previous REST API call is paginated.

Parameters:
response: Response

A HTTP request’s response.

Returns:

The URL of the next page if any, otherwise None.