blob: e5b4140569c1c408a25bb42fb800243a29bcb1fe [file] [log] [blame]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08001= Prolog Facts for Gerrit Changes
Sasa Zivkov40bc3582012-07-24 14:51:44 +02002
3Prior to invoking the `submit_rule(X)` query for a change, Gerrit initializes
4the Prolog engine with a set of facts (current data) about this change.
5The following table provides an overview of the provided facts.
6
Michael Ochmann8129ece2016-07-08 11:25:25 +02007[IMPORTANT]
8All the terms listed below are defined in the `gerrit` package. To use any
Sasa Zivkov40bc3582012-07-24 14:51:44 +02009of them we must use a qualified name like `gerrit:change_branch(X)`.
10
11.Prolog facts about the current change
12[grid="cols"]
13[options="header"]
14|=============================================================================
15|Fact |Example |Description
16
17|`change_branch/1` |`change_branch('refs/heads/master').`
18 |Destination Branch for the change as string atom
19
20|`change_owner/1` |`change_owner(user(1000000)).`
21 |Owner of the change as `user(ID)` term. ID is the numeric account ID
22
23|`change_project/1` |`change_project('full/project/name').`
24 |Name of the project as string atom
25
26|`change_topic/1` |`change_topic('plugins').`
27 |Topic name as string atom
28
29|`commit_author/1` |`commit_author(user(100000)).`
30 |Author of the commit as `user(ID)` term. ID is the numeric account ID
31
32|`commit_author/3` |`commit_author(user(100000), 'John Doe', 'john.doe@example.com').`
33 |ID, full name and the email of the commit author. The full name and the
34 email are string atoms
35
Changcheng Xiao0a19b2e2018-01-08 18:16:54 +010036|`commit_committer/1` |`commit_committer(user(100000)).`
Sasa Zivkov40bc3582012-07-24 14:51:44 +020037 |Committer of the commit as `user(ID)` term. ID is the numeric account ID
38
Changcheng Xiao0a19b2e2018-01-08 18:16:54 +010039|`commit_committer/3` |`commit_committer(user(100000), 'John Doe', 'john.doe@example.com').`
Sasa Zivkov40bc3582012-07-24 14:51:44 +020040 |ID, full name and the email of the commit committer. The full name and the
41 email are string atoms
42
43.2+|`commit_label/2` |`commit_label(label('Code-Review', 2), user(1000000)).`
44 .2+|Set of votes on the last patch-set
45
46 |`commit_label(label('Verified', -1), user(1000001)).`
47
48|`commit_message/1` |`commit_message('Fix bug X').`
49 |Commit message as string atom
50
Lucas Bader8e6c5a52020-03-11 07:49:50 +010051|`commit_parent_count/1` |`commit_parent_count(1).`
52 |Number of parent commits of a commit. Can be used to detect merge commits
53
Johan Björk48a6ca12012-10-18 13:34:04 -040054|`commit_stats/3` |`commit_stats(5,20,50).`
55 |Number of files modified, number of insertions and the number of deletions.
56
Gal Paikin1226ce62020-07-24 20:58:45 +030057|`files/3` |`files(file('modules/jgit', 'A', 'SUBMODULE')).`
58
59 |`files(file('a.txt', 'M', 'REGULAR')).'
60
Youssef Elghareeb374e6972020-08-06 23:01:12 +020061 A list of tuples: The first argument is a file name of the current patchset.
Gal Paikin1226ce62020-07-24 20:58:45 +030062 The second argument is the modification type of this file, with the options being
63 'A' for 'added', 'M' for 'modified', 'D' for 'deleted', 'R' for 'renamed', 'C' for
64 'COPIED' and 'W' for 'rewrite'.
65 The third argument is the type of file, with the options being a submodule file
66 'SUBMODULE' and a non-submodule file being 'REGULAR'.
67
Patrick Hiesel42db9342017-09-12 11:45:06 +020068|`pure_revert/1` |`pure_revert(1).`
69 |link:rest-api-changes.html#get-pure-revert[Pure revert] as integer atom (1 if
70 the change is a pure revert, 0 otherwise)
71
Edwin Kempin59f91ab2016-01-28 15:11:23 +010072|`uploader/1` |`uploader(user(1000000)).`
73 |Uploader as `user(ID)` term. ID is the numeric account ID
Changcheng Xiaoa5d01782017-02-15 13:11:20 +010074
75|`unresolved_comments_count/1` |`unresolved_comments_count(0).`
76 |The number of unresolved comments as an integer atom
Sasa Zivkov40bc3582012-07-24 14:51:44 +020077|=============================================================================
78
79In addition Gerrit provides a set of built-in helper predicates that can be used
80when implementing the `submit_rule` predicate. The most common ones are listed in
81the following table.
82
83.Built-in Prolog helper predicates
84[grid="cols"]
85[options="header"]
86|=============================================================================
87|Predicate |Example usage |Description
88
89|`commit_delta/1` |`commit_delta('\\.java$').`
90 |True if any file name from the last patch set matches the given regex.
91
92|`commit_delta/3` |`commit_delta('\\.java$', T, P)`
Joerg Zierencfc77522021-03-08 16:42:47 +000093 |Returns the change type (via `T`) and path (via `P`), if the change type
94 is `rename`, it also returns the old path. If the change type is `rename`, it
95 returns a delete for old path and an add for new path. If the change type
96 is `copy`, an add is returned along with new path.
Sasa Zivkov40bc3582012-07-24 14:51:44 +020097
98 Possible values for the change type are the following symbols: `add`,
99 `modify`, `delete`, `rename`, `copy`
100
101|`commit_delta/4` |`commit_delta('\\.java$', T, P, O)`
Joerg Zierencfc77522021-03-08 16:42:47 +0000102 |Like `commit_delta/3` plus the old path (via `O`) if applicable.
Sasa Zivkov40bc3582012-07-24 14:51:44 +0200103
104|`commit_edits/2` |`commit_edits('/pom.xml$', 'dependency')`
105 |True if any of the files matched by the file name regex (first parameter)
106 have edited lines that match the regex in the second parameter. This
107 example will be true if there is a modification of a `pom.xml` file such
108 that an edited line contains or contained the string `'dependency'`.
109
110|`commit_message_matches/1` |`commit_message_matches('^Bug fix')`
111 |True if the commit message matches the given regex.
112
113|=============================================================================
114
Michael Ochmann8129ece2016-07-08 11:25:25 +0200115[NOTE]
116For a complete list of built-in helpers read the `gerrit_common.pl` and
Sasa Zivkov40bc3582012-07-24 14:51:44 +0200117all Java classes whose name matches `PRED_*.java` from Gerrit's source code.
118
119GERRIT
120------
121Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700122
123SEARCHBOX
124---------