= Gerrit Code Review - Hooks Gerrit does not run any of the standard git hooks in the repositories it works with, but it does have its own hook mechanism included. Gerrit looks in `'$site_path'/hooks` for executables with names listed below. The environment will have GIT_DIR set to the full path of the affected git repository so that git commands can be easily run. Make sure your hook scripts are executable if running on *nix. With the exception of the ref-update hook, hooks are run in the background after the relevant change has taken place so are unable to affect the outcome of any given change. Because of the fact the hooks are run in the background after the activity, a hook might not be notified about an event if the server is shutdown before the hook can be invoked. == Supported Hooks === ref-update This is called when a push request is received by Gerrit. It allows a push to be rejected before it is committed to the Gerrit repository. If the script exits with non-zero return code the push will be rejected. Any output from the script will be returned to the user, regardless of the return code. This hook is called synchronously so it is recommended that it not block. A default timeout on the hook is set to 30 seconds to avoid "runaway" hooks using up server threads. See link:config-gerrit.html#hooks.syncHookTimeout[hooks.syncHookTimeout] for configuration details. ==== ref-update --project --refname --uploader --oldrev --newrev ==== === patchset-created This is called whenever a patchset is created (this includes new changes and drafts). ==== patchset-created --change --is-draft --kind --change-url --change-owner --project --branch --topic --uploader --commit --patchset ==== kind:: change kind represents the kind of change uploaded, also represented in link:json.html#patchSet[patchSet] REWORK;; Nontrivial content changes. TRIVIAL_REBASE;; Conflict-free merge between the new parent and the prior patch set. NO_CODE_CHANGE;; No code changed; same tree and same parents. === draft-published This is called whenever a draft change is published. ==== draft-published --change --change-url --change-owner --project --branch --topic --uploader --commit --patchset ==== === comment-added This is called whenever a comment is added to a change. ==== comment-added --change --is-draft --change-url --change-owner --project --branch --topic --author --commit --comment [-- -- ...] ==== === change-merged Called whenever a change has been merged. ==== change-merged --change --change-url --change-owner --project --branch --topic --submitter --commit ==== === merge-failed Called whenever a change has failed to merge. ==== merge-failed --change --change-url --change-owner --project --branch --topic --submitter --commit --reason ==== === change-abandoned Called whenever a change has been abandoned. ==== change-abandoned --change --change-url --change-owner --project --branch --topic --abandoner --commit --reason ==== === change-restored Called whenever a change has been restored. ==== change-restored --change --change-url --change-owner --project --branch --topic --restorer --commit --reason ==== === ref-updated Called whenever a ref has been updated. ==== ref-updated --oldrev --newrev --refname --project --submitter ==== === reviewer-added Called whenever a reviewer is added to a change. ==== reviewer-added --change --change-url --change-owner --project --branch --reviewer ==== === topic-changed Called whenever a change's topic is changed from the Web UI or via the REST API. ==== topic-changed --change --change-owner --project --branch --changer --old-topic --new-topic ==== === hashtags-changed Called whenever hashtags are added to or removed from a change from the Web UI or via the REST API. ==== hashtags-edited --change --change-owner --project --branch --editor --added --removed --hashtag ==== The `--added` parameter may be passed multiple times, once for each hashtag that was added to the change. The `--removed` parameter may be passed multiple times, once for each hashtag that was removed from the change. The `--hashtag` parameter may be passed multiple times, once for each hashtag remaining on the change after the add or remove operation has been performed. === cla-signed Called whenever a user signs a contributor license agreement. ==== cla-signed --submitter --user-id --cla-id ==== == Configuration Settings It is possible to change where Gerrit looks for hooks, and what filenames it looks for, by adding a [hooks] section in gerrit.config. Gerrit will use the value of hooks.path for the hooks directory. For the hook filenames, Gerrit will use the values of hooks.patchsetCreatedHook, hooks.draftPublishedHook, hooks.commentAddedHook, hooks.changeMergedHook, hooks.changeAbandonedHook, hooks.changeRestoredHook, hooks.refUpdatedHook, hooks.refUpdateHook, hooks.reviewerAddedHook and hooks.claSignedHook. == Missing Change URLs If link:config-gerrit.html#gerrit.canonicalWebUrl[gerrit.canonicalWebUrl] is not set in `gerrit.config` the `--change-url` flag may not be passed to all hooks. Hooks started out of an SSH context (for example the patchset-created hook) don't know the server's web URL, unless this variable is configured. == SEE ALSO * link:config-gerrit.html#hooks[Section hooks] GERRIT ------ Part of link:index.html[Gerrit Code Review] SEARCHBOX ---------