Vadim Spivak | 1767cb9 | 2013-04-23 20:19:13 -0700 | [diff] [blame] | 1 | # Gerrit OWNERS Plugin |
| 2 | |
Claudio Pacchiega | 6098f61 | 2016-11-03 21:13:07 +0000 | [diff] [blame] | 3 | This plugin provides some Prolog predicates that can be used to add customized |
| 4 | validation checks based on the approval of ‘path owners’ of a particular folder |
| 5 | in the project. |
Vadim Spivak | 1767cb9 | 2013-04-23 20:19:13 -0700 | [diff] [blame] | 6 | |
Claudio Pacchiega | 6098f61 | 2016-11-03 21:13:07 +0000 | [diff] [blame] | 7 | That allows creating a single big project including multiple components and |
| 8 | users have different roles depending on the particular path where changes are |
| 9 | being proposed. A user can be “owner” in a specific directory, and thus |
| 10 | influencing the approvals of changes there, but cannot do the same in others |
| 11 | paths, so assuring a kind of dynamic subproject access rights. |
Vadim Spivak | 1767cb9 | 2013-04-23 20:19:13 -0700 | [diff] [blame] | 12 | |
Claudio Pacchiega | 6098f61 | 2016-11-03 21:13:07 +0000 | [diff] [blame] | 13 | ## How it works |
Vadim Spivak | 1767cb9 | 2013-04-23 20:19:13 -0700 | [diff] [blame] | 14 | |
Claudio Pacchiega | 6098f61 | 2016-11-03 21:13:07 +0000 | [diff] [blame] | 15 | There are currently two main prolog public verbs: |
Vadim Spivak | 1767cb9 | 2013-04-23 20:19:13 -0700 | [diff] [blame] | 16 | |
Claudio Pacchiega | 6098f61 | 2016-11-03 21:13:07 +0000 | [diff] [blame] | 17 | `add_owner_approval/3` (UserList, InList, OutList) |
| 18 | appends `label('Owner-Approval', need(_))` to InList building OutList if |
| 19 | UserList has no users contained in the defined owners of this path change. |
Vadim Spivak | 1767cb9 | 2013-04-23 20:19:13 -0700 | [diff] [blame] | 20 | |
Claudio Pacchiega | 6098f61 | 2016-11-03 21:13:07 +0000 | [diff] [blame] | 21 | In other words, the predicate just copies InList to OutList if at least one of |
| 22 | the elements in UserList is an owner. |
Vadim Spivak | 1767cb9 | 2013-04-23 20:19:13 -0700 | [diff] [blame] | 23 | |
Claudio Pacchiega | 6098f61 | 2016-11-03 21:13:07 +0000 | [diff] [blame] | 24 | `add_owner_approval/2` (InList, OutList) |
| 25 | appends `label('Owner-Approval', need(_))` to InList building OutList if |
| 26 | no owners has given a Code-Review +2 to this path change. |
Vadim Spivak | 1767cb9 | 2013-04-23 20:19:13 -0700 | [diff] [blame] | 27 | |
Claudio Pacchiega | 6098f61 | 2016-11-03 21:13:07 +0000 | [diff] [blame] | 28 | This predicate is similar to the first one but generates a UserList with an |
| 29 | hardcoded policy. |
Vadim Spivak | 1767cb9 | 2013-04-23 20:19:13 -0700 | [diff] [blame] | 30 | |
Claudio Pacchiega | 6098f61 | 2016-11-03 21:13:07 +0000 | [diff] [blame] | 31 | Since add_owner_approval/3 is not using hard coded policies, it can be suitable |
| 32 | for complex customizations. |
Vadim Spivak | 1767cb9 | 2013-04-23 20:19:13 -0700 | [diff] [blame] | 33 | |
Vadim Spivak | 604dc2c | 2013-04-29 01:27:20 -0700 | [diff] [blame] | 34 | ## Auto assigner |
| 35 | |
Claudio Pacchiega | 6098f61 | 2016-11-03 21:13:07 +0000 | [diff] [blame] | 36 | There is a second plugin, gerrit-owners-autoassign which depends on |
| 37 | gerrit-owners. It will automatically assign all of the owners to review a |
| 38 | change when it's created or updated. |
Luca Milanesio | 9ba5a06 | 2017-01-19 11:57:00 +0000 | [diff] [blame] | 39 | |
| 40 | ## How to build |
| 41 | |
David Ostrovsky | 31c55ab | 2017-12-16 09:45:33 +0100 | [diff] [blame] | 42 | This plugin is built with Bazel and two build modes are supported: |
| 43 | |
| 44 | * Standalone |
| 45 | * In Gerrit tree |
| 46 | |
| 47 | ### Build standalone |
| 48 | |
| 49 | To build the plugin, issue the following command: |
| 50 | |
| 51 | ``` |
| 52 | bazel build :all |
| 53 | ``` |
| 54 | |
| 55 | The output is created in |
| 56 | |
| 57 | ``` |
David Pursehouse | 0fd372a | 2019-10-16 12:56:54 +0900 | [diff] [blame] | 58 | bazel-bin/owners/owners.jar |
| 59 | bazel-bin/owners-autoassign/owners-autoassign.jar |
Antonio Barone | 0c61d38 | 2021-06-22 16:45:20 +0300 | [diff] [blame] | 60 | bazel-bin/owners-api/owners-api.jar |
David Ostrovsky | 31c55ab | 2017-12-16 09:45:33 +0100 | [diff] [blame] | 61 | |
| 62 | ``` |
| 63 | |
| 64 | To execute the tests run: |
| 65 | |
| 66 | ``` |
| 67 | bazel test //... |
| 68 | ``` |
| 69 | |
| 70 | This project can be imported into the Eclipse IDE: |
| 71 | |
| 72 | ``` |
| 73 | ./tools/eclipse/project.sh |
| 74 | ``` |
| 75 | |
| 76 | ## Build in Gerrit tree |
| 77 | |
| 78 | Create symbolic links of the owners and owners-autoassign folders and of the |
| 79 | external_plugin_deps.bzl file to the Gerrit source code /plugins directory. |
| 80 | |
| 81 | Create a symbolic link of the owners-common plugin to the Gerrit source code |
| 82 | directory. |
Luca Milanesio | 9ba5a06 | 2017-01-19 11:57:00 +0000 | [diff] [blame] | 83 | |
Luca Milanesio | 9ba5a06 | 2017-01-19 11:57:00 +0000 | [diff] [blame] | 84 | Then build the owners and owners-autoassign plugins with the usual Gerrit |
| 85 | plugin compile command. |
| 86 | |
| 87 | Example: |
| 88 | |
| 89 | ``` |
| 90 | $ git clone https://gerrit.googlesource.com/plugins/owners |
| 91 | $ git clone https://gerrit.googlesource.com/gerrit |
| 92 | $ cd gerrit/plugins |
David Pursehouse | 1f9e724 | 2018-06-16 20:10:20 +0900 | [diff] [blame] | 93 | $ ln -s ../../owners/owners . |
| 94 | $ ln -s ../../owners/owners-autoassign . |
Antonio Barone | 0c61d38 | 2021-06-22 16:45:20 +0300 | [diff] [blame] | 95 | $ ln -s ../../owners/owners-api . |
Luca Milanesio | ca10905 | 2017-05-13 22:45:18 +0100 | [diff] [blame] | 96 | $ ln -sf ../../owners/external_plugin_deps.bzl . |
Luca Milanesio | 9ba5a06 | 2017-01-19 11:57:00 +0000 | [diff] [blame] | 97 | $ cd .. |
David Pursehouse | 1f9e724 | 2018-06-16 20:10:20 +0900 | [diff] [blame] | 98 | $ ln -s ../owners/owners-common . |
Luca Milanesio | ca10905 | 2017-05-13 22:45:18 +0100 | [diff] [blame] | 99 | $ bazel build plugins/owners plugins/owners-autoassign |
Luca Milanesio | 9ba5a06 | 2017-01-19 11:57:00 +0000 | [diff] [blame] | 100 | ``` |
| 101 | |
| 102 | NOTE: the owners-common folder is producing shared artifacts for the two plugins |
| 103 | and does not need to be built separately being a direct dependency of the build |
| 104 | process. Its resulting .jar must not be installed in gerrit plugins directory. |
Luca Milanesio | 6d1a67e | 2017-01-19 09:23:52 +0000 | [diff] [blame] | 105 | |
David Ostrovsky | 31c55ab | 2017-12-16 09:45:33 +0100 | [diff] [blame] | 106 | The output is created in |
| 107 | |
| 108 | ``` |
David Pursehouse | 0fd372a | 2019-10-16 12:56:54 +0900 | [diff] [blame] | 109 | bazel-bin/plugins/owners/owners.jar |
| 110 | bazel-bin/plugins/owners-autoassign/owners-autoassign.jar |
David Ostrovsky | 31c55ab | 2017-12-16 09:45:33 +0100 | [diff] [blame] | 111 | ``` |
| 112 | |
| 113 | To execute the tests run: |
| 114 | |
| 115 | ``` |
| 116 | bazel test owners-common:test |
| 117 | ``` |
| 118 | |
| 119 | This project can be imported into the Eclipse IDE: |
| 120 | |
Jacek Centkowski | 8e16f25 | 2023-02-04 10:16:18 +0100 | [diff] [blame] | 121 | Add the plugin name to the `CUSTOM_PLUGINS` (and in case when you want to run |
| 122 | tests from the IDE to `CUSTOM_PLUGINS_TEST_DEPS`) in Gerrit core in |
David Ostrovsky | 31c55ab | 2017-12-16 09:45:33 +0100 | [diff] [blame] | 123 | `tools/bzl/plugins.bzl` file and run: |
| 124 | |
| 125 | ``` |
| 126 | ./tools/eclipse/project.py |
| 127 | ``` |
| 128 | |