reviewbot.processing.review¶
Module Attributes
The logger for the module. |
Classes
|
Represents a file in the review. |
|
An object which orchestrates the creation of a review. |
|
The change status of a file. |
- logger = <Logger reviewbot.processing.review (WARNING)>[source]¶
The logger for the module.
New in version 3.0.
- class ReviewFileStatus(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
The change status of a file.
New in version 3.0.
- class File(review, api_filediff)[source]¶
Bases:
object
Represents a file in the review.
Information about the file can be retreived through this class, including retrieving the actual body of the original or patched file.
Allows comments to be made to the file in the review.
- COMMENT_MAX_LINES = 10[source]¶
The maximum number of lines allowed for a comment.
If a comment exceeds this count, it will be capped and a line range will be provided in the comment.
- __init__(review, api_filediff)[source]¶
Initialize the File.
- Parameters:
review (
Review
) – The review object.api_filediff (
rbtools.api.resource.Resource
) – The filediff resource.
- property patched_file_contents[source]¶
The patched contents of the file.
- Returns:
The contents of the patched file.
- Return type:
bytes
- property original_file_contents[source]¶
The original contents of the file.
- Returns:
The contents of the original file.
- Return type:
bytes
- get_patched_file_path()[source]¶
Fetch the patched file and return the filename of it.
Changed in version 3.0: Empty files no longer return
None
.- Returns:
The filename of a new temporary file containing the patched file contents. If the file is deleted, this will return
None
.- Return type:
str
- get_original_file_path()[source]¶
Fetch the original file and return the filename of it.
Changed in version 3.0: Empty files no longer return
None
.- Returns:
The filename of a new temporary file containing the original file contents. If the file is new, this will return
None
.- Return type:
str
- get_lines(first_line, num_lines=1, original=False)[source]¶
Return the lines from the file in the given range.
This can be used to extract lines from the original or modified file, as represented in the diff data. Some tool implementations can use this to provide more informative results (e.g., by providing suggested fixes to lines based on diffed/delta information coming from the program backing the tool).
- Parameters:
first_line (
int
) – The first line in the range.num_lines (
int
, optional) – The maximum number of lines to return.original (
bool
, optional) – Whether to return lines from the original (unmodified) file.
- Returns:
The list of lines, up to the maximum requested. This will be empty if the lines could not be found.
- Return type:
list
ofstr
- apply_patch(root_target_dir)[source]¶
Apply the patch for this file to the filesystem.
The file will be written relative to the current directory.
New in version 3.0.
- Parameters:
root_target_dir (
str
) – The root directory for the project. No files are allowed to be created, modified, deleted, or linked to outside of this path.- Raises:
reviewbot.errors.SuspiciousFilePath – The patch tried to work with a file outside of
root_target_dir
.
- comment(text, first_line, num_lines=1, start_column=None, error_code=None, issue=None, rich_text=False, original=False, text_extra=None, severity=None)[source]¶
Make a comment on the file.
Changed in version 3.0: Added
error_code
,severity
,start_column
, andtext_extra
arguments.- Parameters:
text (
str
) – The text of the comment.first_line (
int
) – The line number that the comment starts on. IfNone
, the comment is considered to be for the entire file.num_lines (
int
, optional) – The number of lines that the comment should span.start_column (
int
, optional) – The starting column within the code line where an error applied, as reported by a linter. If provided, this will be appended to the text.error_code (
str
, optional) – An error code for the error being reported. If provided, this will be appended to the text.issue (
bool
, optional) – Whether an issue should be opened.rich_text (
bool
, optional) – Whether the comment text should be formatted using Markdown.original (
bool
, optional) – If True, thefirst_line
argument corresponds to the line number in the original file, instead of the patched file.severity (
str
, optional) – A tool-specific, human-readable indication of the severity of this comment.text_extra (
list
oftuple
, optional) – Additional data to append to the text inKey: Value
form. Each item is an ordered tuple of(Key, Value
). These will be placed after the default items (“Column” and “Error code”).
- class Review(api_root, review_request_id, diff_revision, settings)[source]¶
Bases:
object
An object which orchestrates the creation of a review.
- __init__(api_root, review_request_id, diff_revision, settings)[source]¶
Initialize the review.
- Parameters:
api_root (
rbtools.api.resource.Resource
) – The API root.review_request_id (
int
) – The ID of the review request being reviewed (ID for use in the API, which is the “display_id” field).diff_revision (
int
) – The diff revision being reviewed.settings (
dict
) – The settings provided by the extension when triggering the task.
- general_comment(text, issue=None, rich_text=False)[source]¶
Make a general comment.
- Parameters:
text (
str
) – The text of the comment.issue (
bool
, optional) – Whether an issue should be opened.rich_text (
bool
, optional) – Whether the comment text should be formatted using Markdown.