blob: 96dbff5afafa89fa1781f974b8b523f78dad40c5 [file] [log] [blame]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08001= Gerrit Code Review - Hooks
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +00002
3Gerrit does not run any of the standard git hooks in the
4repositories it works with, but it does have its own hook mechanism
5included. Gerrit looks in `'$site_path'/hooks` for executables with
6names listed below.
7
8The environment will have GIT_DIR set to the full path of the
9affected git repository so that git commands can be easily run.
10
11Make sure your hook scripts are executable if running on *nix.
12
Chris Harrisf736d6c2012-11-21 09:35:56 -050013With the exception of the ref-update hook, hooks are run in the background
14after the relevant change has taken place so are unable to affect
15the outcome of any given change. Because of the fact the hooks are
16run in the background after the activity, a hook might not be notified
17about an event if the server is shutdown before the hook can be invoked.
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000018
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080019== Supported Hooks
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000020
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080021=== ref-update
Chris Harrisf736d6c2012-11-21 09:35:56 -050022
23This is called when a push request is received by Gerrit. It allows
24a push to be rejected before it is committed to the Gerrit repository.
25If the script exits with non-zero return code the push will be rejected.
26Any output from the script will be returned to the user, regardless of the
27return code.
28
29This hook is called synchronously so it is recommended that
30it not block. A default timeout on the hook is set to 30 seconds to avoid
31"runaway" hooks using up server threads. See link:config-gerrit.html#hooks.syncHookTimeout[hooks.syncHookTimeout]
32for configuration details.
33
34====
35 ref-update --project <project name> --refname <refname> --uploader <uploader> --oldrev <sha1> --newrev <sha1>
36====
37
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080038=== patchset-created
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000039
40This is called whenever a patchset is created (this includes new
David Pursehoused556c192012-06-12 18:34:37 +090041changes and drafts).
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000042
43====
Doug Kelly58ba2062014-05-15 11:54:44 -050044 patchset-created --change <change id> --is-draft <boolean> --kind <change kind> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --topic <topic> --uploader <uploader> --commit <sha1> --patchset <patchset id>
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000045====
46
Doug Kelly58ba2062014-05-15 11:54:44 -050047kind:: change kind represents the kind of change uploaded, also represented in link:json.html#patchSet[patchSet]
48
49 REWORK;; Nontrivial content changes.
50
51 TRIVIAL_REBASE;; Conflict-free merge between the new parent and the prior patch set.
52
53 NO_CODE_CHANGE;; No code changed; same tree and same parents.
54
55
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080056=== draft-published
David Pursehoused556c192012-06-12 18:34:37 +090057
58This is called whenever a draft change is published.
59
60====
Khai Do70dbd5e2014-04-22 10:38:21 -070061 draft-published --change <change id> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --topic <topic> --uploader <uploader> --commit <sha1> --patchset <patchset id>
David Pursehoused556c192012-06-12 18:34:37 +090062====
63
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080064=== comment-added
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000065
66This is called whenever a comment is added to a change.
67
68====
Khai Do70dbd5e2014-04-22 10:38:21 -070069 comment-added --change <change id> --is-draft <boolean> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --topic <topic> --author <comment author> --commit <commit> --comment <comment> [--<approval category id> <score> --<approval category id> <score> ...]
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000070====
71
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080072=== change-merged
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000073
74Called whenever a change has been merged.
75
76====
Khai Do70dbd5e2014-04-22 10:38:21 -070077 change-merged --change <change id> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --topic <topic> --submitter <submitter> --commit <sha1>
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000078====
79
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080080=== merge-failed
David Pursehousef9f3b272012-09-28 19:58:59 +090081
82Called whenever a change has failed to merge.
83
84====
Khai Do70dbd5e2014-04-22 10:38:21 -070085 merge-failed --change <change id> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --topic <topic> --submitter <submitter> --commit <sha1> --reason <reason>
David Pursehousef9f3b272012-09-28 19:58:59 +090086====
87
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080088=== change-abandoned
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000089
90Called whenever a change has been abandoned.
91
92====
Khai Do70dbd5e2014-04-22 10:38:21 -070093 change-abandoned --change <change id> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --topic <topic> --abandoner <abandoner> --commit <sha1> --reason <reason>
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +000094====
95
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080096=== change-restored
Anatol Pomazau607570e2010-08-04 11:28:50 -070097
98Called whenever a change has been restored.
99
100====
Khai Do70dbd5e2014-04-22 10:38:21 -0700101 change-restored --change <change id> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --topic <topic> --restorer <restorer> --commit <sha1> --reason <reason>
Anatol Pomazau607570e2010-08-04 11:28:50 -0700102====
103
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800104=== ref-updated
Jesse Greenwald6cc11902010-10-06 19:46:25 -0500105
106Called whenever a ref has been updated.
107
108====
109 ref-updated --oldrev <old rev> --newrev <new rev> --refname <ref name> --project <project name> --submitter <submitter>
110====
111
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800112=== reviewer-added
David Pursehouse2336bd82012-09-21 12:50:19 +0900113
114Called whenever a reviewer is added to a change.
115
116====
Khai Do70dbd5e2014-04-22 10:38:21 -0700117 reviewer-added --change <change id> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --reviewer <reviewer>
David Pursehouse2336bd82012-09-21 12:50:19 +0900118====
119
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800120=== topic-changed
David Pursehouseba3e28d2013-07-12 14:48:51 +0900121
122Called whenever a change's topic is changed from the Web UI or via the REST API.
123
124====
Khai Do70dbd5e2014-04-22 10:38:21 -0700125 topic-changed --change <change id> --change-owner <change owner> --project <project name> --branch <branch> --changer <changer> --old-topic <old topic> --new-topic <new topic>
David Pursehouseba3e28d2013-07-12 14:48:51 +0900126====
127
David Pursehousecb2e4852014-09-12 15:09:12 +0200128=== hashtags-changed
129
130Called whenever hashtags are added to or removed from a change from the Web UI
131or via the REST API.
132
133====
David Pursehouse1db6d972014-12-25 11:57:26 +0900134 hashtags-changed --change <change id> --change-owner <change owner> --project <project name> --branch <branch> --editor <editor> --added <hashtag> --removed <hashtag> --hashtag <hashtag>
David Pursehousecb2e4852014-09-12 15:09:12 +0200135====
136
137The `--added` parameter may be passed multiple times, once for each
138hashtag that was added to the change.
139
140The `--removed` parameter may be passed multiple times, once for each
141hashtag that was removed from the change.
142
143The `--hashtag` parameter may be passed multiple times, once for each
144hashtag remaining on the change after the add or remove operation has
145been performed.
146
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800147=== cla-signed
Mike Wiederhold2ad3f982010-11-01 14:11:13 -0700148
David Pursehousea93c9302012-06-15 16:29:26 +0900149Called whenever a user signs a contributor license agreement.
Mike Wiederhold2ad3f982010-11-01 14:11:13 -0700150
151====
152 cla-signed --submitter <submitter> --user-id <user_id> --cla-id <cla_id>
153====
154
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +0000155
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800156== Configuration Settings
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +0000157
David Pursehouse221d4f62012-06-08 17:38:08 +0900158It is possible to change where Gerrit looks for hooks, and what
David Pursehousea93c9302012-06-15 16:29:26 +0900159filenames it looks for, by adding a [hooks] section in gerrit.config.
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +0000160
David Pursehousea93c9302012-06-15 16:29:26 +0900161Gerrit will use the value of hooks.path for the hooks directory.
162
163For the hook filenames, Gerrit will use the values of hooks.patchsetCreatedHook,
David Pursehoused556c192012-06-12 18:34:37 +0900164hooks.draftPublishedHook, hooks.commentAddedHook, hooks.changeMergedHook,
David Pursehouse2336bd82012-09-21 12:50:19 +0900165hooks.changeAbandonedHook, hooks.changeRestoredHook, hooks.refUpdatedHook,
Chris Harrisf736d6c2012-11-21 09:35:56 -0500166hooks.refUpdateHook, hooks.reviewerAddedHook and hooks.claSignedHook.
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +0000167
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800168== Missing Change URLs
Shawn O. Pearcebd870e52010-08-23 08:33:55 -0700169
170If link:config-gerrit.html#gerrit.canonicalWebUrl[gerrit.canonicalWebUrl]
Edwin Kempincdb0e002011-09-08 14:23:30 +0200171is not set in `gerrit.config` the `--change-url` flag may not be
Shawn O. Pearcebd870e52010-08-23 08:33:55 -0700172passed to all hooks. Hooks started out of an SSH context (for example
173the patchset-created hook) don't know the server's web URL, unless
174this variable is configured.
175
Fredrik Luthandera6bb9512014-03-24 18:59:45 -0700176== SEE ALSO
Shane Mc Cormack6c2b6772010-01-12 21:56:44 +0000177
178* link:config-gerrit.html#hooks[Section hooks]
179
180GERRIT
181------
Scott Andersond57422e2010-06-01 15:06:04 -0400182Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700183
184SEARCHBOX
185---------