Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1 | = Prolog Facts for Gerrit Changes |
Sasa Zivkov | 40bc358 | 2012-07-24 14:51:44 +0200 | [diff] [blame] | 2 | |
| 3 | Prior to invoking the `submit_rule(X)` query for a change, Gerrit initializes |
| 4 | the Prolog engine with a set of facts (current data) about this change. |
| 5 | The following table provides an overview of the provided facts. |
| 6 | |
Michael Ochmann | 8129ece | 2016-07-08 11:25:25 +0200 | [diff] [blame] | 7 | [IMPORTANT] |
| 8 | All the terms listed below are defined in the `gerrit` package. To use any |
Sasa Zivkov | 40bc358 | 2012-07-24 14:51:44 +0200 | [diff] [blame] | 9 | of 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 Xiao | 0a19b2e | 2018-01-08 18:16:54 +0100 | [diff] [blame] | 36 | |`commit_committer/1` |`commit_committer(user(100000)).` |
Sasa Zivkov | 40bc358 | 2012-07-24 14:51:44 +0200 | [diff] [blame] | 37 | |Committer of the commit as `user(ID)` term. ID is the numeric account ID |
| 38 | |
Changcheng Xiao | 0a19b2e | 2018-01-08 18:16:54 +0100 | [diff] [blame] | 39 | |`commit_committer/3` |`commit_committer(user(100000), 'John Doe', 'john.doe@example.com').` |
Sasa Zivkov | 40bc358 | 2012-07-24 14:51:44 +0200 | [diff] [blame] | 40 | |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 Bader | 8e6c5a5 | 2020-03-11 07:49:50 +0100 | [diff] [blame] | 51 | |`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örk | 48a6ca1 | 2012-10-18 13:34:04 -0400 | [diff] [blame] | 54 | |`commit_stats/3` |`commit_stats(5,20,50).` |
| 55 | |Number of files modified, number of insertions and the number of deletions. |
| 56 | |
Gal Paikin | 1226ce6 | 2020-07-24 20:58:45 +0300 | [diff] [blame] | 57 | |`files/3` |`files(file('modules/jgit', 'A', 'SUBMODULE')).` |
| 58 | |
| 59 | |`files(file('a.txt', 'M', 'REGULAR')).' |
| 60 | |
Youssef Elghareeb | 374e697 | 2020-08-06 23:01:12 +0200 | [diff] [blame] | 61 | A list of tuples: The first argument is a file name of the current patchset. |
Gal Paikin | 1226ce6 | 2020-07-24 20:58:45 +0300 | [diff] [blame] | 62 | 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 Hiesel | 42db934 | 2017-09-12 11:45:06 +0200 | [diff] [blame] | 68 | |`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 Kempin | 59f91ab | 2016-01-28 15:11:23 +0100 | [diff] [blame] | 72 | |`uploader/1` |`uploader(user(1000000)).` |
| 73 | |Uploader as `user(ID)` term. ID is the numeric account ID |
Changcheng Xiao | a5d0178 | 2017-02-15 13:11:20 +0100 | [diff] [blame] | 74 | |
| 75 | |`unresolved_comments_count/1` |`unresolved_comments_count(0).` |
| 76 | |The number of unresolved comments as an integer atom |
Sasa Zivkov | 40bc358 | 2012-07-24 14:51:44 +0200 | [diff] [blame] | 77 | |============================================================================= |
| 78 | |
| 79 | In addition Gerrit provides a set of built-in helper predicates that can be used |
| 80 | when implementing the `submit_rule` predicate. The most common ones are listed in |
| 81 | the 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 Zieren | cfc7752 | 2021-03-08 16:42:47 +0000 | [diff] [blame] | 93 | |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 Zivkov | 40bc358 | 2012-07-24 14:51:44 +0200 | [diff] [blame] | 97 | |
| 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 Zieren | cfc7752 | 2021-03-08 16:42:47 +0000 | [diff] [blame] | 102 | |Like `commit_delta/3` plus the old path (via `O`) if applicable. |
Sasa Zivkov | 40bc358 | 2012-07-24 14:51:44 +0200 | [diff] [blame] | 103 | |
| 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 Ochmann | 8129ece | 2016-07-08 11:25:25 +0200 | [diff] [blame] | 115 | [NOTE] |
| 116 | For a complete list of built-in helpers read the `gerrit_common.pl` and |
Sasa Zivkov | 40bc358 | 2012-07-24 14:51:44 +0200 | [diff] [blame] | 117 | all Java classes whose name matches `PRED_*.java` from Gerrit's source code. |
| 118 | |
| 119 | GERRIT |
| 120 | ------ |
| 121 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 122 | |
| 123 | SEARCHBOX |
| 124 | --------- |