David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 1 | # Supported Hooks |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 2 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 3 | [TOC] |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 4 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 5 | ## Synchronous Hooks |
JT Olds | 60adf57 | 2017-03-02 14:38:28 +0900 | [diff] [blame] | 6 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 7 | These hooks are invoked synchronously so it is recommended that they not block. |
| 8 | |
| 9 | A default timeout on the hook is set to 30 seconds to avoid "runaway" hooks using |
| 10 | up server threads. The timeout can be changed by setting [`hooks.syncHookTimeout`][1]. |
| 11 | |
| 12 | ### ref-update |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 13 | |
David Pursehouse | a44e590 | 2018-05-16 14:33:59 +0900 | [diff] [blame] | 14 | This is called when a ref update request (direct push, non-fastforward update, or |
| 15 | ref deletion) is received by Gerrit. It allows a request to be rejected before it |
| 16 | is committed to the Gerrit repository. |
| 17 | |
David Pursehouse | 57c8e62 | 2019-12-02 15:22:20 +0900 | [diff] [blame] | 18 | When multiple commits are pushed by direct push, this hook is called once with |
| 19 | the `--oldrev` being the sha1 of the current branch tip, and `--newrev` being the |
| 20 | sha1 of the commit that will be the new tip of the branch. |
| 21 | |
David Pursehouse | 0c6be30 | 2019-12-02 15:15:47 +0900 | [diff] [blame] | 22 | If the hook exits with non-zero return code the update will be rejected and any |
| 23 | output will be returned to the user. |
JT Olds | 60adf57 | 2017-03-02 14:38:28 +0900 | [diff] [blame] | 24 | |
| 25 | ``` |
David Pursehouse | b7fe209 | 2017-07-12 10:39:45 +0900 | [diff] [blame] | 26 | ref-update --project <project name> --refname <refname> --uploader <uploader> --uploader-username <username> --oldrev <sha1> --newrev <sha1> |
JT Olds | 60adf57 | 2017-03-02 14:38:28 +0900 | [diff] [blame] | 27 | ``` |
| 28 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 29 | ### commit-received |
JT Olds | 60adf57 | 2017-03-02 14:38:28 +0900 | [diff] [blame] | 30 | |
David Pursehouse | 57c8e62 | 2019-12-02 15:22:20 +0900 | [diff] [blame] | 31 | This is called when a commit is received by Gerrit either by direct push or by |
| 32 | push for review (to `refs/for/branch`). It allows a push to be rejected before |
| 33 | a review is created, or before the branch is updated in case of a direct push. |
| 34 | It is called once for each commit in the push. |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 35 | |
David Pursehouse | a44e590 | 2018-05-16 14:33:59 +0900 | [diff] [blame] | 36 | If the hook exits with non-zero return code the push will be rejected. Any output |
| 37 | from the hook will be returned to the user, regardless of the return code. |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 38 | |
| 39 | ``` |
David Pursehouse | b7fe209 | 2017-07-12 10:39:45 +0900 | [diff] [blame] | 40 | commit-received --project <project name> --refname <refname> --uploader <uploader> --uploader-username <username> --oldrev <sha1> --newrev <sha1> --cmdref <refname> |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 41 | ``` |
| 42 | |
David Pursehouse | 0fe206d | 2018-05-16 16:12:52 +0900 | [diff] [blame] | 43 | ### submit |
| 44 | |
| 45 | This is called when a user attempts to submit a change. It allows the submit to |
| 46 | be rejected. |
| 47 | |
| 48 | If the hook exits with non-zero return code the submit will be rejected and the |
Gert van Dijk | 657f7c5 | 2019-02-20 23:00:45 +0100 | [diff] [blame] | 49 | output from the hook will be returned to the user. |
David Pursehouse | 0fe206d | 2018-05-16 16:12:52 +0900 | [diff] [blame] | 50 | |
| 51 | ``` |
| 52 | submit --project <project name> --branch <branch> --submitter <submitter> --patchset <patchset id> --commit <sha1> |
| 53 | ``` |
| 54 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 55 | ## Asynchronous Hooks |
| 56 | |
| 57 | These hooks are invoked asynchronously on a background thread. |
| 58 | |
| 59 | ### patchset-created |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 60 | |
David Ostrovsky | 4bad0fe | 2017-02-23 22:22:44 +0100 | [diff] [blame] | 61 | Called whenever a patchset is created (this includes new changes). |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 62 | |
Nick Talbot | 71cdc88 | 2018-09-20 15:57:18 +0100 | [diff] [blame] | 63 | New 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 Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 69 | ``` |
David Ostrovsky | 4bad0fe | 2017-02-23 22:22:44 +0100 | [diff] [blame] | 70 | 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 Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 71 | ``` |
| 72 | |
| 73 | The `--kind` parameter represents the kind of change uploaded. See documentation |
| 74 | of [`patchSet`][2] for details. |
| 75 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 76 | ### comment-added |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 77 | |
| 78 | Called whenever a comment is added to a change. |
| 79 | |
| 80 | ``` |
David Ostrovsky | 4bad0fe | 2017-02-23 22:22:44 +0100 | [diff] [blame] | 81 | 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 Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 82 | ``` |
| 83 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 84 | ### change-merged |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 85 | |
| 86 | Called whenever a change has been merged. |
| 87 | |
| 88 | ``` |
David Pursehouse | b7fe209 | 2017-07-12 10:39:45 +0900 | [diff] [blame] | 89 | 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 Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 90 | ``` |
| 91 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 92 | ### change-abandoned |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 93 | |
| 94 | Called whenever a change has been abandoned. |
| 95 | |
| 96 | ``` |
David Pursehouse | b7fe209 | 2017-07-12 10:39:45 +0900 | [diff] [blame] | 97 | 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 Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 98 | ``` |
| 99 | |
David Pursehouse | 8b71877 | 2018-09-14 10:32:11 +0900 | [diff] [blame] | 100 | ### change-deleted |
| 101 | |
| 102 | Called 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 Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 108 | ### change-restored |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 109 | |
| 110 | Called whenever a change has been restored. |
| 111 | |
| 112 | ``` |
David Pursehouse | b7fe209 | 2017-07-12 10:39:45 +0900 | [diff] [blame] | 113 | 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 Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 114 | ``` |
| 115 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 116 | ### ref-updated |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 117 | |
| 118 | Called whenever a ref has been updated. |
| 119 | |
| 120 | ``` |
David Pursehouse | b7fe209 | 2017-07-12 10:39:45 +0900 | [diff] [blame] | 121 | ref-updated --oldrev <old rev> --newrev <new rev> --refname <ref name> --project <project name> --submitter <submitter> --submitter-username <username> |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 122 | ``` |
| 123 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 124 | ### project-created |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 125 | |
| 126 | Called whenever a project has been created. |
| 127 | |
| 128 | ``` |
| 129 | project-created --project <project name> --head <head name> |
| 130 | ``` |
| 131 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 132 | ### reviewer-added |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 133 | |
| 134 | Called whenever a reviewer is added to a change. |
| 135 | |
| 136 | ``` |
David Pursehouse | b7fe209 | 2017-07-12 10:39:45 +0900 | [diff] [blame] | 137 | 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 Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 138 | ``` |
| 139 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 140 | ### reviewer-deleted |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 141 | |
| 142 | Called whenever a reviewer (with a vote) is removed from a change. |
| 143 | |
| 144 | ``` |
David Pursehouse | b7fe209 | 2017-07-12 10:39:45 +0900 | [diff] [blame] | 145 | 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 Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 146 | ``` |
| 147 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 148 | ### topic-changed |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 149 | |
| 150 | Called whenever a change's topic is changed from the Web UI or via the REST API. |
| 151 | |
| 152 | ``` |
David Pursehouse | b7fe209 | 2017-07-12 10:39:45 +0900 | [diff] [blame] | 153 | 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 Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 154 | ``` |
| 155 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 156 | ### hashtags-changed |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 157 | |
| 158 | Called whenever hashtags are added to or removed from a change from the Web UI |
| 159 | or via the REST API. |
| 160 | |
| 161 | ``` |
David Pursehouse | b7fe209 | 2017-07-12 10:39:45 +0900 | [diff] [blame] | 162 | 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 Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 163 | ``` |
| 164 | |
| 165 | The `--added` parameter may be passed multiple times, once for each |
| 166 | hashtag that was added to the change. |
| 167 | |
| 168 | The `--removed` parameter may be passed multiple times, once for each |
| 169 | hashtag that was removed from the change. |
| 170 | |
| 171 | The `--hashtag` parameter may be passed multiple times, once for each |
| 172 | hashtag remaining on the change after the add or remove operation has |
| 173 | been performed. |
| 174 | |
David Pursehouse | 64e8445 | 2018-05-16 05:17:15 +0000 | [diff] [blame] | 175 | ### cla-signed |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 176 | |
| 177 | Called 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' Wang | c1705a7 | 2016-08-22 19:15:22 -0700 | [diff] [blame] | 183 | [1]: config.md#hooks.syncHookTimeout |
David Pursehouse | ac06f40 | 2016-06-21 10:20:49 +0900 | [diff] [blame] | 184 | [2]: ../../../Documentation/json.html#patchSet |