summaryrefslogtreecommitdiffstats
path: root/Documentation/config-hooks.txt
blob: 1236077d4bae18c4f1564e8e62fbdf66685e03cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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 <project name> --refname <refname> --uploader <uploader> --oldrev <sha1> --newrev <sha1>
====

patchset-created
~~~~~~~~~~~~~~~~

This is called whenever a patchset is created (this includes new
changes and drafts).

====
  patchset-created --change <change id> --is-draft <boolean> --change-url <change url> --project <project name> --branch <branch> --topic <topic> --uploader <uploader> --commit <sha1> --patchset <patchset id>
====

draft-published
~~~~~~~~~~~~~~~

This is called whenever a draft change is published.

====
  draft-published --change <change id> --change-url <change url> --project <project name> --branch <branch> --topic <topic> --uploader <uploader> --commit <sha1> --patchset <patchset id>
====

comment-added
~~~~~~~~~~~~~

This is called whenever a comment is added to a change.

====
  comment-added --change <change id> --is-draft <boolean> --change-url <change url> --project <project name> --branch <branch> --topic <topic> --author <comment author> --commit <commit> --comment <comment> [--<approval category id> <score> --<approval category id> <score> ...]
====

change-merged
~~~~~~~~~~~~~

Called whenever a change has been merged.

====
  change-merged --change <change id> --change-url <change url> --project <project name> --branch <branch> --topic <topic> --submitter <submitter> --commit <sha1>
====

merge-failed
~~~~~~~~~~~~

Called whenever a change has failed to merge.

====
  merge-failed --change <change id> --change-url <change url> --project <project name> --branch <branch> --topic <topic> --submitter <submitter> --commit <sha1> --reason <reason>
====

change-abandoned
~~~~~~~~~~~~~~~~

Called whenever a change has been abandoned.

====
  change-abandoned --change <change id> --change-url <change url> --project <project name> --branch <branch> --topic <topic> --abandoner <abandoner> --reason <reason>
====

change-restored
~~~~~~~~~~~~~~~

Called whenever a change has been restored.

====
  change-restored --change <change id> --change-url <change url> --project <project name> --branch <branch> --topic <topic> --restorer <restorer> --reason <reason>
====

ref-updated
~~~~~~~~~~~

Called whenever a ref has been updated.

====
  ref-updated --oldrev <old rev> --newrev <new rev> --refname <ref name> --project <project name> --submitter <submitter>
====

reviewer-added
~~~~~~~~~~~~~~

Called whenever a reviewer is added to a change.

====
  reviewer-added --change <change id> --change-url <change url> --project <project name> --branch <branch> --reviewer <reviewer>
====

cla-signed
~~~~~~~~~~

Called whenever a user signs a contributor license agreement.

====
  cla-signed --submitter <submitter> --user-id <user_id> --cla-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]