rbtools.hooks.common¶
Common functionality for working with repository hooks.
Functions
|
Closes the specified review request as submitted. |
|
Execute the specified command and return the stdout output. |
|
Returns an RBClient instance and the associated root resource. |
|
Returns the review request resource for the given ID. |
|
Returns the approval information for the given review request. |
|
Returns the review request ID referenced in the commit message. |
|
Sets up a log handler to format log messages. |
Exceptions
- exception rbtools.hooks.common.HookError[source]¶
Bases:
Exception- __firstlineno__ = 23¶
- __static_attributes__ = ()¶
- rbtools.hooks.common.close_review_request(server_url, username, password, review_request_id, description)[source]¶
Closes the specified review request as submitted.
- rbtools.hooks.common.execute(command: Sequence[str] | str, *, text: bool = False, strip: bool = True) bytes | str | None[source]¶
Execute the specified command and return the stdout output.
Changed in version 5.0: Added the
textandstriparguments.Deprecated since version 5.0: Deprecated in favor of
run_process().- Parameters:
text (
bool, optional) –If
True, this will return the output as a string, otherwise it will return bytes. This defaults toFalse.Added in version 5.0.
strip (
bool, optional) –Whether to strip leading and trailing whitespace from the output of the command. This defaults to
True.Added in version 5.0.
- Returns:
The stdout output of the command or
Noneif the command failed to execute.- Return type:
- rbtools.hooks.common.get_api(server_url, **kwargs)[source]¶
Returns an RBClient instance and the associated root resource.
Hooks should use this method to gain access to the API, instead of instantiating their own client.
- Parameters:
server_url (
unicode) – The server URL to retrieve.**kwargs (
dict) – Additional keyword arguments to pass to theRBClientconstructor. SeeSyncTransport.__init__()for arguments that are accepted.
- Returns:
This returns a 2-tuple of the
RBClientand<root resource> rbtools.api.resource.Resource.- Return type:
- rbtools.hooks.common.get_review_request(review_request_id, api_root)[source]¶
Returns the review request resource for the given ID.
- rbtools.hooks.common.get_review_request_approval(server_url, username, password, review_request_id)[source]¶
Returns the approval information for the given review request.
- rbtools.hooks.common.get_review_request_id(regex, commit_message)[source]¶
Returns the review request ID referenced in the commit message.
We assume there is at most one review request associated with each commit. If a matching review request cannot be found, we return 0.
- rbtools.hooks.common.initialize_logging(debug: bool = False) None[source]¶
Sets up a log handler to format log messages.
Warning, error, and critical messages will show the level name as a prefix, followed by the message. Debug logs can optionally be enabled as well.
Changed in version 4.1: Added the
debugargument.- Parameters:
debug (
bool, optional) –Whether to enable debug logging.
Added in version 4.1.