Hook dispatcher¶
This dispatcher handles the hook execution
Allowed tags in gerrit commit message:¶
Allowed tags in gerrit comment:¶
Rerun-Hooks¶
Run again the given hooks (patchset-created event hooks only):
Rerun-Hooks: hook1, hook2 ...
Rerun-Hooks: all
API¶
-
hook_dispatcher.
flatten
(array, elems)[source]¶ Function that appends to the array the options given by elems, to build a new command line array.
Parameters: - array – Command line array as [‘ls’, ‘-l’, ‘/tmp’]
- elems – Command line options as parsed by argparse, like [(‘author’, ‘dcaro’), (‘email’, ‘dcaroest@redhat.com’)]
Get the tags that were specified in gerrit message
Parameters: comment – Gerrit comment
Get the tags that were specified in the comit message
Parameters: commit – Commit to get the message from
-
hook_dispatcher.
get_hook_type
(opts)[source]¶ Guess the right hook type, gerrit sometimes resolves the real path
Parameters: opts – options given to the script, so it can guess the hook type
-
hook_dispatcher.
get_hooks
(path, hook_type)[source]¶ Get all the hooks that match the given type in the given path
Parameters: - path – Path to look the hooks in
- hook_type – Hook type to look for
Retrieves all the tags defined in the tag_def from text
Parameters: - tags_def – Definition of the tags as specified above
- text – text to look for tags (commit message, gerrit message…)
-
hook_dispatcher.
ignore
(ignored_hooks, current_hooks)[source]¶ Return the hooks list without the given hooks
:param ignored_hooks; csv lis tof the hooks to ignore :param current_hooks: array with the currently available hooks
-
hook_dispatcher.
parse_stdout
(stdout)[source]¶ The expected output format is:
code_review_value verified_value multi_line_msg
Where code_review_value and verified_value can be an empty line if it’s an abstention (no modifying the value any of the previous or next hooks in the chain set) If any of the lines is missing then it will assumed an abstention.
- 2 lines -> No message
- 1 line -> No message and no verified value
- 0 lines -> Not changing anything
And if any of the two first lines fails when converting to integer, it will assume that’s the start of the message and count the non-specified votes as abstentions
Examples: Skipping hooks comment - return codes: If rc == 3 the execution of the hook will not be added to the comments, on any other case, it will add a comment with the message provided
message starts here -1 message continues
^^^ this will be parsed as only message and two abstentions
-1 message starts here 0 message continues here
^^^ this will count as CR:-1, and the rest message
0 message
^^^ This will count as CR:0 (will level any positive review) and the rest message
-
hook_dispatcher.
print_title
(title, line_size=40, line_symbol='=')[source]¶ Printing the title with upper and lower lines with specified line size and symbol
Parameters: - title – title string
- line_size – line size (default: 40)
- line_symbol – line symbol (default: ‘=’)
-
hook_dispatcher.
rerun
(tag_val, to_rerun_hooks, args)[source]¶ Handles the Rerun-Hooks tag, reruns the given hooks, if all is given it will rerun all the hooks
Parameters: - tag_val – string passed to “Rerun-Hooks:” tag in comment
- to_rerun_hooks – array with the csv string passed to the tag
- args – object with all the passed arguments
:return list of hooks that will be rerun
-
hook_dispatcher.
run_chains
(path, hooks)[source]¶ Builds the chains from the given hooks and runs them.
If a hook on a chain returns with 1 or 2, it will break that chain and no futher hooks for that chain will be executed, continuing with the next chain
Parameters: - path – Path where the hooks are located
- hooks – hook names to run
-
hook_dispatcher.
run_hooks
(path, hooks)[source]¶ Run the given hooks form the given path
If any of the hooks returns with 1 or 2, the execution is stopped, if returns with 3, only a warning message is logged, and the execution will continue.
Parameters: - path – Path where the hooks are located
- hooks – hook names to run
Returns str: Log string with the combined result of all the executed hooks
-
hook_dispatcher.
run_only
(to_run_hooks, current_hooks)[source]¶ Handles the Run-Only tag, removes all the hooks not matching the given hooks
Parameters: - to_run_hooks – array with the csv string passed to the tag
- current_hooks – array with the current available hooks
-
hook_dispatcher.
send_summary
(change_id, project, results)[source]¶ Parse all the results and generate the summary review
Parameters: - change_id – string to identify the change with, usually the commit hash or the change-id,patchset pair
- project – project name (i.e ‘ovirt-engine’)
- results – Dictionary with the compiled results for all the chains
It will use the lowest values for the votes, skipping the ones that are None, and merge all the messages into one.
For example, if it has two chains, one with CR:0 and one with CR:1, the result will be CR:0.