blob: 4f46af6941025c1ba4ac36f3850c2c8a2cf1c2ae [file] [log] [blame]
James E. Blaireff5a9d2017-06-20 00:00:37 -07001:title: GitHub Driver
2
3GitHub
4======
5
6The GitHub driver supports sources, triggers, and reporters. It can
7interact with the public GitHub service as well as site-local
8installations of GitHub enterprise.
9
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000010Configure GitHub
11----------------
James E. Blaireff5a9d2017-06-20 00:00:37 -070012
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000013There are two options currently available. GitHub's project owner can either
14manually setup web-hook or install a GitHub Application. In the first case,
15the project's owner needs to know the zuul endpoint and the webhook secrets.
James E. Blaireff5a9d2017-06-20 00:00:37 -070016
James E. Blaireff5a9d2017-06-20 00:00:37 -070017
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000018Web-Hook
19........
20
Joshua Heskethabac0d02017-12-11 13:35:56 +110021To configure a project's `webhook events
22<https://developer.github.com/webhooks/creating/>`_:
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000023
Joshua Heskethabac0d02017-12-11 13:35:56 +110024* Set *Payload URL* to
25 ``http://<zuul-hostname>/connection/<connection-name>/payload``.
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000026
27* Set *Content Type* to ``application/json``.
James E. Blaireff5a9d2017-06-20 00:00:37 -070028
29Select *Events* you are interested in. See below for the supported events.
30
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000031You will also need to have a GitHub user created for your zuul:
32
33* Zuul public key needs to be added to the GitHub account
34
Joshua Heskethabac0d02017-12-11 13:35:56 +110035* A api_token needs to be created too, see this `article
36 <https://help.github.com/articles/creating-an-access-token-for-command-line-use/>`_
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000037
38Then in the zuul.conf, set webhook_token and api_token.
39
40Application
41...........
42
Joshua Heskethabac0d02017-12-11 13:35:56 +110043To create a `GitHub application
44<https://developer.github.com/apps/building-integrations/setting-up-and-registering-github-apps/registering-github-apps/>`_:
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000045
Joshua Heskethabac0d02017-12-11 13:35:56 +110046* Go to your organization settings page to create the application, e.g.:
47 https://github.com/organizations/my-org/settings/apps/new
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000048
49* Set GitHub App name to "my-org-zuul"
50
Joshua Heskethabac0d02017-12-11 13:35:56 +110051* Set Setup URL to your setup documentation, when user install the application
52 they are redirected to this url
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000053
Joshua Heskethabac0d02017-12-11 13:35:56 +110054* Set Webhook URL to
55 ``http://<zuul-hostname>/connection/<connection-name>/payload``.
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000056
57* Create a Webhook secret
58
59* Set permissions:
60
61 * Commit statuses: Read & Write
62
63 * Issues: Read & Write
64
65 * Pull requests: Read & Write
66
67 * Repository contents: Read & Write (write to let zuul merge change)
68
69* Set events subscription:
70
71 * Label
72
73 * Status
74
75 * Issue comment
76
77 * Issues
78
79 * Pull request
80
81 * Pull request review
82
83 * Pull request review comment
84
85 * Commit comment
86
87 * Create
88
89 * Push
90
91 * Release
92
93* Set Where can this GitHub App be installed to "Any account"
94
95* Create the App
96
97* Generate a Private key in the app settings page
98
99Then in the zuul.conf, set webhook_token, app_id and app_key.
100After restarting zuul-scheduler, verify in the 'Advanced' tab that the
101Ping payload works (green tick and 200 response)
102
Joshua Heskethabac0d02017-12-11 13:35:56 +1100103Users can now install the application using its public page, e.g.:
104https://github.com/apps/my-org-zuul
Tristan Cacqueray9d83c612017-11-23 02:09:53 +0000105
106
James E. Blaireff5a9d2017-06-20 00:00:37 -0700107Connection Configuration
108------------------------
109
Monty Taylorae1f03a2017-07-27 14:43:32 -0500110There are two forms of operation. Either the Zuul installation can be
111configured as a `Github App`_ or it can be configured as a Webhook.
112
113If the `Github App`_ approach is taken, the config settings ``app_id`` and
114``app_key`` are required. If the Webhook approach is taken, the ``api_token``
115setting is required.
116
James E. Blair02157ad2017-08-03 17:34:22 -0700117The supported options in ``zuul.conf`` connections are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700118
James E. Blair02157ad2017-08-03 17:34:22 -0700119.. attr:: <github connection>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700120
James E. Blair02157ad2017-08-03 17:34:22 -0700121 .. attr:: driver
122 :required:
Monty Taylorae1f03a2017-07-27 14:43:32 -0500123
James E. Blair02157ad2017-08-03 17:34:22 -0700124 .. value:: github
Monty Taylorae1f03a2017-07-27 14:43:32 -0500125
James E. Blair02157ad2017-08-03 17:34:22 -0700126 The connection must set ``driver=github`` for GitHub connections.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700127
James E. Blair02157ad2017-08-03 17:34:22 -0700128 .. attr:: app_id
James E. Blaireff5a9d2017-06-20 00:00:37 -0700129
James E. Blair02157ad2017-08-03 17:34:22 -0700130 App ID if you are using a *GitHub App*. Can be found under the
131 **Public Link** on the right hand side labeled **ID**.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700132
James E. Blair02157ad2017-08-03 17:34:22 -0700133 .. attr:: app_key
James E. Blaireff5a9d2017-06-20 00:00:37 -0700134
James E. Blair02157ad2017-08-03 17:34:22 -0700135 Path to a file containing the secret key Zuul will use to create
136 tokens for the API interactions. In Github this is known as
137 **Private key** and must be collected when generated.
James E. Blair4d5dd252017-06-23 21:40:56 +0100138
James E. Blair02157ad2017-08-03 17:34:22 -0700139 .. attr:: api_token
140
141 API token for accessing GitHub if Zuul is configured with
142 Webhooks. See `Creating an access token for command-line use
143 <https://help.github.com/articles/creating-an-access-token-for-command-line-use/>`_.
144
145 .. attr:: webhook_token
146
147 Required token for validating the webhook event payloads. In
148 the GitHub App Configuration page, this is called **Webhook
149 secret**. See `Securing your webhooks
150 <https://developer.github.com/webhooks/securing/>`_.
151
152 .. attr:: sshkey
153 :default: ~/.ssh/id_rsa
154
155 Path to SSH key to use when cloning github repositories.
156
157 .. attr:: server
158 :default: github.com
159
160 Hostname of the github install (such as a GitHub Enterprise).
161
162 .. attr:: canonical_hostname
163
164 The canonical hostname associated with the git repos on the
165 GitHub server. Defaults to the value of :attr:`<github
166 connection>.server`. This is used to identify projects from
167 this connection by name and in preparing repos on the filesystem
168 for use by jobs. Note that Zuul will still only communicate
169 with the GitHub server identified by **server**; this option is
170 useful if users customarily use a different hostname to clone or
171 pull git repos so that when Zuul places them in the job's
172 working directory, they appear under this directory name.
173
174 .. attr:: verify_ssl
175 :default: true
176
177 Enable or disable ssl verification for GitHub Enterprise. This
178 is useful for a connection to a test installation.
Tobias Henkel65e0e8c2017-08-01 13:44:33 +0200179
James E. Blaireff5a9d2017-06-20 00:00:37 -0700180Trigger Configuration
181---------------------
182GitHub webhook events can be configured as triggers.
183
James E. Blair02157ad2017-08-03 17:34:22 -0700184A connection name with the GitHub driver can take multiple events with
185the following options.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700186
James E. Blair02157ad2017-08-03 17:34:22 -0700187.. attr:: pipeline.trigger.<github source>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700188
James E. Blair02157ad2017-08-03 17:34:22 -0700189 The dictionary passed to the GitHub pipeline ``trigger`` attribute
190 supports the following attributes:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700191
James E. Blair02157ad2017-08-03 17:34:22 -0700192 .. attr:: event
193 :required:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700194
James E. Blair02157ad2017-08-03 17:34:22 -0700195 The event from github. Supported events are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700196
James E. Blair02157ad2017-08-03 17:34:22 -0700197 .. value:: pull_request
James E. Blaireff5a9d2017-06-20 00:00:37 -0700198
James E. Blair02157ad2017-08-03 17:34:22 -0700199 .. value:: pull_request_review
James E. Blaireff5a9d2017-06-20 00:00:37 -0700200
James E. Blair02157ad2017-08-03 17:34:22 -0700201 .. value:: push
James E. Blaireff5a9d2017-06-20 00:00:37 -0700202
James E. Blair02157ad2017-08-03 17:34:22 -0700203 .. attr:: action
James E. Blaireff5a9d2017-06-20 00:00:37 -0700204
James E. Blair02157ad2017-08-03 17:34:22 -0700205 A :value:`pipeline.trigger.<github source>.event.pull_request`
206 event will have associated action(s) to trigger from. The
207 supported actions are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700208
James E. Blair02157ad2017-08-03 17:34:22 -0700209 .. value:: opened
James E. Blaireff5a9d2017-06-20 00:00:37 -0700210
James E. Blair02157ad2017-08-03 17:34:22 -0700211 Pull request opened.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700212
James E. Blair02157ad2017-08-03 17:34:22 -0700213 .. value:: changed
James E. Blaireff5a9d2017-06-20 00:00:37 -0700214
James E. Blair02157ad2017-08-03 17:34:22 -0700215 Pull request synchronized.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700216
James E. Blair02157ad2017-08-03 17:34:22 -0700217 .. value:: closed
James E. Blaireff5a9d2017-06-20 00:00:37 -0700218
James E. Blair02157ad2017-08-03 17:34:22 -0700219 Pull request closed.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700220
James E. Blair02157ad2017-08-03 17:34:22 -0700221 .. value:: reopened
James E. Blaireff5a9d2017-06-20 00:00:37 -0700222
James E. Blair02157ad2017-08-03 17:34:22 -0700223 Pull request reopened.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700224
James E. Blair02157ad2017-08-03 17:34:22 -0700225 .. value:: comment
James E. Blaireff5a9d2017-06-20 00:00:37 -0700226
James E. Blair02157ad2017-08-03 17:34:22 -0700227 Comment added to pull request.
228
229 .. value:: labeled
230
231 Label added to pull request.
232
233 .. value:: unlabeled
234
235 Label removed from pull request.
236
237 .. value:: status
238
239 Status set on commit.
240
241 A :value:`pipeline.trigger.<github
242 source>.event.pull_request_review` event will have associated
243 action(s) to trigger from. The supported actions are:
244
245 .. value:: submitted
246
247 Pull request review added.
248
249 .. value:: dismissed
250
251 Pull request review removed.
252
253 .. attr:: branch
254
255 The branch associated with the event. Example: ``master``. This
256 field is treated as a regular expression, and multiple branches
257 may be listed. Used for ``pull_request`` and
258 ``pull_request_review`` events.
259
260 .. attr:: comment
261
262 This is only used for ``pull_request`` ``comment`` actions. It
263 accepts a list of regexes that are searched for in the comment
264 string. If any of these regexes matches a portion of the comment
265 string the trigger is matched. ``comment: retrigger`` will
266 match when comments containing 'retrigger' somewhere in the
267 comment text are added to a pull request.
268
269 .. attr:: label
270
271 This is only used for ``labeled`` and ``unlabeled``
272 ``pull_request`` actions. It accepts a list of strings each of
273 which matches the label name in the event literally. ``label:
274 recheck`` will match a ``labeled`` action when pull request is
275 labeled with a ``recheck`` label. ``label: 'do not test'`` will
276 match a ``unlabeled`` action when a label with name ``do not
277 test`` is removed from the pull request.
278
279 .. attr:: state
280
281 This is only used for ``pull_request_review`` events. It
282 accepts a list of strings each of which is matched to the review
283 state, which can be one of ``approved``, ``comment``, or
284 ``request_changes``.
285
286 .. attr:: status
287
288 This is used for ``pull-request`` and ``status`` actions. It
289 accepts a list of strings each of which matches the user setting
290 the status, the status context, and the status itself in the
291 format of ``user:context:status``. For example,
292 ``zuul_github_ci_bot:check_pipeline:success``.
293
294 .. attr:: ref
295
296 This is only used for ``push`` events. This field is treated as
297 a regular expression and multiple refs may be listed. GitHub
298 always sends full ref name, eg. ``refs/tags/bar`` and this
299 string is matched against the regular expression.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700300
301Reporter Configuration
302----------------------
303Zuul reports back to GitHub via GitHub API. Available reports include a PR
304comment containing the build results, a commit status on start, success and
305failure, an issue label addition/removal on the PR, and a merge of the PR
306itself. Status name, description, and context is taken from the pipeline.
307
James E. Blair02157ad2017-08-03 17:34:22 -0700308.. attr:: pipeline.<reporter>.<github source>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700309
James E. Blair02157ad2017-08-03 17:34:22 -0700310 To report to GitHub, the dictionaries passed to any of the pipeline
311 :ref:`reporter<reporters>` attributes support the following
312 attributes:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700313
James E. Blair02157ad2017-08-03 17:34:22 -0700314 .. attr:: status
James E. Blaireff5a9d2017-06-20 00:00:37 -0700315
James E. Blair02157ad2017-08-03 17:34:22 -0700316 String value (``pending``, ``success``, ``failure``) that the
317 reporter should set as the commit status on github.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700318
James E. Blair02157ad2017-08-03 17:34:22 -0700319 .. TODO support role markup in :default: so we can xref
320 :attr:`webapp.status_url` below
James E. Blaireff5a9d2017-06-20 00:00:37 -0700321
James E. Blair02157ad2017-08-03 17:34:22 -0700322 .. attr:: status-url
323 :default: webapp.status_url or the empty string
James E. Blaireff5a9d2017-06-20 00:00:37 -0700324
James E. Blair02157ad2017-08-03 17:34:22 -0700325 String value for a link url to set in the github
326 status. Defaults to the zuul server status_url, or the empty
327 string if that is unset.
328
329 .. attr:: comment
330 :default: true
331
332 Boolean value that determines if the reporter should add a
333 comment to the pipeline status to the github pull request. Only
334 used for Pull Request based items.
335
336 .. attr:: merge
337 :default: false
338
339 Boolean value that determines if the reporter should merge the
340 pull reqeust. Only used for Pull Request based items.
341
342 .. attr:: label
343
344 List of strings each representing an exact label name which
345 should be added to the pull request by reporter. Only used for
346 Pull Request based items.
347
348 .. attr:: unlabel
349
350 List of strings each representing an exact label name which
351 should be removed from the pull request by reporter. Only used
352 for Pull Request based items.
Monty Taylorae1f03a2017-07-27 14:43:32 -0500353
354.. _Github App: https://developer.github.com/apps/
James E. Blaird134c6d2017-07-26 16:09:34 -0700355
356Requirements Configuration
357--------------------------
358
James E. Blair32c52482017-07-29 07:49:03 -0700359As described in :attr:`pipeline.require` and :attr:`pipeline.reject`,
360pipelines may specify that items meet certain conditions in order to
361be enqueued into the pipeline. These conditions vary according to the
362source of the project in question. To supply requirements for changes
James E. Blair02157ad2017-08-03 17:34:22 -0700363from a GitHub source named ``my-github``, create a congfiguration such
James E. Blair32c52482017-07-29 07:49:03 -0700364as the following::
James E. Blaird134c6d2017-07-26 16:09:34 -0700365
366 pipeline:
367 require:
368 my-github:
369 review:
370 - type: approval
371
372This indicates that changes originating from the GitHub connection
James E. Blair02157ad2017-08-03 17:34:22 -0700373named ``my-github`` must have an approved code review in order to be
James E. Blaird134c6d2017-07-26 16:09:34 -0700374enqueued into the pipeline.
375
James E. Blair94375912017-07-28 17:20:27 -0700376.. attr:: pipeline.require.<github source>
James E. Blaird134c6d2017-07-26 16:09:34 -0700377
378 The dictionary passed to the GitHub pipeline `require` attribute
379 supports the following attributes:
380
James E. Blair94375912017-07-28 17:20:27 -0700381 .. attr:: review
James E. Blaird134c6d2017-07-26 16:09:34 -0700382
383 This requires that a certain kind of code review be present for
384 the pull request (it could be added by the event in question).
385 It takes several sub-parameters, all of which are optional and
386 are combined together so that there must be a code review
387 matching all specified requirements.
388
James E. Blair94375912017-07-28 17:20:27 -0700389 .. attr:: username
James E. Blaird134c6d2017-07-26 16:09:34 -0700390
391 If present, a code review from this username is required. It
392 is treated as a regular expression.
393
James E. Blair94375912017-07-28 17:20:27 -0700394 .. attr:: email
James E. Blaird134c6d2017-07-26 16:09:34 -0700395
396 If present, a code review with this email address is
397 required. It is treated as a regular expression.
398
James E. Blair94375912017-07-28 17:20:27 -0700399 .. attr:: older-than
James E. Blaird134c6d2017-07-26 16:09:34 -0700400
401 If present, the code review must be older than this amount of
402 time to match. Provide a time interval as a number with a
403 suffix of "w" (weeks), "d" (days), "h" (hours), "m"
404 (minutes), "s" (seconds). Example ``48h`` or ``2d``.
405
James E. Blair94375912017-07-28 17:20:27 -0700406 .. attr:: newer-than
James E. Blaird134c6d2017-07-26 16:09:34 -0700407
408 If present, the code review must be newer than this amount of
409 time to match. Same format as "older-than".
410
James E. Blair94375912017-07-28 17:20:27 -0700411 .. attr:: type
James E. Blaird134c6d2017-07-26 16:09:34 -0700412
413 If present, the code review must match this type (or types).
414
415 .. TODO: what types are valid?
416
James E. Blair94375912017-07-28 17:20:27 -0700417 .. attr:: permission
James E. Blaird134c6d2017-07-26 16:09:34 -0700418
419 If present, the author of the code review must have this
420 permission (or permissions). The available values are
421 ``read``, ``write``, and ``admin``.
422
James E. Blair94375912017-07-28 17:20:27 -0700423 .. attr:: open
James E. Blaird134c6d2017-07-26 16:09:34 -0700424
425 A boolean value (``true`` or ``false``) that indicates whether
426 the change must be open or closed in order to be enqueued.
427
James E. Blair94375912017-07-28 17:20:27 -0700428 .. attr:: current-patchset
James E. Blaird134c6d2017-07-26 16:09:34 -0700429
430 A boolean value (``true`` or ``false``) that indicates whether
431 the item must be associated with the latest commit in the pull
432 request in order to be enqueued.
433
434 .. TODO: this could probably be expanded upon -- under what
435 circumstances might this happen with github
436
James E. Blair94375912017-07-28 17:20:27 -0700437 .. attr:: status
James E. Blaird134c6d2017-07-26 16:09:34 -0700438
439 A string value that corresponds with the status of the pull
440 request. The syntax is ``user:status:value``.
441
James E. Blair94375912017-07-28 17:20:27 -0700442 .. attr:: label
James E. Blaird134c6d2017-07-26 16:09:34 -0700443
444 A string value indicating that the pull request must have the
445 indicated label (or labels).
446
James E. Blair94375912017-07-28 17:20:27 -0700447.. attr:: pipeline.reject.<github source>
James E. Blaird134c6d2017-07-26 16:09:34 -0700448
449 The `reject` attribute is the mirror of the `require` attribute. It
450 also accepts a dictionary under the connection name. This
451 dictionary supports the following attributes:
452
James E. Blair94375912017-07-28 17:20:27 -0700453 .. attr:: review
James E. Blaird134c6d2017-07-26 16:09:34 -0700454
455 This takes a list of code reviews. If a code review matches the
456 provided criteria the pull request can not be entered into the
James E. Blair91fe4832017-07-28 17:28:26 -0700457 pipeline. It follows the same syntax as
458 :attr:`pipeline.require.<github source>.review`