James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 1 | :title: GitHub Driver |
| 2 | |
| 3 | GitHub |
| 4 | ====== |
| 5 | |
| 6 | The GitHub driver supports sources, triggers, and reporters. It can |
| 7 | interact with the public GitHub service as well as site-local |
| 8 | installations of GitHub enterprise. |
| 9 | |
| 10 | .. TODO: make this section more user friendly |
| 11 | |
| 12 | Configure GitHub `webhook events |
| 13 | <https://developer.github.com/webhooks/creating/>`_. |
| 14 | |
| 15 | Set *Payload URL* to |
| 16 | ``http://<zuul-hostname>/connection/<connection-name>/payload``. |
| 17 | |
| 18 | Set *Content Type* to ``application/json``. |
| 19 | |
| 20 | Select *Events* you are interested in. See below for the supported events. |
| 21 | |
| 22 | Connection Configuration |
| 23 | ------------------------ |
| 24 | |
Monty Taylor | ae1f03a | 2017-07-27 14:43:32 -0500 | [diff] [blame] | 25 | There are two forms of operation. Either the Zuul installation can be |
| 26 | configured as a `Github App`_ or it can be configured as a Webhook. |
| 27 | |
| 28 | If the `Github App`_ approach is taken, the config settings ``app_id`` and |
| 29 | ``app_key`` are required. If the Webhook approach is taken, the ``api_token`` |
| 30 | setting is required. |
| 31 | |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 32 | The supported options in zuul.conf connections are: |
| 33 | |
| 34 | **driver=github** |
| 35 | |
Monty Taylor | ae1f03a | 2017-07-27 14:43:32 -0500 | [diff] [blame] | 36 | **app_id** |
| 37 | App ID if you are using a GitHub App. Can be found under the "Public Link" |
| 38 | on the right hand side labeled "ID". |
Monty Taylor | 4b20399 | 2017-07-28 04:09:19 -0500 | [diff] [blame] | 39 | ``app_id=1234`` |
Monty Taylor | ae1f03a | 2017-07-27 14:43:32 -0500 | [diff] [blame] | 40 | |
| 41 | **app_key** |
Monty Taylor | 4b20399 | 2017-07-28 04:09:19 -0500 | [diff] [blame] | 42 | Path to a file containing the Secret Key Zuul will use to create tokens for |
| 43 | the API interactions. In Github this is known as "Private key" and must be |
| 44 | collected when generated. |
| 45 | ``app_key=/etc/zuul/github.key`` |
Monty Taylor | ae1f03a | 2017-07-27 14:43:32 -0500 | [diff] [blame] | 46 | |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 47 | **api_token** |
Monty Taylor | ae1f03a | 2017-07-27 14:43:32 -0500 | [diff] [blame] | 48 | API token for accessing GitHub if Zuul is configured with Webhooks. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 49 | See `Creating an access token for command-line use |
| 50 | <https://help.github.com/articles/creating-an-access-token-for-command-line-use/>`_. |
| 51 | |
| 52 | **webhook_token** |
Clint Byrum | cf1b742 | 2017-07-27 17:12:00 -0700 | [diff] [blame] | 53 | Required token for validating the webhook event payloads. In the |
| 54 | GitHub App Configuration page, this is called "Webhook secret". |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 55 | See `Securing your webhooks |
| 56 | <https://developer.github.com/webhooks/securing/>`_. |
| 57 | |
| 58 | **sshkey** |
| 59 | Path to SSH key to use when cloning github repositories. |
| 60 | ``sshkey=/home/zuul/.ssh/id_rsa`` |
| 61 | |
James E. Blair | 5f11ff3 | 2017-06-23 21:46:45 +0100 | [diff] [blame] | 62 | **server** |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 63 | Optional: Hostname of the github install (such as a GitHub Enterprise) |
| 64 | If not specified, defaults to ``github.com`` |
James E. Blair | 5f11ff3 | 2017-06-23 21:46:45 +0100 | [diff] [blame] | 65 | ``server=github.myenterprise.com`` |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 66 | |
James E. Blair | 4d5dd25 | 2017-06-23 21:40:56 +0100 | [diff] [blame] | 67 | **canonical_hostname** |
| 68 | The canonical hostname associated with the git repos on the GitHub |
James E. Blair | 5f11ff3 | 2017-06-23 21:46:45 +0100 | [diff] [blame] | 69 | server. Defaults to the value of **server**. This is used to |
James E. Blair | cc3ca7d | 2017-06-29 11:09:18 -0700 | [diff] [blame] | 70 | identify projects from this connection by name and in preparing |
| 71 | repos on the filesystem for use by jobs. Note that Zuul will still |
| 72 | only communicate with the GitHub server identified by **server**; |
| 73 | this option is useful if users customarily use a different hostname |
| 74 | to clone or pull git repos so that when Zuul places them in the |
| 75 | job's working directory, they appear under this directory name. |
James E. Blair | 4d5dd25 | 2017-06-23 21:40:56 +0100 | [diff] [blame] | 76 | ``canonical_hostname=git.example.com`` |
| 77 | |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 78 | Trigger Configuration |
| 79 | --------------------- |
| 80 | GitHub webhook events can be configured as triggers. |
| 81 | |
| 82 | A connection name with the github driver can take multiple events with the |
| 83 | following options. |
| 84 | |
| 85 | **event** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 86 | The event from github. Supported events are ``pull_request``, |
| 87 | ``pull_request_review``, and ``push``. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 88 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 89 | A ``pull_request`` event will have associated action(s) to trigger |
| 90 | from. The supported actions are: |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 91 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 92 | *opened* - pull request opened |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 93 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 94 | *changed* - pull request synchronized |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 95 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 96 | *closed* - pull request closed |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 97 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 98 | *reopened* - pull request reopened |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 99 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 100 | *comment* - comment added on pull request |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 101 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 102 | *labeled* - label added on pull request |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 103 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 104 | *unlabeled* - label removed from pull request |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 105 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 106 | *status* - status set on commit |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 107 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 108 | A ``pull_request_review`` event will |
| 109 | have associated action(s) to trigger from. The supported actions are: |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 110 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 111 | *submitted* - pull request review added |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 112 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 113 | *dismissed* - pull request review removed |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 114 | |
| 115 | **branch** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 116 | The branch associated with the event. Example: ``master``. This |
| 117 | field is treated as a regular expression, and multiple branches may |
| 118 | be listed. Used for ``pull_request`` and ``pull_request_review`` |
| 119 | events. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 120 | |
| 121 | **comment** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 122 | This is only used for ``pull_request`` ``comment`` actions. It |
| 123 | accepts a list of regexes that are searched for in the comment |
| 124 | string. If any of these regexes matches a portion of the comment |
| 125 | string the trigger is matched. ``comment: retrigger`` will match |
| 126 | when comments containing 'retrigger' somewhere in the comment text |
| 127 | are added to a pull request. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 128 | |
| 129 | **label** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 130 | This is only used for ``labeled`` and ``unlabeled`` ``pull_request`` |
| 131 | actions. It accepts a list of strings each of which matches the |
| 132 | label name in the event literally. ``label: recheck`` will match a |
| 133 | ``labeled`` action when pull request is labeled with a ``recheck`` |
| 134 | label. ``label: 'do not test'`` will match a ``unlabeled`` action |
| 135 | when a label with name ``do not test`` is removed from the pull |
| 136 | request. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 137 | |
| 138 | **state** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 139 | This is only used for ``pull_request_review`` events. It accepts a |
| 140 | list of strings each of which is matched to the review state, which |
| 141 | can be one of ``approved``, ``comment``, or ``request_changes``. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 142 | |
| 143 | **status** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 144 | This is used for ``pull-request`` and ``status`` actions. It accepts |
| 145 | a list of strings each of which matches the user setting the status, |
| 146 | the status context, and the status itself in the format of |
| 147 | ``user:context:status``. For example, |
| 148 | ``zuul_github_ci_bot:check_pipeline:success``. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 149 | |
| 150 | **ref** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 151 | This is only used for ``push`` events. This field is treated as a |
| 152 | regular expression and multiple refs may be listed. GitHub always |
| 153 | sends full ref name, eg. ``refs/tags/bar`` and this string is |
| 154 | matched against the regexp. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 155 | |
| 156 | Reporter Configuration |
| 157 | ---------------------- |
| 158 | Zuul reports back to GitHub via GitHub API. Available reports include a PR |
| 159 | comment containing the build results, a commit status on start, success and |
| 160 | failure, an issue label addition/removal on the PR, and a merge of the PR |
| 161 | itself. Status name, description, and context is taken from the pipeline. |
| 162 | |
| 163 | A :ref:`connection<connections>` that uses the github driver must be |
| 164 | supplied to the reporter. It has the following options: |
| 165 | |
| 166 | **status** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 167 | String value (``pending``, ``success``, ``failure``) that the |
| 168 | reporter should set as the commit status on github. ``status: |
| 169 | 'success'`` |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 170 | |
| 171 | **status-url** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 172 | String value for a link url to set in the github status. Defaults to |
| 173 | the zuul server status_url, or the empty string if that is unset. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 174 | |
| 175 | **comment** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 176 | Boolean value (``true`` or ``false``) that determines if the |
| 177 | reporter should add a comment to the pipeline status to the github |
| 178 | pull request. Defaults to ``true``. Only used for Pull Request based |
| 179 | events. ``comment: false`` |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 180 | |
| 181 | **merge** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 182 | Boolean value (``true`` or ``false``) that determines if the |
| 183 | reporter should merge the pull reqeust. Defaults to ``false``. Only |
| 184 | used for Pull Request based events. ``merge=true`` |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 185 | |
| 186 | **label** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 187 | List of strings each representing an exact label name which should |
| 188 | be added to the pull request by reporter. Only used for Pull Request |
| 189 | based events. ``label: 'test successful'`` |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 190 | |
| 191 | **unlabel** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 192 | List of strings each representing an exact label name which should |
| 193 | be removed from the pull request by reporter. Only used for Pull |
| 194 | Request based events. ``unlabel: 'test failed'`` |
Monty Taylor | ae1f03a | 2017-07-27 14:43:32 -0500 | [diff] [blame] | 195 | |
| 196 | .. _Github App: https://developer.github.com/apps/ |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 197 | |
| 198 | Requirements Configuration |
| 199 | -------------------------- |
| 200 | |
James E. Blair | 32c5248 | 2017-07-29 07:49:03 -0700 | [diff] [blame] | 201 | As described in :attr:`pipeline.require` and :attr:`pipeline.reject`, |
| 202 | pipelines may specify that items meet certain conditions in order to |
| 203 | be enqueued into the pipeline. These conditions vary according to the |
| 204 | source of the project in question. To supply requirements for changes |
| 205 | from a GitHub source named *my-github*, create a congfiguration such |
| 206 | as the following:: |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 207 | |
| 208 | pipeline: |
| 209 | require: |
| 210 | my-github: |
| 211 | review: |
| 212 | - type: approval |
| 213 | |
| 214 | This indicates that changes originating from the GitHub connection |
| 215 | named *my-github* must have an approved code review in order to be |
| 216 | enqueued into the pipeline. |
| 217 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 218 | .. attr:: pipeline.require.<github source> |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 219 | |
| 220 | The dictionary passed to the GitHub pipeline `require` attribute |
| 221 | supports the following attributes: |
| 222 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 223 | .. attr:: review |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 224 | |
| 225 | This requires that a certain kind of code review be present for |
| 226 | the pull request (it could be added by the event in question). |
| 227 | It takes several sub-parameters, all of which are optional and |
| 228 | are combined together so that there must be a code review |
| 229 | matching all specified requirements. |
| 230 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 231 | .. attr:: username |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 232 | |
| 233 | If present, a code review from this username is required. It |
| 234 | is treated as a regular expression. |
| 235 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 236 | .. attr:: email |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 237 | |
| 238 | If present, a code review with this email address is |
| 239 | required. It is treated as a regular expression. |
| 240 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 241 | .. attr:: older-than |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 242 | |
| 243 | If present, the code review must be older than this amount of |
| 244 | time to match. Provide a time interval as a number with a |
| 245 | suffix of "w" (weeks), "d" (days), "h" (hours), "m" |
| 246 | (minutes), "s" (seconds). Example ``48h`` or ``2d``. |
| 247 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 248 | .. attr:: newer-than |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 249 | |
| 250 | If present, the code review must be newer than this amount of |
| 251 | time to match. Same format as "older-than". |
| 252 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 253 | .. attr:: type |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 254 | |
| 255 | If present, the code review must match this type (or types). |
| 256 | |
| 257 | .. TODO: what types are valid? |
| 258 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 259 | .. attr:: permission |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 260 | |
| 261 | If present, the author of the code review must have this |
| 262 | permission (or permissions). The available values are |
| 263 | ``read``, ``write``, and ``admin``. |
| 264 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 265 | .. attr:: open |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 266 | |
| 267 | A boolean value (``true`` or ``false``) that indicates whether |
| 268 | the change must be open or closed in order to be enqueued. |
| 269 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 270 | .. attr:: current-patchset |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 271 | |
| 272 | A boolean value (``true`` or ``false``) that indicates whether |
| 273 | the item must be associated with the latest commit in the pull |
| 274 | request in order to be enqueued. |
| 275 | |
| 276 | .. TODO: this could probably be expanded upon -- under what |
| 277 | circumstances might this happen with github |
| 278 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 279 | .. attr:: status |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 280 | |
| 281 | A string value that corresponds with the status of the pull |
| 282 | request. The syntax is ``user:status:value``. |
| 283 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 284 | .. attr:: label |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 285 | |
| 286 | A string value indicating that the pull request must have the |
| 287 | indicated label (or labels). |
| 288 | |
| 289 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 290 | .. attr:: pipeline.reject.<github source> |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 291 | |
| 292 | The `reject` attribute is the mirror of the `require` attribute. It |
| 293 | also accepts a dictionary under the connection name. This |
| 294 | dictionary supports the following attributes: |
| 295 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 296 | .. attr:: review |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 297 | |
| 298 | This takes a list of code reviews. If a code review matches the |
| 299 | provided criteria the pull request can not be entered into the |
James E. Blair | 91fe483 | 2017-07-28 17:28:26 -0700 | [diff] [blame] | 300 | pipeline. It follows the same syntax as |
| 301 | :attr:`pipeline.require.<github source>.review` |