Prolog Facts for Gerrit Changes

version v2.16.5

Prior to invoking the submit_rule(X) query for a change, Gerrit initializes
the Prolog engine with a set of facts (current data) about this change.
The following table provides an overview of the provided facts.

Important

All the terms listed below are defined in the gerrit package. To use any
of them we must use a qualified name like gerrit:change_branch(X).

ID, full name and the email of the commit committer. The full name and the
email are string atoms

commit_label/2

commit_label(label('Code-Review', 2), user(1000000)).

Set of votes on the last patch-set

commit_label(label('Verified', -1), user(1000001)).

commit_message/1

commit_message('Fix bug X').

Commit message as string atom

commit_stats/3

commit_stats(5,20,50).

Number of files modified, number of insertions and the number of deletions.

pure_revert/1

pure_revert(1).

Pure revert as integer atom (1 if
the change is a pure revert, 0 otherwise)

uploader/1

uploader(user(1000000)).

Uploader as user(ID) term. ID is the numeric account ID

unresolved_comments_count/1

unresolved_comments_count(0).

The number of unresolved comments as an integer atom

In addition Gerrit provides a set of built-in helper predicates that can be used
when implementing the submit_rule predicate. The most common ones are listed in
the following table.

Table 2. Built-in Prolog helper predicates

Predicate

Example usage

Description

commit_delta/1

commit_delta('\\.java$').

True if any file name from the last patch set matches the given regex.

commit_delta/3

commit_delta('\\.java$', T, P)

Returns the change type (via T) and path (via P), if the change type
is rename, it also returns the old path. If the change type is rename, it
returns a delete for old path and an add for new path. If the change type
is copy, an add is returned along with new path.

Possible values for the change type are the following symbols: add,
modify, delete, rename, copy

commit_delta/4

commit_delta('\\.java$', T, P, O)

Like commit_delta/3 plus the old path (via O) if applicable.

commit_edits/2

commit_edits('/pom.xml$', 'dependency')

True if any of the files matched by the file name regex (first parameter)
have edited lines that match the regex in the second parameter. This
example will be true if there is a modification of a pom.xml file such
that an edited line contains or contained the string 'dependency'.

commit_message_matches/1

commit_message_matches('^Bug fix')

True if the commit message matches the given regex.

Note

For a complete list of built-in helpers read the gerrit_common.pl and
all Java classes whose name matches PRED_*.java from Gerrit’s source code.