• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. RBTools 5.x
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.0
    6. Version 1.0
    7. Version 0.7
    8. Version 0.6
    9. Version 0.5
    10. RBTools Python API
    11. Module and Class References
    12. rbtools.utils.review_request
  • Home
  • Installing RBTools
  • rbt Command
  • Configuration
  • Authenticating to Review Board
  • Repository Configuration
  • Per-User Configuration
  • Team Foundation Server Configuration
  • Commands
  • alias
  • api-get
  • attach
  • clear-cache
  • close
  • diff
  • install
  • land
  • list-repo-types
  • login
  • logout
  • patch
  • post
  • publish
  • review
  • setup-completion
  • setup-repo
  • stamp
  • status
  • status-update
  • RBTools Workflows
  • Using RBTools With Cliosoft SOS
  • Using RBTools with Git
  • Using RBTools with HCL VersionVault and IBM ClearCase
  • Using RBTools With Perforce
  • RBTools Python API
  • Overview of the Python API Client
  • Tutorial
  • Resource-Specific Functionality
  • Module and Class References
  • rbtools
  • rbtools.deprecation
  • rbtools.api
  • rbtools.api.cache
  • rbtools.api.capabilities
  • rbtools.api.client
  • rbtools.api.decode
  • rbtools.api.decorators
  • rbtools.api.errors
  • rbtools.api.factory
  • rbtools.api.request
  • rbtools.api.resource
  • rbtools.api.transport
  • rbtools.api.transport.sync
  • rbtools.api.utils
  • rbtools.clients
  • rbtools.clients.base
  • rbtools.clients.base.patch
  • rbtools.clients.base.registry
  • rbtools.clients.base.repository
  • rbtools.clients.base.scmclient
  • rbtools.clients.errors
  • rbtools.clients.bazaar
  • rbtools.clients.clearcase
  • rbtools.clients.cvs
  • rbtools.clients.git
  • rbtools.clients.mercurial
  • rbtools.clients.perforce
  • rbtools.clients.plastic
  • rbtools.clients.sos
  • rbtools.clients.svn
  • rbtools.clients.tfs
  • rbtools.config
  • rbtools.config.config
  • rbtools.config.loader
  • rbtools.diffs
  • rbtools.diffs.patches
  • rbtools.diffs.patcher
  • rbtools.diffs.tools
  • rbtools.diffs.tools.backends
  • rbtools.diffs.tools.backends.gnu
  • rbtools.diffs.tools.base
  • rbtools.diffs.tools.base.diff_file_result
  • rbtools.diffs.tools.base.diff_tool
  • rbtools.diffs.tools.errors
  • rbtools.diffs.tools.registry
  • rbtools.diffs.writers
  • rbtools.commands
  • rbtools.commands.main
  • rbtools.commands
  • rbtools.commands.base
  • rbtools.commands.base.commands
  • rbtools.commands.base.errors
  • rbtools.commands.base.options
  • rbtools.commands.base.output
  • rbtools.commands.alias
  • rbtools.commands.api_get
  • rbtools.commands.attach
  • rbtools.commands.clearcache
  • rbtools.commands.close
  • rbtools.commands.diff
  • rbtools.commands.info
  • rbtools.commands.install
  • rbtools.commands.land
  • rbtools.commands.list_repo_types
  • rbtools.commands.login
  • rbtools.commands.logout
  • rbtools.commands.patch
  • rbtools.commands.post
  • rbtools.commands.publish
  • rbtools.commands.review
  • rbtools.commands.setup_completion
  • rbtools.commands.setup_repo
  • rbtools.commands.stamp
  • rbtools.commands.status
  • rbtools.commands.status_update
  • rbtools.hooks
  • rbtools.hooks.common
  • rbtools.hooks.git
  • rbtools.testing
  • rbtools.testing.api
  • rbtools.testing.api.payloads
  • rbtools.testing.api.transport
  • rbtools.testing.commands
  • rbtools.testing.testcase
  • rbtools.testing.transport
  • rbtools.utils
  • rbtools.utils.aliases
  • rbtools.utils.browser
  • rbtools.utils.checks
  • rbtools.utils.commands
  • rbtools.utils.console
  • rbtools.utils.diffs
  • rbtools.utils.encoding
  • rbtools.utils.errors
  • rbtools.utils.filesystem
  • rbtools.utils.graphs
  • rbtools.utils.mimetypes
  • rbtools.utils.process
  • rbtools.utils.repository
  • rbtools.utils.review_request
  • rbtools.utils.source_tree
  • rbtools.utils.users
  • Glossary
  • General Index
  • Python Module Index
  • Release Notes
  • rbtools.utils.review_request¶

    Utilities for matching review requests.

    Functions

    find_review_request_by_change_id(*, ...[, ...])

    Ask Review Board for the review request ID for the tip revision.

    find_review_request_matches(review_requests)

    Find review requests that match the provided criteria.

    get_draft_or_current_value(field_name, ...)

    Returns the draft or current field value from a review request.

    get_pending_review_requests(api_root, username)

    Return pending review requests for a user.

    get_revisions(tool, cmd_args)

    Returns the parsed revisions from the command line arguments.

    guess_existing_review_request(*, api_root[, ...])

    Try to guess the existing review request ID if it is available.

    parse_review_request_url(url)

    Parse a review request URL and return its component parts.

    rbtools.utils.review_request.get_draft_or_current_value(field_name, review_request)[source]¶

    Returns the draft or current field value from a review request.

    If a draft exists for the supplied review request, return the draft’s field value for the supplied field name, otherwise return the review request’s field value for the supplied field name.

    rbtools.utils.review_request.get_revisions(tool, cmd_args)[source]¶

    Returns the parsed revisions from the command line arguments.

    These revisions are used for diff generation and commit message extraction. They will be cached for future calls.

    rbtools.utils.review_request.get_pending_review_requests(api_root, username, repository_id=None, additional_fields=None)[source]¶

    Return pending review requests for a user.

    Each review request will contain a pre-fetched list of fields:

    • absolute_url

    • bugs_closed

    • commit_id

    • description

    • draft

    • extra_data

    • id

    • public

    • status

    • summary

    • url

    If needed, additional fields can be requested by passing in additional_fields.

    This requires a valid existing login session.

    New in version 3.1.

    Parameters:
    • api_root (rbtools.api.resource.RootResource) – The root resource of the Review Board server.

    • username (unicode) –

      The username owning the review requests.

      The authenticated user will need to have access to this user’s pending review requests. For instance, it would need to be a superuser, a special user with the can_submit_as permission, or the user itself.

    • repository_id (int, optional) –

      The repository ID that all matching review requests must be posted against.

      If not provided, only review requests not backed by a repository will be matched.

    • additional_fields (list of unicode, optional) – Additional fields to fetch for the review request payload.

    rbtools.utils.review_request.find_review_request_by_change_id(*, api_client: RBClient, api_root: RootResource, revisions: SCMClientRevisionSpec, repository_id: Optional[int] = None) → Optional[ReviewRequestResource][source]¶

    Ask Review Board for the review request ID for the tip revision.

    Note that this function calls the Review Board API with the only_fields parameter, thus the returned review request will contain only the fields specified by the only_fields variable.

    If no review request is found, None will be returned instead.

    Changed in version 5.0:

    • Removed deprecated repository_info and repository_name arguments.

    • Made all arguments keyword-only.

    Changed in version 3.0: The repository_info and repository_name arguments were deprecated in favor of adding the new repository_id argument.

    Parameters:
    • api_client (rbtools.api.client.RBClient) – The API client.

    • api_root (rbtools.api.resource.RootResource) – The root resource of the Review Board server.

    • revisions (dict) – The parsed revision information, including the tip key.

    • repository_id (int, optional) – The repository ID to use.

    Returns:

    The matching review request, if found.

    Return type:

    rbtools.api.resource.ReviewRequestResource

    rbtools.utils.review_request.find_review_request_matches(review_requests, tool=None, revisions=None, commit_id=None, summary=None, description=None, max_review_requests=50)[source]¶

    Find review requests that match the provided criteria.

    This will iterate through a provided list of review request resources, comparing the contained information against the provided criteria in order to generate matches.

    There are two possible types of results: An exact match, or a list of fuzzy matches.

    If only one exact match is found, it will be in the results, and any fuzzy matches will be discarded.

    If more than one exact match is found, they’ll be converted to fuzzy matches, with higher precedence than any actual fuzzy matches.

    If an exact match is not found, a list of fuzzy matches will be provided, each with a score (a floating point number between 0.0 and 1.0) indicating how close it matched the criteria.

    The following criteria is checked for a match:

    1. Matching commit_id.

      This would be considered an exact match.

    2. Matching SCMClient-specific extra_data.

      A BaseSCMClient can provide its own matching logic, comparing state stored on a review request with information from the local clone/checkout. The result may be an exact match or a fuzzy match.

    3. Matching a summary/description, if provided.

      The provided summary/description will be compared against the review request. If the strings are both equal, then this will be an exact match. Otherwise, it’s a fuzzy match.

    New in version 3.1.

    Parameters:
    • review_requests (list or rbtools.api.resource.ListResource) –

      Either a list resource for review requests (in which case all pages will be searched for matches), or a list of rbtools.api.resource.ReviewRequestResource instances.

      Note

      It’s expected that these will all be backed by the same repository. Otherwise, commit ID matching will not be reliable. This is the responsibility of the caller.

    • tool (rbtools.clients.base.BaseSCMClient, optional) – An optional client tool used to perform tool-specific matches.

    • revisions (dict, optional) – The parsed revisions from the tool.

    • summary (unicode, optional) – An optional summary to match against.

    • description (unicode, optional) – An optional description to match against.

    • max_review_requests (int, optional) – The maximum number of review requests to check. This avoids iterating through too many pages of review requests on the server.

    Returns:

    A dictionary of results, containing:

    Keys:
    • exact (rbtools.api.resource.ReviewRequestResource) – An exact review request match. This may be None.

    • fuzzy (list of dict) – A list of fuzzy matches. Each contains:

      Keys:
      • review_request (rbtools.api.resource.ReviewRequestResource) – The review request match candidate.

      • score (float) – The match score (between 0.0 and 1.0), indicating the confidence of the match.

    Return type:

    dict

    rbtools.utils.review_request.guess_existing_review_request(*, api_root: RootResource, api_client: Optional[RBClient] = None, tool: BaseSCMClient, revisions: SCMClientRevisionSpec, is_fuzzy_match_func: Optional[Callable[[ReviewRequestResource], bool]] = None, no_commit_error: Optional[Callable[[], None]] = None, submit_as: str, additional_fields: Optional[list[str]] = None, repository_id: Optional[int] = None, commit_id: Optional[str] = None) → Optional[ReviewRequestResource][source]¶

    Try to guess the existing review request ID if it is available.

    The existing review request is guessed by comparing the existing summary and description to the current post’s summary and description, respectively. The current post’s summary and description are guessed if they are not provided.

    If the summary and description exactly match those of an existing review request, that request is immediately returned. Otherwise, the user is prompted to select from a list of potential matches, sorted by the highest ranked match first.

    Note that this function calls the ReviewBoard API with the only_fields parameter, thus the returned review request will contain only the fields specified by the only_fields variable.

    Changed in version 5.0:

    • Removed the deprecated repository_info, repository_name, guess_summary, and guess_description arguments.

    • Made submit_as required.

    • Deprecated the api_client argument.

    • Made all arguments keyword-only.

    Changed in version 3.1:

    • Added the commit_id argument.

    • The guess_summary and guess_description arguments are deprecated and will be removed in RBTools 4.0.

    • submit_as should now be provided, and will be required in RBTools 4.0.

    Changed in version 3.0: The repository_info and repository_name arguments were deprecated in favor of adding the new repository_id argument.

    Parameters:
    • api_root (rbtools.api.resource.RootResource) – The root resource of the Review Board server.

    • api_client (rbtools.api.client.RBClient) – The API client.

    • tool (rbtools.clients.base.BaseSCMClient) – The SCM client.

    • revisions (dict) – The parsed revisions object.

    • is_fuzzy_match_func (callable, optional) – A function which can check if a review request is a match for the data being posted.

    • no_commit_error (callable, optional) – A function to be called when there’s no local commit.

    • submit_as (str) –

      A username on the server which is used for posting review requests. If provided, review requests owned by this user will be matched.

      Changed in version 3.1: This will be required in RBTools 4.0.

    • additional_fields (list of str, optional) – A list of additional fields to include in the fetched review request resource.

    • repository_id (int, optional) – The ID of the repository to match.

    • commit_id (str, optional) –

      The ID of the commit to match.

      New in version 3.1.

    Returns:

    The resulting review request, if a match was made, or None if no review request could be matched.

    Return type:

    rbtools.api.resource.ReviewRequestResource

    Raises:
    • rbtools.utils.errors.MatchReviewRequestError – Error fetching the user session or review requests from the API. This will replace the ValueError exception for API issues in RBTools 4.0.

    • ValueError – Error fetching review requests from the API.

    rbtools.utils.review_request.parse_review_request_url(url)[source]¶

    Parse a review request URL and return its component parts.

    Parameters:

    url (unicode) – The URL to parse.

    Returns:

    A 3-tuple consisting of the server URL, the review request ID, and the diff revision.

    Return type:

    tuple

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • get_draft_or_current_value()
    • get_revisions()
    • get_pending_review_requests()
    • find_review_request_by_change_id()
    • find_review_request_matches()
    • guess_existing_review_request()
    • parse_review_request_url()