rest_api.github_api

A module that holds any github-specific interactions. Most of this functionality is designed around GitHub’s REST API.

class cpp_linter.rest_api.github_api.GithubApiClient[source]

A class that describes the API used to interact with Github’s REST API.

api_url

The base domain for the REST API

repo

The owner/repository name.

event_name

The triggering event type’s name

sha

The HEAD commit’s SHA

debug_enabled

A flag that describes if debug logs are enabled.

pull_request

The pull request number for the event (if applicable).

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.

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.

verify_files_are_present(files: list[FileObj]) None[source]

Download the files if not present.

Parameters:
files: list[FileObj]

A list of files to check for existence.

Hint

This function assumes the working directory is the root of the invoking repository. If files are not found, then they are downloaded to the working directory. This is bad for files with the same name from different folders.

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.

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.

make_annotations(files: list[FileObj], style: str) None[source]

Use github log commands to make annotations from clang-format and clang-tidy output.

Parameters:
files: list[FileObj]

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

style: str

The chosen code style guidelines. The value ‘file’ is replaced with ‘custom style’.

update_comment(comment: str, comments_url: str, no_lgtm: bool, update_only: bool, is_lgtm: bool)[source]

Updates the comment for an existing comment or posts a new comment if update_only is False.

Parameters:
comment: str

The Comment to post.

comments_url: str

The URL used to fetch the comments.

no_lgtm: bool

A flag to control if a “Looks Good To Me” comment should be posted. If this is True, then an outdated bot comment will still be deleted.

update_only: bool

A flag that describes if the outdated bot comment should only be updated (instead of replaced).

is_lgtm: bool

A flag the describes if the comment being posted is essentially a “Looks Good To Me” comment.

remove_bot_comments(comments_url: str, delete: bool) str | None[source]

Traverse the list of comments made by a specific user and remove all.

Parameters:
comments_url: str

The URL used to fetch the comments.

delete: bool

A flag describing if first applicable bot comment should be deleted or not.

Returns:

If updating a comment, this will return the comment URL.

static create_review_comments(files: list[FileObj], tidy_tool: bool, summary_only: bool, review_comments: ReviewComments)[source]

Creates a batch of comments for a specific clang tool’s PR review.

Parameters:
files: list[FileObj]

The list of files to traverse.

tidy_tool: bool

A flag to indicate if the suggestions should originate from clang-tidy.

summary_only: bool

A flag to indicate if only the review summary is desired.

review_comments: ReviewComments

An object (passed by reference) that is used to store the results.