Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1 | = Gerrit Code Review - Hooks |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 2 | |
| 3 | Gerrit does not run any of the standard git hooks in the |
| 4 | repositories it works with, but it does have its own hook mechanism |
| 5 | included. Gerrit looks in `'$site_path'/hooks` for executables with |
| 6 | names listed below. |
| 7 | |
| 8 | The environment will have GIT_DIR set to the full path of the |
| 9 | affected git repository so that git commands can be easily run. |
| 10 | |
| 11 | Make sure your hook scripts are executable if running on *nix. |
| 12 | |
Chris Harris | f736d6c | 2012-11-21 09:35:56 -0500 | [diff] [blame] | 13 | With the exception of the ref-update hook, hooks are run in the background |
| 14 | after the relevant change has taken place so are unable to affect |
| 15 | the outcome of any given change. Because of the fact the hooks are |
| 16 | run in the background after the activity, a hook might not be notified |
| 17 | about an event if the server is shutdown before the hook can be invoked. |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 18 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 19 | == Supported Hooks |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 20 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 21 | === ref-update |
Chris Harris | f736d6c | 2012-11-21 09:35:56 -0500 | [diff] [blame] | 22 | |
| 23 | This is called when a push request is received by Gerrit. It allows |
| 24 | a push to be rejected before it is committed to the Gerrit repository. |
| 25 | If the script exits with non-zero return code the push will be rejected. |
| 26 | Any output from the script will be returned to the user, regardless of the |
| 27 | return code. |
| 28 | |
| 29 | This hook is called synchronously so it is recommended that |
| 30 | it 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] |
| 32 | for configuration details. |
| 33 | |
| 34 | ==== |
| 35 | ref-update --project <project name> --refname <refname> --uploader <uploader> --oldrev <sha1> --newrev <sha1> |
| 36 | ==== |
| 37 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 38 | === patchset-created |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 39 | |
| 40 | This is called whenever a patchset is created (this includes new |
David Pursehouse | d556c19 | 2012-06-12 18:34:37 +0900 | [diff] [blame] | 41 | changes and drafts). |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 42 | |
| 43 | ==== |
Doug Kelly | 58ba206 | 2014-05-15 11:54:44 -0500 | [diff] [blame] | 44 | 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 Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 45 | ==== |
| 46 | |
Doug Kelly | 58ba206 | 2014-05-15 11:54:44 -0500 | [diff] [blame] | 47 | kind:: 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' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 56 | === draft-published |
David Pursehouse | d556c19 | 2012-06-12 18:34:37 +0900 | [diff] [blame] | 57 | |
| 58 | This is called whenever a draft change is published. |
| 59 | |
| 60 | ==== |
Khai Do | 70dbd5e | 2014-04-22 10:38:21 -0700 | [diff] [blame] | 61 | 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 Pursehouse | d556c19 | 2012-06-12 18:34:37 +0900 | [diff] [blame] | 62 | ==== |
| 63 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 64 | === comment-added |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 65 | |
| 66 | This is called whenever a comment is added to a change. |
| 67 | |
| 68 | ==== |
Khai Do | 70dbd5e | 2014-04-22 10:38:21 -0700 | [diff] [blame] | 69 | 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 Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 70 | ==== |
| 71 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 72 | === change-merged |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 73 | |
| 74 | Called whenever a change has been merged. |
| 75 | |
| 76 | ==== |
Khai Do | 70dbd5e | 2014-04-22 10:38:21 -0700 | [diff] [blame] | 77 | 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 Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 78 | ==== |
| 79 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 80 | === merge-failed |
David Pursehouse | f9f3b27 | 2012-09-28 19:58:59 +0900 | [diff] [blame] | 81 | |
| 82 | Called whenever a change has failed to merge. |
| 83 | |
| 84 | ==== |
Khai Do | 70dbd5e | 2014-04-22 10:38:21 -0700 | [diff] [blame] | 85 | 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 Pursehouse | f9f3b27 | 2012-09-28 19:58:59 +0900 | [diff] [blame] | 86 | ==== |
| 87 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 88 | === change-abandoned |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 89 | |
| 90 | Called whenever a change has been abandoned. |
| 91 | |
| 92 | ==== |
Khai Do | 70dbd5e | 2014-04-22 10:38:21 -0700 | [diff] [blame] | 93 | 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 Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 94 | ==== |
| 95 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 96 | === change-restored |
Anatol Pomazau | 607570e | 2010-08-04 11:28:50 -0700 | [diff] [blame] | 97 | |
| 98 | Called whenever a change has been restored. |
| 99 | |
| 100 | ==== |
Khai Do | 70dbd5e | 2014-04-22 10:38:21 -0700 | [diff] [blame] | 101 | 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 Pomazau | 607570e | 2010-08-04 11:28:50 -0700 | [diff] [blame] | 102 | ==== |
| 103 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 104 | === ref-updated |
Jesse Greenwald | 6cc1190 | 2010-10-06 19:46:25 -0500 | [diff] [blame] | 105 | |
| 106 | Called 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' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 112 | === reviewer-added |
David Pursehouse | 2336bd8 | 2012-09-21 12:50:19 +0900 | [diff] [blame] | 113 | |
| 114 | Called whenever a reviewer is added to a change. |
| 115 | |
| 116 | ==== |
Khai Do | 70dbd5e | 2014-04-22 10:38:21 -0700 | [diff] [blame] | 117 | reviewer-added --change <change id> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --reviewer <reviewer> |
David Pursehouse | 2336bd8 | 2012-09-21 12:50:19 +0900 | [diff] [blame] | 118 | ==== |
| 119 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 120 | === topic-changed |
David Pursehouse | ba3e28d | 2013-07-12 14:48:51 +0900 | [diff] [blame] | 121 | |
| 122 | Called whenever a change's topic is changed from the Web UI or via the REST API. |
| 123 | |
| 124 | ==== |
Khai Do | 70dbd5e | 2014-04-22 10:38:21 -0700 | [diff] [blame] | 125 | 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 Pursehouse | ba3e28d | 2013-07-12 14:48:51 +0900 | [diff] [blame] | 126 | ==== |
| 127 | |
David Pursehouse | cb2e485 | 2014-09-12 15:09:12 +0200 | [diff] [blame] | 128 | === hashtags-changed |
| 129 | |
| 130 | Called whenever hashtags are added to or removed from a change from the Web UI |
| 131 | or via the REST API. |
| 132 | |
| 133 | ==== |
David Pursehouse | 1db6d97 | 2014-12-25 11:57:26 +0900 | [diff] [blame] | 134 | hashtags-changed --change <change id> --change-owner <change owner> --project <project name> --branch <branch> --editor <editor> --added <hashtag> --removed <hashtag> --hashtag <hashtag> |
David Pursehouse | cb2e485 | 2014-09-12 15:09:12 +0200 | [diff] [blame] | 135 | ==== |
| 136 | |
| 137 | The `--added` parameter may be passed multiple times, once for each |
| 138 | hashtag that was added to the change. |
| 139 | |
| 140 | The `--removed` parameter may be passed multiple times, once for each |
| 141 | hashtag that was removed from the change. |
| 142 | |
| 143 | The `--hashtag` parameter may be passed multiple times, once for each |
| 144 | hashtag remaining on the change after the add or remove operation has |
| 145 | been performed. |
| 146 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 147 | === cla-signed |
Mike Wiederhold | 2ad3f98 | 2010-11-01 14:11:13 -0700 | [diff] [blame] | 148 | |
David Pursehouse | a93c930 | 2012-06-15 16:29:26 +0900 | [diff] [blame] | 149 | Called whenever a user signs a contributor license agreement. |
Mike Wiederhold | 2ad3f98 | 2010-11-01 14:11:13 -0700 | [diff] [blame] | 150 | |
| 151 | ==== |
| 152 | cla-signed --submitter <submitter> --user-id <user_id> --cla-id <cla_id> |
| 153 | ==== |
| 154 | |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 155 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 156 | == Configuration Settings |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 157 | |
David Pursehouse | 221d4f6 | 2012-06-08 17:38:08 +0900 | [diff] [blame] | 158 | It is possible to change where Gerrit looks for hooks, and what |
David Pursehouse | a93c930 | 2012-06-15 16:29:26 +0900 | [diff] [blame] | 159 | filenames it looks for, by adding a [hooks] section in gerrit.config. |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 160 | |
David Pursehouse | a93c930 | 2012-06-15 16:29:26 +0900 | [diff] [blame] | 161 | Gerrit will use the value of hooks.path for the hooks directory. |
| 162 | |
| 163 | For the hook filenames, Gerrit will use the values of hooks.patchsetCreatedHook, |
David Pursehouse | d556c19 | 2012-06-12 18:34:37 +0900 | [diff] [blame] | 164 | hooks.draftPublishedHook, hooks.commentAddedHook, hooks.changeMergedHook, |
David Pursehouse | 2336bd8 | 2012-09-21 12:50:19 +0900 | [diff] [blame] | 165 | hooks.changeAbandonedHook, hooks.changeRestoredHook, hooks.refUpdatedHook, |
Chris Harris | f736d6c | 2012-11-21 09:35:56 -0500 | [diff] [blame] | 166 | hooks.refUpdateHook, hooks.reviewerAddedHook and hooks.claSignedHook. |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 167 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 168 | == Missing Change URLs |
Shawn O. Pearce | bd870e5 | 2010-08-23 08:33:55 -0700 | [diff] [blame] | 169 | |
| 170 | If link:config-gerrit.html#gerrit.canonicalWebUrl[gerrit.canonicalWebUrl] |
Edwin Kempin | cdb0e00 | 2011-09-08 14:23:30 +0200 | [diff] [blame] | 171 | is not set in `gerrit.config` the `--change-url` flag may not be |
Shawn O. Pearce | bd870e5 | 2010-08-23 08:33:55 -0700 | [diff] [blame] | 172 | passed to all hooks. Hooks started out of an SSH context (for example |
| 173 | the patchset-created hook) don't know the server's web URL, unless |
| 174 | this variable is configured. |
| 175 | |
Fredrik Luthander | a6bb951 | 2014-03-24 18:59:45 -0700 | [diff] [blame] | 176 | == SEE ALSO |
Shane Mc Cormack | 6c2b677 | 2010-01-12 21:56:44 +0000 | [diff] [blame] | 177 | |
| 178 | * link:config-gerrit.html#hooks[Section hooks] |
| 179 | |
| 180 | GERRIT |
| 181 | ------ |
Scott Anderson | d57422e | 2010-06-01 15:06:04 -0400 | [diff] [blame] | 182 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 183 | |
| 184 | SEARCHBOX |
| 185 | --------- |