blob: 16bbc46936d23b69045e2436d4d69867bd699015 [file] [log] [blame] [view]
David Pursehouse64e84452018-05-16 05:17:15 +00001# Supported Hooks
David Pursehouseac06f402016-06-21 10:20:49 +09002
David Pursehouse64e84452018-05-16 05:17:15 +00003[TOC]
David Pursehouseac06f402016-06-21 10:20:49 +09004
David Pursehouse64e84452018-05-16 05:17:15 +00005## Synchronous Hooks
JT Olds60adf572017-03-02 14:38:28 +09006
David Pursehouse64e84452018-05-16 05:17:15 +00007These hooks are invoked synchronously so it is recommended that they not block.
8
9A default timeout on the hook is set to 30 seconds to avoid "runaway" hooks using
10up server threads. The timeout can be changed by setting [`hooks.syncHookTimeout`][1].
11
12### ref-update
David Pursehouseac06f402016-06-21 10:20:49 +090013
David Pursehousea44e5902018-05-16 14:33:59 +090014This is called when a ref update request (direct push, non-fastforward update, or
15ref deletion) is received by Gerrit. It allows a request to be rejected before it
16is committed to the Gerrit repository.
17
David Pursehouse57c8e622019-12-02 15:22:20 +090018When multiple commits are pushed by direct push, this hook is called once with
19the `--oldrev` being the sha1 of the current branch tip, and `--newrev` being the
20sha1 of the commit that will be the new tip of the branch.
21
David Pursehouse0c6be302019-12-02 15:15:47 +090022If the hook exits with non-zero return code the update will be rejected and any
23output will be returned to the user.
JT Olds60adf572017-03-02 14:38:28 +090024
25```
David Pursehouseb7fe2092017-07-12 10:39:45 +090026 ref-update --project <project name> --refname <refname> --uploader <uploader> --uploader-username <username> --oldrev <sha1> --newrev <sha1>
JT Olds60adf572017-03-02 14:38:28 +090027```
28
David Pursehouse64e84452018-05-16 05:17:15 +000029### commit-received
JT Olds60adf572017-03-02 14:38:28 +090030
David Pursehouse57c8e622019-12-02 15:22:20 +090031This is called when a commit is received by Gerrit either by direct push or by
32push for review (to `refs/for/branch`). It allows a push to be rejected before
33a review is created, or before the branch is updated in case of a direct push.
34It is called once for each commit in the push.
David Pursehouseac06f402016-06-21 10:20:49 +090035
David Pursehousea44e5902018-05-16 14:33:59 +090036If the hook exits with non-zero return code the push will be rejected. Any output
37from the hook will be returned to the user, regardless of the return code.
David Pursehouseac06f402016-06-21 10:20:49 +090038
39```
David Pursehouseb7fe2092017-07-12 10:39:45 +090040 commit-received --project <project name> --refname <refname> --uploader <uploader> --uploader-username <username> --oldrev <sha1> --newrev <sha1> --cmdref <refname>
David Pursehouseac06f402016-06-21 10:20:49 +090041```
42
David Pursehouse0fe206d2018-05-16 16:12:52 +090043### submit
44
45This is called when a user attempts to submit a change. It allows the submit to
46be rejected.
47
48If the hook exits with non-zero return code the submit will be rejected and the
Gert van Dijk657f7c52019-02-20 23:00:45 +010049output from the hook will be returned to the user.
David Pursehouse0fe206d2018-05-16 16:12:52 +090050
51```
52 submit --project <project name> --branch <branch> --submitter <submitter> --patchset <patchset id> --commit <sha1>
53```
54
David Pursehouse64e84452018-05-16 05:17:15 +000055## Asynchronous Hooks
56
57These hooks are invoked asynchronously on a background thread.
58
59### patchset-created
David Pursehouseac06f402016-06-21 10:20:49 +090060
David Ostrovsky4bad0fe2017-02-23 22:22:44 +010061Called whenever a patchset is created (this includes new changes).
David Pursehouseac06f402016-06-21 10:20:49 +090062
Nick Talbot71cdc882018-09-20 15:57:18 +010063New patchsets do not generate this event when created as a result of merging a change
64(see change-merged for this). Examples are:
65* Submitting a change
66* Merging a change
67* Closing a change by direct push to branch
68
David Pursehouseac06f402016-06-21 10:20:49 +090069```
David Ostrovsky4bad0fe2017-02-23 22:22:44 +010070 patchset-created --change <change id> --kind <change kind> --change-url <change url> --change-owner <change owner> --change-owner-username <username> --project <project name> --branch <branch> --topic <topic> --uploader <uploader> --uploader-username <username> --commit <sha1> --patchset <patchset id>
David Pursehouseac06f402016-06-21 10:20:49 +090071```
72
73The `--kind` parameter represents the kind of change uploaded. See documentation
74of [`patchSet`][2] for details.
75
David Pursehouse64e84452018-05-16 05:17:15 +000076### comment-added
David Pursehouseac06f402016-06-21 10:20:49 +090077
78Called whenever a comment is added to a change.
79
80```
David Ostrovsky4bad0fe2017-02-23 22:22:44 +010081 comment-added --change <change id> --change-url <change url> --change-owner <change owner> --change-owner-username <username> --project <project name> --branch <branch> --topic <topic> --author <comment author> --author-username <username> --commit <commit> --comment <comment> [--<approval category id> <score> --<approval category id> <score> --<approval category id>-oldValue <score> ...]
David Pursehouseac06f402016-06-21 10:20:49 +090082```
83
David Pursehouse64e84452018-05-16 05:17:15 +000084### change-merged
David Pursehouseac06f402016-06-21 10:20:49 +090085
86Called whenever a change has been merged.
87
88```
David Pursehouseb7fe2092017-07-12 10:39:45 +090089 change-merged --change <change id> --change-url <change url> --change-owner <change owner> --change-owner-username <username> --project <project name> --branch <branch> --topic <topic> --submitter <submitter> --submitter-username <username> --commit <sha1> --newrev <sha1>
David Pursehouseac06f402016-06-21 10:20:49 +090090```
91
David Pursehouse64e84452018-05-16 05:17:15 +000092### change-abandoned
David Pursehouseac06f402016-06-21 10:20:49 +090093
94Called whenever a change has been abandoned.
95
96```
David Pursehouseb7fe2092017-07-12 10:39:45 +090097 change-abandoned --change <change id> --change-url <change url> --change-owner <change owner> --change-owner-username <username> --project <project name> --branch <branch> --topic <topic> --abandoner <abandoner> --abandoner-username <username> --commit <sha1> --reason <reason>
David Pursehouseac06f402016-06-21 10:20:49 +090098```
99
David Pursehouse8b718772018-09-14 10:32:11 +0900100### change-deleted
101
102Called whenever a change has been deleted.
103
104```
105 change-deleted --change <change id> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --topic <topic> --deleter <deleter>
106```
107
David Pursehouse64e84452018-05-16 05:17:15 +0000108### change-restored
David Pursehouseac06f402016-06-21 10:20:49 +0900109
110Called whenever a change has been restored.
111
112```
David Pursehouseb7fe2092017-07-12 10:39:45 +0900113 change-restored --change <change id> --change-url <change url> --change-owner <change owner> --change-owner-username <username> --project <project name> --branch <branch> --topic <topic> --restorer <restorer> --restorer-username <username> --commit <sha1> --reason <reason>
David Pursehouseac06f402016-06-21 10:20:49 +0900114```
115
David Pursehouse64e84452018-05-16 05:17:15 +0000116### ref-updated
David Pursehouseac06f402016-06-21 10:20:49 +0900117
118Called whenever a ref has been updated.
119
120```
David Pursehouseb7fe2092017-07-12 10:39:45 +0900121 ref-updated --oldrev <old rev> --newrev <new rev> --refname <ref name> --project <project name> --submitter <submitter> --submitter-username <username>
David Pursehouseac06f402016-06-21 10:20:49 +0900122```
123
David Pursehouse64e84452018-05-16 05:17:15 +0000124### project-created
David Pursehouseac06f402016-06-21 10:20:49 +0900125
126Called whenever a project has been created.
127
128```
129 project-created --project <project name> --head <head name>
130```
131
David Pursehouse64e84452018-05-16 05:17:15 +0000132### reviewer-added
David Pursehouseac06f402016-06-21 10:20:49 +0900133
134Called whenever a reviewer is added to a change.
135
136```
David Pursehouseb7fe2092017-07-12 10:39:45 +0900137 reviewer-added --change <change id> --change-url <change url> --change-owner <change owner> --change-owner-username <username> --project <project name> --branch <branch> --reviewer <reviewer> --reviewer-username <username>
David Pursehouseac06f402016-06-21 10:20:49 +0900138```
139
David Pursehouse64e84452018-05-16 05:17:15 +0000140### reviewer-deleted
David Pursehouseac06f402016-06-21 10:20:49 +0900141
142Called whenever a reviewer (with a vote) is removed from a change.
143
144```
David Pursehouseb7fe2092017-07-12 10:39:45 +0900145 reviewer-deleted --change <change id> --change-url <change url> --change-owner <change owner> --change-owner-username <username> --project <project name> --branch <branch> --reviewer <reviewer> [--<approval category id> <score> --<approval category id> <score> ...]
David Pursehouseac06f402016-06-21 10:20:49 +0900146```
147
David Pursehouse64e84452018-05-16 05:17:15 +0000148### topic-changed
David Pursehouseac06f402016-06-21 10:20:49 +0900149
150Called whenever a change's topic is changed from the Web UI or via the REST API.
151
152```
David Pursehouseb7fe2092017-07-12 10:39:45 +0900153 topic-changed --change <change id> --change-owner <change owner> --change-owner-username <username> --project <project name> --branch <branch> --changer <changer> --changer-username <username> --old-topic <old topic> --new-topic <new topic>
David Pursehouseac06f402016-06-21 10:20:49 +0900154```
155
David Pursehouse64e84452018-05-16 05:17:15 +0000156### hashtags-changed
David Pursehouseac06f402016-06-21 10:20:49 +0900157
158Called whenever hashtags are added to or removed from a change from the Web UI
159or via the REST API.
160
161```
David Pursehouseb7fe2092017-07-12 10:39:45 +0900162 hashtags-changed --change <change id> --change-owner <change owner> --change-owner-username <username> --project <project name> --branch <branch> --editor <editor> --editor-username <username> --added <hashtag> --removed <hashtag> --hashtag <hashtag>
David Pursehouseac06f402016-06-21 10:20:49 +0900163```
164
165The `--added` parameter may be passed multiple times, once for each
166hashtag that was added to the change.
167
168The `--removed` parameter may be passed multiple times, once for each
169hashtag that was removed from the change.
170
171The `--hashtag` parameter may be passed multiple times, once for each
172hashtag remaining on the change after the add or remove operation has
173been performed.
174
David Pursehouse64e84452018-05-16 05:17:15 +0000175### cla-signed
David Pursehouseac06f402016-06-21 10:20:49 +0900176
177Called whenever a user signs a contributor license agreement.
178
179```
180 cla-signed --submitter <submitter> --user-id <user_id> --cla-id <cla_id>
181```
182
Yuxuan 'fishy' Wangc1705a72016-08-22 19:15:22 -0700183[1]: config.md#hooks.syncHookTimeout
David Pursehouseac06f402016-06-21 10:20:49 +0900184[2]: ../../../Documentation/json.html#patchSet