rbtools.utils.review_request¶
Utilities for matching review requests.
Functions
|
Ask Review Board for the review request ID for the tip revision. |
|
Find review requests that match the provided criteria. |
|
Returns the draft or current field value from a review request. |
|
Return pending review requests for a user. |
|
Returns the parsed revisions from the command line arguments. |
|
Try to guess the existing review request ID if it is available. |
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
ofunicode
, 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 theonly_fields
variable.If no review request is found,
None
will be returned instead.Changed in version 5.0:
Removed deprecated
repository_info
andrepository_name
arguments.Made all arguments keyword-only.
Changed in version 3.0: The
repository_info
andrepository_name
arguments were deprecated in favor of adding the newrepository_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 thetip
key.repository_id (
int
, optional) – The repository ID to use.
- Returns:
The matching review request, if found.
- Return type:
- 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:
Matching
commit_id
.This would be considered an exact match.
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.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
orrbtools.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 beNone
.fuzzy (
list
ofdict
) – 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:
- 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
, andguess_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
andguess_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
andrepository_name
arguments were deprecated in favor of adding the newrepository_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
ofstr
, 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:
- 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.