| 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 | |
| 7 | IMPORTANT: All the terms listed below are defined in the `gerrit` package. To use any |
| 8 | of them we must use a qualified name like `gerrit:change_branch(X)`. |
| 9 | |
| 10 | .Prolog facts about the current change |
| 11 | [grid="cols"] |
| 12 | [options="header"] |
| 13 | |============================================================================= |
| 14 | |Fact |Example |Description |
| 15 | |
| 16 | |`change_branch/1` |`change_branch('refs/heads/master').` |
| 17 | |Destination Branch for the change as string atom |
| 18 | |
| 19 | |`change_owner/1` |`change_owner(user(1000000)).` |
| 20 | |Owner of the change as `user(ID)` term. ID is the numeric account ID |
| 21 | |
| 22 | |`change_project/1` |`change_project('full/project/name').` |
| 23 | |Name of the project as string atom |
| 24 | |
| 25 | |`change_topic/1` |`change_topic('plugins').` |
| 26 | |Topic name as string atom |
| 27 | |
| 28 | |`commit_author/1` |`commit_author(user(100000)).` |
| 29 | |Author of the commit as `user(ID)` term. ID is the numeric account ID |
| 30 | |
| 31 | |`commit_author/3` |`commit_author(user(100000), 'John Doe', 'john.doe@example.com').` |
| 32 | |ID, full name and the email of the commit author. The full name and the |
| 33 | email are string atoms |
| 34 | |
| 35 | |`commit_committer/1` |`commit_committer()` |
| 36 | |Committer of the commit as `user(ID)` term. ID is the numeric account ID |
| 37 | |
| 38 | |`commit_committer/3` |`commit_committer()` |
| 39 | |ID, full name and the email of the commit committer. The full name and the |
| 40 | email are string atoms |
| 41 | |
| 42 | .2+|`commit_label/2` |`commit_label(label('Code-Review', 2), user(1000000)).` |
| 43 | .2+|Set of votes on the last patch-set |
| 44 | |
| 45 | |`commit_label(label('Verified', -1), user(1000001)).` |
| 46 | |
| 47 | |`commit_message/1` |`commit_message('Fix bug X').` |
| 48 | |Commit message as string atom |
| 49 | |
| Johan Björk | 48a6ca1 | 2012-10-18 13:34:04 -0400 | [diff] [blame] | 50 | |`commit_stats/3` |`commit_stats(5,20,50).` |
| 51 | |Number of files modified, number of insertions and the number of deletions. |
| 52 | |
| Sasa Zivkov | 40bc358 | 2012-07-24 14:51:44 +0200 | [diff] [blame] | 53 | .4+|`current_user/1` |`current_user(user(1000000)).` |
| 54 | .4+|Current user as one of the four given possibilities |
| 55 | |
| 56 | |`current_user(user(anonymous)).` |
| 57 | |`current_user(user(peer_daemon)).` |
| 58 | |`current_user(user(replication)).` |
| 59 | |============================================================================= |
| 60 | |
| 61 | In addition Gerrit provides a set of built-in helper predicates that can be used |
| 62 | when implementing the `submit_rule` predicate. The most common ones are listed in |
| 63 | the following table. |
| 64 | |
| 65 | .Built-in Prolog helper predicates |
| 66 | [grid="cols"] |
| 67 | [options="header"] |
| 68 | |============================================================================= |
| 69 | |Predicate |Example usage |Description |
| 70 | |
| 71 | |`commit_delta/1` |`commit_delta('\\.java$').` |
| 72 | |True if any file name from the last patch set matches the given regex. |
| 73 | |
| 74 | |`commit_delta/3` |`commit_delta('\\.java$', T, P)` |
| 75 | |Returns the change type (via `T`) and path (via `P`), if the change type |
| 76 | is `rename`, it also returns the old path. If the change type is `rename`, it |
| 77 | returns a delete for old path and an add for new path. If the change type |
| 78 | is `copy`, an add is returned along with new path. |
| 79 | |
| 80 | Possible values for the change type are the following symbols: `add`, |
| 81 | `modify`, `delete`, `rename`, `copy` |
| 82 | |
| 83 | |`commit_delta/4` |`commit_delta('\\.java$', T, P, O)` |
| 84 | |Like `commit_delta/3` plus the old path (via `O`) if applicable. |
| 85 | |
| 86 | |`commit_edits/2` |`commit_edits('/pom.xml$', 'dependency')` |
| 87 | |True if any of the files matched by the file name regex (first parameter) |
| 88 | have edited lines that match the regex in the second parameter. This |
| 89 | example will be true if there is a modification of a `pom.xml` file such |
| 90 | that an edited line contains or contained the string `'dependency'`. |
| 91 | |
| 92 | |`commit_message_matches/1` |`commit_message_matches('^Bug fix')` |
| 93 | |True if the commit message matches the given regex. |
| 94 | |
| 95 | |============================================================================= |
| 96 | |
| 97 | NOTE: for a complete list of built-in helpers read the `gerrit_common.pl` and |
| 98 | all Java classes whose name matches `PRED_*.java` from Gerrit's source code. |
| 99 | |
| 100 | GERRIT |
| 101 | ------ |
| 102 | Part of link:index.html[Gerrit Code Review] |
| Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 103 | |
| 104 | SEARCHBOX |
| 105 | --------- |