gerrit.changes package

Subpackages

Submodules

gerrit.changes.change module

class gerrit.changes.change.GerritChange(id: str, gerrit)[source]

Bases: GerritBase

abandon()[source]

Abandons a change. Abandoning a change also removes all users from the attention set. If the change cannot be abandoned because the change state doesn’t allow abandoning of the change, the response is “409 Conflict” and the error message is contained in the response body.

Returns:

add_to_attention_set(input_)[source]

Adds a single user to the attention set of a change. support this method since v3.3.0

A user can only be added if they are not in the attention set. If a user is added while already in the attention set, the request is silently ignored.

input_ = {
    "user": "John Doe",
    "reason": "reason"
}
change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.add_to_attention_set(input_)
Parameters:

input – the AttentionSetInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#attention-set-input

Returns:

check_submit_requirement(input_)[source]

Tests a submit requirement.

Parameters:

input – the SubmitRequirementInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#submit-requirement-input

Returns:

consistency_check()[source]

Performs consistency checks on the change, and returns a ChangeInfo entity with the problems field set to a list of ProblemInfo entities.

Returns:

create_empty_edit()[source]

Creates empty change edit

Returns:

create_merge_patch_set(input_)[source]

Update an existing change by using a MergePatchSetInput entity. Gerrit will create a merge commit based on the information of MergePatchSetInput and add a new patch set to the change corresponding to the new merge commit.

input_ = {
    "subject": "Merge master into stable",
    "merge": {
      "source": "refs/heads/master"
    }
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.update(input_)
Parameters:

input – the MergePatchSetInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#merge-patch-set-input

Returns:

delete()[source]

Deletes a change.

Returns:

delete_assignee()[source]

Deletes the assignee of a change.

Returns:

delete_topic()[source]

Deletes the topic of a change.

Returns:

delete_vote(account, label, input_=None)[source]

Deletes a single vote from a change. Note, that even when the last vote of a reviewer is removed the reviewer itself is still listed on the change. If another user removed a user’s vote, the user with the deleted vote will be added to the attention set.

input_ = {
    "notify": "NONE"
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
change.delete_vote('John', 'Code-Review', input_)
# or
change.delete_vote('John', 'Code-Review')
Parameters:
Returns:

fix(input_=None)[source]

Performs consistency checks on the change as with GET /check, and additionally fixes any problems that can be fixed automatically. The returned field values reflect any fixes. Some fixes have options controlling their behavior, which can be set in the FixInput entity body. Only the change owner, a project owner, or an administrator may fix changes.

input_ = {
    "delete_patch_set_if_commit_missing": "true",
    "expect_merged_as": "something"
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.fix()
# or
result = change.fix(input_)
Parameters:

input – the FixInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#fix-input

Returns:

get_assignee()[source]

Retrieves the account of the user assigned to a change.

Returns:

get_attention_set()[source]

Returns all users that are currently in the attention set. support this method since v3.3.0

Returns:

get_detail(options=None)[source]

retrieve a change with labels, detailed labels, detailed accounts, reviewer updates, and messages.

Parameters:

options – List of options to fetch additional data about a change

Returns:

get_edit()[source]

Retrieves a change edit details. As response an EditInfo entity is returned that describes the change edit, or 204 No Content when change edit doesn’t exist for this change.

Returns:

get_hashtags()[source]

Gets the hashtags associated with a change.

Returns:

get_include_in()[source]

Retrieves the branches and tags in which a change is included.

Returns:

get_meta_diff(old=None, meta=None)[source]

Retrieves the difference between two historical states of a change by specifying the and the parameters. old=SHA-1,meta=SHA-1. If the parameter is not provided, the parent of the SHA-1 is used. If the parameter is not provided, the current state of the change is used. If neither are provided, the difference between the current state of the change and its previous state is returned.

Parameters:
  • old

  • meta

Returns:

get_past_assignees()[source]

Returns a list of every user ever assigned to a change, in the order in which they were first assigned.

Returns:

get_pure_revert(commit)[source]

Check if the given change is a pure revert of the change it references in revertOf.

Parameters:

commit – commit id

Returns:

get_revision(revision_id='current')[source]

Get one revision by revision SHA or integer number.

Parameters:

revision_id – Optional ID. If not specified, the current revision will be retrieved. It supports SHA IDs and integer numbers from -X to +X, where X is the current (latest) revision. Zero means current revision. -N means the current revision number X minus N, so if the current revision is 50, and -1 is given, the revision 49 will be retrieved.

Returns:

get_topic()[source]

Retrieves the topic of a change.

Getter:

Retrieves the topic of a change.

Setter:

Sets the topic of a change.

Deleter:

Deletes the topic of a change.

Returns:

ignore()[source]

Marks a change as ignored. The change will not be shown in the incoming reviews’ dashboard, and email notifications will be suppressed. Ignoring a change does not cause the change’s “updated” timestamp to be modified, and the owner is not notified.

Returns:

index()[source]

Adds or updates the change in the secondary index.

Returns:

list_comments()[source]

Lists the published comments of all revisions of the change.

Returns:

list_drafts()[source]

Lists the draft comments of all revisions of the change that belong to the calling user.

Returns:

list_robot_comments()[source]

Lists the robot comments of all revisions of the change.

Returns:

list_submitted_together_changes()[source]

Computes list of all changes which are submitted when Submit is called for this change, including the current change itself.

list_votes(account)[source]

Lists the votes for a specific reviewer of the change.

Parameters:

account – account id or username

Returns:

mark_as_reviewed()[source]

Marks a change as reviewed.

Returns:

mark_as_unreviewed()[source]

Marks a change as unreviewed.

Returns:

mark_private(input_)[source]

Marks the change to be private. Only open changes can be marked private. Changes may only be marked private by the owner or site administrators.

input_ = {
    "message": "After this security fix has been released we can make it public now."
}
change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
change.mark_private(input_)
Parameters:

input – the PrivateInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#private-input

Returns:

property messages
move(input_)[source]

Move a change. If the change cannot be moved because the change state doesn’t allow moving the change, the response is ‘409 Conflict’ and the error message is contained in the response body.

input_ = {
    "destination_branch" : "release-branch"
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.move(input_)
Parameters:

input – the MoveInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#move-input

Returns:

rebase(input_)[source]

Rebase a change. If the change cannot be rebased, e.g. due to conflicts, the response is ‘409 Conflict’ and the error message is contained in the response body.

input_ = {
    "base" : "1234",
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.rebase(input_)
Parameters:

input – the RebaseInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#rebase-input

Returns:

remove_from_attention_set(id_, input_=None)[source]

Deletes a single user from the attention set of a change. support this method since v3.3.0

A user can only be removed from the attention set. if they are currently in the attention set. Otherwise, the request is silently ignored.

input_ = {
    "reason": "reason"
}
change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
change.remove_from_attention_set('kevin.shi', input_)
# or
change.remove_from_attention_set('kevin.shi')
Parameters:
Returns:

restore()[source]

Restores a change. If the change cannot be restored because the change state doesn’t allow restoring the change, the response is “409 Conflict” and the error message is contained in the response body.

Returns:

revert(input_=None)[source]

Reverts a change. The request body does not need to include a RevertInput entity if no review comment is added.

If the user doesn’t have revert permission on the change or upload permission on the destination branch, the response is ‘403 Forbidden’, and the error message is contained in the response body.

If the change cannot be reverted because the change state doesn’t allow reverting the change, the response is 409 Conflict and the error message is contained in the response body.

input_ = {
    "message" : "Message to be added as review comment to the change when reverting the
    change."
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.revert()
# or
result = change.revert(input_)
Parameters:

input – the RevertInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#revert-input

Returns:

revert_submission()[source]

Creates open revert changes for all of the changes of a certain submission.

If the user doesn’t have revert permission on the change or upload permission on the destination, the response is ‘403 Forbidden’, and the error message is contained in the response body.

If the change cannot be reverted because the change state doesn’t allow reverting the change the response is ‘409 Conflict’, and the error message is contained in the response body.

Returns:

property reviewers
set_assignee(input_)[source]

Sets the assignee of a change.

input_ = {
    "assignee": "jhon.doe"
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.set_assignee(input_)
Parameters:

input – the AssigneeInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#assignee-input

Returns:

set_commit_message(input_)[source]

Creates a new patch set with a new commit message.

input_ = {
    "message": "New Commit message \n\nChange-Id: I10394472cbd17dd12454f22b143a444\n"
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.set_commit_message(input_)
Parameters:

input – the CommitMessageInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#commit-message-input

Returns:

set_hashtags(input_)[source]

Adds and/or removes hashtags from a change.

input_ = {
    "add" : [
        "hashtag3"
    ],
    "remove" : [
        "hashtag2"
    ]
}
change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.set_hashtags(input_)
Parameters:

input – the HashtagsInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#hashtags-input

Returns:

set_ready_for_review(input_)[source]

Marks the change as ready for review (set WIP property to false). Changes may only be marked ready by the owner, project owners or site administrators. Marking a change ready for review also adds all of the reviewers of the change to the attention set.

input_ = {
    'message': 'Refactoring is done.'
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
change.set_ready_for_review(input_)
Parameters:

input – the WorkInProgressInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#work-in-progress-input

Returns:

set_topic(topic)[source]

Sets the topic of a change.

Parameters:

topic – The new topic

Returns:

set_work_in_progress(input_=None)[source]

Marks the change as not ready for review yet. Changes may only be marked not ready by the owner, project owners or site administrators. Marking a change work in progress also removes all users from the attention set.

The request body does not need to include a WorkInProgressInput entity if no review comment is added.

input_ = {
    "message": "Refactoring needs to be done before we can proceed here."
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.set_work_in_progress(input_)
# or
result = change.set_work_in_progress()
Parameters:

input – the WorkInProgressInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#work-in-progress-input

Returns:

submit(input_=None)[source]

Submits a change. Submitting a change also removes all users from the attention set.

If the change cannot be submitted because the submit rule doesn’t allow submitting the change, the response is 409 Conflict and the error message is contained in the response body.

input_ = {
    "on_behalf_of": 1001439
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
result = change.submit(input_)
Parameters:

input – the SubmitInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#submit-input

Returns:

unignore()[source]

Un-marks a change as ignored.

Returns:

unmark_private(input_=None)[source]

Marks the change to be non-private. Note users can only unmark own private changes. If the change was already not private, the response is ‘409 Conflict’.

input_ = {
    "message": "This is a security fix that must not be public."
}
change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
change.unmark_private(input_)
# or
change.unmark_private()
Parameters:

input – the PrivateInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#private-input

Returns:

gerrit.changes.changes module

class gerrit.changes.changes.GerritChanges(gerrit)[source]

Bases: object

create(input_)[source]

create a change

input_ = {
    "project": "myProject",
    "subject": "Let's support 100% Gerrit workflow direct in browser",
    "branch": "stable",
    "topic": "create-change-in-browser",
    "status": "NEW"
}
result = client.changes.create(input_)
Parameters:

input – the ChangeInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-input

Returns:

delete(id_)[source]

Deletes a change.

Parameters:

id – change id

Returns:

get(id_)[source]

Retrieves a change.

Parameters:

id – change id

Returns:

search(query: str, options=None, limit: int = 25, skip: int = 0)[source]

Queries changes visible to the caller.

query = "is:open+owner:self+is:mergeable"
result = client.changes.search(query=query, options=["LABELS"])
Parameters:
  • query – Query string, it can contain multiple search operators concatenated by ‘+’ character

  • options – List of options to fetch additional data about changes

  • limit – Int value that allows to limit the number of changes to be included in the output results

  • skip – Int value that allows to skip the given number of changes from the beginning of the list

Returns:

gerrit.changes.edit module

class gerrit.changes.edit.GerritChangeEdit(change: str, gerrit)[source]

Bases: object

change_commit_message(input_)[source]

Modify commit message.

input_ = {
    "message": "New commit message\n\n
    Change-Id: I10394472cbd17dd12454f229e4f6de00b143a444"
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
edit = change.get_edit()
edit.change_commit_message(input_)
Parameters:

input – the ChangeEditMessageInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-edit-message-input

Returns:

delete()[source]

Deletes change edit.

Returns:

delete_file(file)[source]

Deletes a file from a change edit.

Parameters:

file – Path to file to delete.

Returns:

get_change_file_content(file)[source]

Retrieves content of a file from a change edit. The content of the file is returned as text encoded inside base64.

Parameters:

file – the file path

Returns:

get_commit_message()[source]

Retrieves commit message from change edit. The commit message is returned as base64 encoded string.

Returns:

get_file_meta_data(file)[source]

Retrieves meta data of a file from a change edit.

Parameters:

file – the file path

Returns:

publish(input_)[source]

Promotes change edit to a regular patch set.

input_ = {
    "notify": "NONE"
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
edit = change.get_edit()
edit.publish(input_)
Parameters:

input – the PublishChangeEditInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#publish-change-edit-input

Returns:

put_change_file_content(file, file_content)[source]

Put content of a file to a change edit.

Parameters:
  • file – the file path

  • file_content – the content of the file need to change

Returns:

rebase()[source]

Rebase change edit on top of the latest patch set. When change was rebased on top of the latest patch set, response ‘204 No Content’ is returned. When change edit is already based on top of the latest patch set, the response ‘409 Conflict’ is returned.

Returns:

rename_file(old_path, new_path)[source]

rename file

Parameters:
  • old_path – Old path to file to rename.

  • new_path – New path to file to rename.

Returns:

restore_file_content(file)[source]

restores file content

Parameters:

file – Path to file to restore.

Returns:

gerrit.changes.messages module

class gerrit.changes.messages.GerritChangeMessage(id: str, change: str, gerrit)[source]

Bases: GerritBase

delete(input_=None)[source]

Deletes a change message. Note that only users with the Administrate Server global capability are permitted to delete a change message.

input_ = {
    "reason": "spam"
}
change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
message = change.messages.get("babf4c5dd53d7a11080696efa78830d0a07762e6")
result = message.delete(input_)
# or
result = message.delete()
Parameters:

input – the DeleteChangeMessageInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#delete-change-message-input

Returns:

class gerrit.changes.messages.GerritChangeMessages(change, gerrit)[source]

Bases: object

get(id_)[source]

Retrieves a change message including detailed account information.

Parameters:

id – change message id

Returns:

list()[source]

Lists all the messages of a change including detailed account information.

Returns:

gerrit.changes.reviewers module

class gerrit.changes.reviewers.GerritChangeReviewer(account: str, change: str, gerrit)[source]

Bases: GerritBase

delete(input_=None)[source]

Deletes a reviewer from a change. Deleting a reviewer also removes that user from the attention set.

input_ = {
    "notify": "NONE"
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
reviewer = change.reviewers.get('john.doe')
reviewer.delete(input_)
# or
reviewer.delete()
Parameters:

input – the DeleteReviewerInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#delete-reviewer-input

Returns:

delete_vote(label, input_=None)[source]

Deletes a single vote from a change. Note, that even when the last vote of a reviewer is removed the reviewer itself is still listed on the change.

input_ = {
    "notify": "NONE"
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
reviewer = change.reviewers.get('john.doe')
reviewer.delete_vote('Code-Review', input_)
# or
reviewer.delete_vote('Code-Review')
Parameters:
Returns:

list_votes()[source]

Lists the votes for a specific reviewer of the change.

Returns:

class gerrit.changes.reviewers.GerritChangeReviewers(change, gerrit)[source]

Bases: object

add(input_)[source]

Adds one user or all members of one group as reviewer to the change.

Users can be moved from reviewer to CC and vice versa. This means if a user is added as CC that is already a reviewer on the change, the reviewer state of that user is updated to CC. If a user that is already a CC on the change is added as reviewer, the reviewer state of that user is updated to reviewer.

Adding a new reviewer also adds that reviewer to the attention set, unless the change is work in progress. Also, moving a reviewer to CC removes that user from the attention set.

input_ = {
    "reviewer": "john.doe"
}

change = client.changes.get('Project~stable~I10394472cbd17dd12454f229e4f6de00b143a444')
new_reviewer = change.reviewers.add(input_)
Parameters:

input – the ReviewerInput entity, https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#reviewer-input

Returns:

get(account)[source]

Retrieves a reviewer of a change.

Parameters:

account – _account_id, name, username or email

Returns:

list()[source]

Lists the reviewers of a change.

Returns:

Module contents