blob: 9c1decb6d462d81d35e2c9984576f50698d166c9 [file] [log] [blame] [view]
Vadim Spivak1767cb92013-04-23 20:19:13 -07001# Gerrit OWNERS Plugin
2
Claudio Pacchiega6098f612016-11-03 21:13:07 +00003This plugin provides some Prolog predicates that can be used to add customized
4validation checks based on the approval of path owners of a particular folder
5in the project.
Vadim Spivak1767cb92013-04-23 20:19:13 -07006
Claudio Pacchiega6098f612016-11-03 21:13:07 +00007That allows creating a single big project including multiple components and
8users have different roles depending on the particular path where changes are
9being proposed. A user can be owner in a specific directory, and thus
10influencing the approvals of changes there, but cannot do the same in others
11paths, so assuring a kind of dynamic subproject access rights.
Vadim Spivak1767cb92013-04-23 20:19:13 -070012
Claudio Pacchiega6098f612016-11-03 21:13:07 +000013## How it works
Vadim Spivak1767cb92013-04-23 20:19:13 -070014
Claudio Pacchiega6098f612016-11-03 21:13:07 +000015There are currently two main prolog public verbs:
Vadim Spivak1767cb92013-04-23 20:19:13 -070016
Claudio Pacchiega6098f612016-11-03 21:13:07 +000017`add_owner_approval/3` (UserList, InList, OutList)
18appends `label('Owner-Approval', need(_))` to InList building OutList if
19UserList has no users contained in the defined owners of this path change.
Vadim Spivak1767cb92013-04-23 20:19:13 -070020
Claudio Pacchiega6098f612016-11-03 21:13:07 +000021In other words, the predicate just copies InList to OutList if at least one of
22the elements in UserList is an owner.
Vadim Spivak1767cb92013-04-23 20:19:13 -070023
Claudio Pacchiega6098f612016-11-03 21:13:07 +000024`add_owner_approval/2` (InList, OutList)
25appends `label('Owner-Approval', need(_))` to InList building OutList if
26no owners has given a Code-Review +2 to this path change.
Vadim Spivak1767cb92013-04-23 20:19:13 -070027
Claudio Pacchiega6098f612016-11-03 21:13:07 +000028This predicate is similar to the first one but generates a UserList with an
29hardcoded policy.
Vadim Spivak1767cb92013-04-23 20:19:13 -070030
Claudio Pacchiega6098f612016-11-03 21:13:07 +000031Since add_owner_approval/3 is not using hard coded policies, it can be suitable
32for complex customizations.
Vadim Spivak1767cb92013-04-23 20:19:13 -070033
Vadim Spivak604dc2c2013-04-29 01:27:20 -070034## Auto assigner
35
Claudio Pacchiega6098f612016-11-03 21:13:07 +000036There is a second plugin, gerrit-owners-autoassign which depends on
37gerrit-owners. It will automatically assign all of the owners to review a
38change when it's created or updated.
Luca Milanesio9ba5a062017-01-19 11:57:00 +000039
40## How to build
41
David Ostrovsky31c55ab2017-12-16 09:45:33 +010042This plugin is built with Bazel and two build modes are supported:
43
44 * Standalone
45 * In Gerrit tree
46
47### Build standalone
48
49To build the plugin, issue the following command:
50
51```
52 bazel build :all
53```
54
55The output is created in
56
57```
David Pursehouse0fd372a2019-10-16 12:56:54 +090058 bazel-bin/owners/owners.jar
59 bazel-bin/owners-autoassign/owners-autoassign.jar
Antonio Barone0c61d382021-06-22 16:45:20 +030060 bazel-bin/owners-api/owners-api.jar
David Ostrovsky31c55ab2017-12-16 09:45:33 +010061
62```
63
64To execute the tests run:
65
66```
67 bazel test //...
68```
69
70This project can be imported into the Eclipse IDE:
71
72```
73 ./tools/eclipse/project.sh
74```
75
76## Build in Gerrit tree
77
78Create symbolic links of the owners and owners-autoassign folders and of the
79external_plugin_deps.bzl file to the Gerrit source code /plugins directory.
80
81Create a symbolic link of the owners-common plugin to the Gerrit source code
82directory.
Luca Milanesio9ba5a062017-01-19 11:57:00 +000083
Luca Milanesio9ba5a062017-01-19 11:57:00 +000084Then build the owners and owners-autoassign plugins with the usual Gerrit
85plugin compile command.
86
87Example:
88
89```
90 $ git clone https://gerrit.googlesource.com/plugins/owners
91 $ git clone https://gerrit.googlesource.com/gerrit
92 $ cd gerrit/plugins
David Pursehouse1f9e7242018-06-16 20:10:20 +090093 $ ln -s ../../owners/owners .
94 $ ln -s ../../owners/owners-autoassign .
Antonio Barone0c61d382021-06-22 16:45:20 +030095 $ ln -s ../../owners/owners-api .
Luca Milanesioca109052017-05-13 22:45:18 +010096 $ ln -sf ../../owners/external_plugin_deps.bzl .
Luca Milanesio9ba5a062017-01-19 11:57:00 +000097 $ cd ..
David Pursehouse1f9e7242018-06-16 20:10:20 +090098 $ ln -s ../owners/owners-common .
Luca Milanesioca109052017-05-13 22:45:18 +010099 $ bazel build plugins/owners plugins/owners-autoassign
Luca Milanesio9ba5a062017-01-19 11:57:00 +0000100```
101
102NOTE: the owners-common folder is producing shared artifacts for the two plugins
103and does not need to be built separately being a direct dependency of the build
104process. Its resulting .jar must not be installed in gerrit plugins directory.
Luca Milanesio6d1a67e2017-01-19 09:23:52 +0000105
David Ostrovsky31c55ab2017-12-16 09:45:33 +0100106The output is created in
107
108```
David Pursehouse0fd372a2019-10-16 12:56:54 +0900109 bazel-bin/plugins/owners/owners.jar
110 bazel-bin/plugins/owners-autoassign/owners-autoassign.jar
David Ostrovsky31c55ab2017-12-16 09:45:33 +0100111```
112
113To execute the tests run:
114
115```
116 bazel test owners-common:test
117```
118
119This project can be imported into the Eclipse IDE:
120
Jacek Centkowski8e16f252023-02-04 10:16:18 +0100121Add the plugin name to the `CUSTOM_PLUGINS` (and in case when you want to run
122tests from the IDE to `CUSTOM_PLUGINS_TEST_DEPS`) in Gerrit core in
David Ostrovsky31c55ab2017-12-16 09:45:33 +0100123`tools/bzl/plugins.bzl` file and run:
124
125```
126 ./tools/eclipse/project.py
127```
128