Gerrit
Functions and classes to manipulate Gerrit changes and subscribe to events.
Configuration files
<home>/.ave/config/gerrit.json: A dictionary with site specific
config details. Example:
{
"host": "review.sonyericsson.net",
"port": 29418,
"user": "john.doe"
}
<home>/.ssh: SSH configuration files, where <home> is read
from /etc/ave/user. Used to implement password-free login.
The value of <home> is read from /etc/ave/user.
ave.gerrit.review
-
ave.gerrit.review.quote_message(message)
Escape any " and \ characters in message. Unescaped strings
interfere with SSH command line parameter handling (Gerrit API’s are only
accessible over SSH). Also put quotes around the contents in message
before returning the modified string.
Parameters: | message – A free form, human readable message. |
Returns: | The quoted version of message. |
-
ave.gerrit.review.indent_message(message, indent=1)
Split message into lines and add indent whitespace characters at the
head of each line. This will cause Gerrit to render the paragraph in code
listing style.
Parameters: |
- message – A free form, human readable message.
- indent – The number of whitespace characters to add at the start of each
line of message.
|
Returns: | The indented version of message.
|
-
ave.gerrit.review.set_labels(project, change, patchset, labels, message=None)
Set scores on one or more labels for a change in Gerrit.
Parameters: |
- project – A string holding the project identity. E.g.
"ave/gerrit".
- change – A character string holding the change number. I.e.
the "456785" part of the following git refspec:
"refs/changes/85/456785/2".
- patchset – A string holding the patchset number. I.e. the final "2"
part of the following git refspec: "refs/changes/85/456785/2".
- labels – A dictionary representing the labels to be scored, in the
form {"label-name": value } where "label-name" is a string
and value is an integer.
|
Raises: |
- Exception – If validation of parameters failed.
- RunError – If communication with Gerrit failed.
|
-
ave.gerrit.review.set_label(project, change, patchset, label, score, message=None)
Set the score on a label for a change in Gerrit.
Parameters: |
- project – A string holding the project identity. E.g.
"ave/gerrit".
- change – A character string holding the change number. I.e.
the "456785" part of the following git refspec:
"refs/changes/85/456785/2".
- patchset – A string holding the patchset number. I.e. the final "2"
part of the following git refspec: "refs/changes/85/456785/2".
- label – A string representing the label to be scored.
- score – An integer in the range expected by Gerrit for label.
|
Raises: |
- Exception – If validation of parameters failed.
- RunError – If communication with Gerrit failed.
|
-
ave.gerrit.review.set_verified(project, change, patchset, value, message=None)
Set the verified status for a change in Gerrit.
Parameters: |
|
Raises: |
- Exception – If validation of parameters failed.
- RunError – If communication with Gerrit failed.
|
-
ave.gerrit.review.set_code_review(project, change, patchset, value, message=None)
Set the code review status for a change in Gerrit.
Parameters: |
|
Raises: |
- Exception – If validation of parameters failed.
- RunError – If communication with Gerrit failed.
|
-
ave.gerrit.review.set_qualified(project, change, patchset, value, message=None)
Set the qualified status for a change in Gerrit.
Parameters: |
|
Raises: |
- Exception – If validation of parameters failed.
- RunError – If communication with Gerrit failed.
|
Make a comment in a Gerrit project.
Parameters: |
- project – A string holding the project identity. E.g.
"ave/gerrit".
- change – A character string holding the change number. I.e.
the "456785" part of the following git refspec:
"refs/changes/85/456785/2".
- patchset – A string holding the patchset number. I.e. the final "2"
part of the following git refspec: "refs/changes/85/456785/2".
- message –
A free form text message. Gerrit comment formatting rules
apply.
Use ave.gerrit.review.quote_message() before set_comment() to
secure that the comment does not contain unescaped " characters.
Use ave.gerrit.review.indent_message() before set_comment() to
make sure Gerrit formats the message in fixed width style. E.g. as code
listing.
|
Raises: |
- Exception – If validation of parameters failed.
- RunError – If communication with Gerrit failed.
|
ave.gerrit.config
-
ave.gerrit.config.load(home)
Load the configuration file that contains Gerrit access details.
Parameters: | home – Path to a directory that contains the .ave/config/gerrit.json
file. |
Returns: | A JSON compatible dictionary. |
Raises Exception: |
| If there is a problem with loading or parsing the file. |
-
ave.gerrit.config.validate(config)
Validate the contents of a configuration dictionary. E.g. the return value
from ave.gerrit.config.load().
Parameters: | config – A dictionary that is expected to contain host, port and
user fields. |
Raises Exception: |
| If the configuration does not validate. |
ave.gerrit.events
-
class ave.gerrit.events.GerritEventStream(host=None, port=0, user=None, pipe=None, mailbox=None, home=None)
This class implements a separate process that listens to Gerrit events and
reposts them on an ave.network.pipe.Pipe or an ave.network.Control mailbox.
Parameters: |
|
Raises Exception: |
| If validation of parameters or the gerrit.json
configuration file fails.
|