Jump to >

reviewbot.processing.review

Classes

File(review, api_filediff)

Represents a file in the review.

Review(api_root, review_request_id, ...)

An object which orchestrates the creation of a review.

ReviewFileStatus(value)

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)[source]

Bases: enum.Enum

The change status of a file.

New in version 3.0.

CREATED = 'created'[source]
DELETED = 'deleted'[source]
MODIFIED = 'modified'[source]
MOVED = 'moved'[source]
COPIED = 'copied'[source]
classmethod for_filediff(filediff)[source]

Return a status for a FileDiff.

Parameters

filediff (rbtools.api.resource.Resource) – The filediff resource.

Returns

The resulting status.

Return type

ReviewFileStatus

Raises

ValueError – The status for the FileDiff is unknown/unsupported.

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.

__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

unicode

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

unicode

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 of unicode

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 (unicode) – 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, and text_extra arguments.

Parameters
  • text (unicode) – The text of the comment.

  • first_line (int) – The line number that the comment starts on. If None, 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 (unicode, 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, the first_line argument corresponds to the line number in the original file, instead of the patched file.

  • severity (unicode, optional) – A tool-specific, human-readable indication of the severity of this comment.

  • text_extra (list of tuple, optional) – Additional data to append to the text in Key: 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.

body_top = ''[source]

Additional text to show above the comments in the review.

body_bottom = ''[source]

Additional text to show below the comments in the 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 (unicode) – 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.

publish()[source]

Upload the review to Review Board.

property has_comments[source]

Whether the review has comments.

property patch_contents[source]

The contents of the patch.

Returns

The contents of the patch associated with the review request and diff revision.

Return type

unicode

get_patch_file_path()[source]

Fetch the patch and return the filename of it.

Returns

The filename of a new temporary file containing the patch contents. If the patch is empty, return None.

Return type

unicode