blob: 8dd7764148b128c92c03672228133a6d59145aad [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
21To configure a project's `webhook events <https://developer.github.com/webhooks/creating/>`_:
22
23* Set *Payload URL* to ``http://<zuul-hostname>/connection/<connection-name>/payload``.
24
25* Set *Content Type* to ``application/json``.
James E. Blaireff5a9d2017-06-20 00:00:37 -070026
27Select *Events* you are interested in. See below for the supported events.
28
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000029You will also need to have a GitHub user created for your zuul:
30
31* Zuul public key needs to be added to the GitHub account
32
33* A api_token needs to be created too, see this `article <See https://help.github.com/articles/creating-an-access-token-for-command-line-use/>`_
34
35Then in the zuul.conf, set webhook_token and api_token.
36
37Application
38...........
39
40To create a `GitHub application <https://developer.github.com/apps/building-integrations/setting-up-and-registering-github-apps/registering-github-apps/>`_:
41
42* Go to your organization settings page to create the application, e.g.: https://github.com/organizations/my-org/settings/apps/new
43
44* Set GitHub App name to "my-org-zuul"
45
46* Set Setup URL to your setup documentation, when user install the application they are redirected to this url
47
48* Set Webhook URL to ``http://<zuul-hostname>/connection/<connection-name>/payload``.
49
50* Create a Webhook secret
51
52* Set permissions:
53
54 * Commit statuses: Read & Write
55
56 * Issues: Read & Write
57
58 * Pull requests: Read & Write
59
60 * Repository contents: Read & Write (write to let zuul merge change)
61
62* Set events subscription:
63
64 * Label
65
66 * Status
67
68 * Issue comment
69
70 * Issues
71
72 * Pull request
73
74 * Pull request review
75
76 * Pull request review comment
77
78 * Commit comment
79
80 * Create
81
82 * Push
83
84 * Release
85
86* Set Where can this GitHub App be installed to "Any account"
87
88* Create the App
89
90* Generate a Private key in the app settings page
91
92Then in the zuul.conf, set webhook_token, app_id and app_key.
93After restarting zuul-scheduler, verify in the 'Advanced' tab that the
94Ping payload works (green tick and 200 response)
95
96Users can now install the application using its public page, e.g.: https://github.com/apps/my-org-zuul
97
98
James E. Blaireff5a9d2017-06-20 00:00:37 -070099Connection Configuration
100------------------------
101
Monty Taylorae1f03a2017-07-27 14:43:32 -0500102There are two forms of operation. Either the Zuul installation can be
103configured as a `Github App`_ or it can be configured as a Webhook.
104
105If the `Github App`_ approach is taken, the config settings ``app_id`` and
106``app_key`` are required. If the Webhook approach is taken, the ``api_token``
107setting is required.
108
James E. Blair02157ad2017-08-03 17:34:22 -0700109The supported options in ``zuul.conf`` connections are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700110
James E. Blair02157ad2017-08-03 17:34:22 -0700111.. attr:: <github connection>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700112
James E. Blair02157ad2017-08-03 17:34:22 -0700113 .. attr:: driver
114 :required:
Monty Taylorae1f03a2017-07-27 14:43:32 -0500115
James E. Blair02157ad2017-08-03 17:34:22 -0700116 .. value:: github
Monty Taylorae1f03a2017-07-27 14:43:32 -0500117
James E. Blair02157ad2017-08-03 17:34:22 -0700118 The connection must set ``driver=github`` for GitHub connections.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700119
James E. Blair02157ad2017-08-03 17:34:22 -0700120 .. attr:: app_id
James E. Blaireff5a9d2017-06-20 00:00:37 -0700121
James E. Blair02157ad2017-08-03 17:34:22 -0700122 App ID if you are using a *GitHub App*. Can be found under the
123 **Public Link** on the right hand side labeled **ID**.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700124
James E. Blair02157ad2017-08-03 17:34:22 -0700125 .. attr:: app_key
James E. Blaireff5a9d2017-06-20 00:00:37 -0700126
James E. Blair02157ad2017-08-03 17:34:22 -0700127 Path to a file containing the secret key Zuul will use to create
128 tokens for the API interactions. In Github this is known as
129 **Private key** and must be collected when generated.
James E. Blair4d5dd252017-06-23 21:40:56 +0100130
James E. Blair02157ad2017-08-03 17:34:22 -0700131 .. attr:: api_token
132
133 API token for accessing GitHub if Zuul is configured with
134 Webhooks. See `Creating an access token for command-line use
135 <https://help.github.com/articles/creating-an-access-token-for-command-line-use/>`_.
136
137 .. attr:: webhook_token
138
139 Required token for validating the webhook event payloads. In
140 the GitHub App Configuration page, this is called **Webhook
141 secret**. See `Securing your webhooks
142 <https://developer.github.com/webhooks/securing/>`_.
143
144 .. attr:: sshkey
145 :default: ~/.ssh/id_rsa
146
147 Path to SSH key to use when cloning github repositories.
148
149 .. attr:: server
150 :default: github.com
151
152 Hostname of the github install (such as a GitHub Enterprise).
153
154 .. attr:: canonical_hostname
155
156 The canonical hostname associated with the git repos on the
157 GitHub server. Defaults to the value of :attr:`<github
158 connection>.server`. This is used to identify projects from
159 this connection by name and in preparing repos on the filesystem
160 for use by jobs. Note that Zuul will still only communicate
161 with the GitHub server identified by **server**; this option is
162 useful if users customarily use a different hostname to clone or
163 pull git repos so that when Zuul places them in the job's
164 working directory, they appear under this directory name.
165
166 .. attr:: verify_ssl
167 :default: true
168
169 Enable or disable ssl verification for GitHub Enterprise. This
170 is useful for a connection to a test installation.
Tobias Henkel65e0e8c2017-08-01 13:44:33 +0200171
James E. Blaireff5a9d2017-06-20 00:00:37 -0700172Trigger Configuration
173---------------------
174GitHub webhook events can be configured as triggers.
175
James E. Blair02157ad2017-08-03 17:34:22 -0700176A connection name with the GitHub driver can take multiple events with
177the following options.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700178
James E. Blair02157ad2017-08-03 17:34:22 -0700179.. attr:: pipeline.trigger.<github source>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700180
James E. Blair02157ad2017-08-03 17:34:22 -0700181 The dictionary passed to the GitHub pipeline ``trigger`` attribute
182 supports the following attributes:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700183
James E. Blair02157ad2017-08-03 17:34:22 -0700184 .. attr:: event
185 :required:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700186
James E. Blair02157ad2017-08-03 17:34:22 -0700187 The event from github. Supported events are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700188
James E. Blair02157ad2017-08-03 17:34:22 -0700189 .. value:: pull_request
James E. Blaireff5a9d2017-06-20 00:00:37 -0700190
James E. Blair02157ad2017-08-03 17:34:22 -0700191 .. value:: pull_request_review
James E. Blaireff5a9d2017-06-20 00:00:37 -0700192
James E. Blair02157ad2017-08-03 17:34:22 -0700193 .. value:: push
James E. Blaireff5a9d2017-06-20 00:00:37 -0700194
James E. Blair02157ad2017-08-03 17:34:22 -0700195 .. attr:: action
James E. Blaireff5a9d2017-06-20 00:00:37 -0700196
James E. Blair02157ad2017-08-03 17:34:22 -0700197 A :value:`pipeline.trigger.<github source>.event.pull_request`
198 event will have associated action(s) to trigger from. The
199 supported actions are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700200
James E. Blair02157ad2017-08-03 17:34:22 -0700201 .. value:: opened
James E. Blaireff5a9d2017-06-20 00:00:37 -0700202
James E. Blair02157ad2017-08-03 17:34:22 -0700203 Pull request opened.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700204
James E. Blair02157ad2017-08-03 17:34:22 -0700205 .. value:: changed
James E. Blaireff5a9d2017-06-20 00:00:37 -0700206
James E. Blair02157ad2017-08-03 17:34:22 -0700207 Pull request synchronized.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700208
James E. Blair02157ad2017-08-03 17:34:22 -0700209 .. value:: closed
James E. Blaireff5a9d2017-06-20 00:00:37 -0700210
James E. Blair02157ad2017-08-03 17:34:22 -0700211 Pull request closed.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700212
James E. Blair02157ad2017-08-03 17:34:22 -0700213 .. value:: reopened
James E. Blaireff5a9d2017-06-20 00:00:37 -0700214
James E. Blair02157ad2017-08-03 17:34:22 -0700215 Pull request reopened.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700216
James E. Blair02157ad2017-08-03 17:34:22 -0700217 .. value:: comment
James E. Blaireff5a9d2017-06-20 00:00:37 -0700218
James E. Blair02157ad2017-08-03 17:34:22 -0700219 Comment added to pull request.
220
221 .. value:: labeled
222
223 Label added to pull request.
224
225 .. value:: unlabeled
226
227 Label removed from pull request.
228
229 .. value:: status
230
231 Status set on commit.
232
233 A :value:`pipeline.trigger.<github
234 source>.event.pull_request_review` event will have associated
235 action(s) to trigger from. The supported actions are:
236
237 .. value:: submitted
238
239 Pull request review added.
240
241 .. value:: dismissed
242
243 Pull request review removed.
244
245 .. attr:: branch
246
247 The branch associated with the event. Example: ``master``. This
248 field is treated as a regular expression, and multiple branches
249 may be listed. Used for ``pull_request`` and
250 ``pull_request_review`` events.
251
252 .. attr:: comment
253
254 This is only used for ``pull_request`` ``comment`` actions. It
255 accepts a list of regexes that are searched for in the comment
256 string. If any of these regexes matches a portion of the comment
257 string the trigger is matched. ``comment: retrigger`` will
258 match when comments containing 'retrigger' somewhere in the
259 comment text are added to a pull request.
260
261 .. attr:: label
262
263 This is only used for ``labeled`` and ``unlabeled``
264 ``pull_request`` actions. It accepts a list of strings each of
265 which matches the label name in the event literally. ``label:
266 recheck`` will match a ``labeled`` action when pull request is
267 labeled with a ``recheck`` label. ``label: 'do not test'`` will
268 match a ``unlabeled`` action when a label with name ``do not
269 test`` is removed from the pull request.
270
271 .. attr:: state
272
273 This is only used for ``pull_request_review`` events. It
274 accepts a list of strings each of which is matched to the review
275 state, which can be one of ``approved``, ``comment``, or
276 ``request_changes``.
277
278 .. attr:: status
279
280 This is used for ``pull-request`` and ``status`` actions. It
281 accepts a list of strings each of which matches the user setting
282 the status, the status context, and the status itself in the
283 format of ``user:context:status``. For example,
284 ``zuul_github_ci_bot:check_pipeline:success``.
285
286 .. attr:: ref
287
288 This is only used for ``push`` events. This field is treated as
289 a regular expression and multiple refs may be listed. GitHub
290 always sends full ref name, eg. ``refs/tags/bar`` and this
291 string is matched against the regular expression.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700292
293Reporter Configuration
294----------------------
295Zuul reports back to GitHub via GitHub API. Available reports include a PR
296comment containing the build results, a commit status on start, success and
297failure, an issue label addition/removal on the PR, and a merge of the PR
298itself. Status name, description, and context is taken from the pipeline.
299
James E. Blair02157ad2017-08-03 17:34:22 -0700300.. attr:: pipeline.<reporter>.<github source>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700301
James E. Blair02157ad2017-08-03 17:34:22 -0700302 To report to GitHub, the dictionaries passed to any of the pipeline
303 :ref:`reporter<reporters>` attributes support the following
304 attributes:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700305
James E. Blair02157ad2017-08-03 17:34:22 -0700306 .. attr:: status
James E. Blaireff5a9d2017-06-20 00:00:37 -0700307
James E. Blair02157ad2017-08-03 17:34:22 -0700308 String value (``pending``, ``success``, ``failure``) that the
309 reporter should set as the commit status on github.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700310
James E. Blair02157ad2017-08-03 17:34:22 -0700311 .. TODO support role markup in :default: so we can xref
312 :attr:`webapp.status_url` below
James E. Blaireff5a9d2017-06-20 00:00:37 -0700313
James E. Blair02157ad2017-08-03 17:34:22 -0700314 .. attr:: status-url
315 :default: webapp.status_url or the empty string
James E. Blaireff5a9d2017-06-20 00:00:37 -0700316
James E. Blair02157ad2017-08-03 17:34:22 -0700317 String value for a link url to set in the github
318 status. Defaults to the zuul server status_url, or the empty
319 string if that is unset.
320
321 .. attr:: comment
322 :default: true
323
324 Boolean value that determines if the reporter should add a
325 comment to the pipeline status to the github pull request. Only
326 used for Pull Request based items.
327
328 .. attr:: merge
329 :default: false
330
331 Boolean value that determines if the reporter should merge the
332 pull reqeust. Only used for Pull Request based items.
333
334 .. attr:: label
335
336 List of strings each representing an exact label name which
337 should be added to the pull request by reporter. Only used for
338 Pull Request based items.
339
340 .. attr:: unlabel
341
342 List of strings each representing an exact label name which
343 should be removed from the pull request by reporter. Only used
344 for Pull Request based items.
Monty Taylorae1f03a2017-07-27 14:43:32 -0500345
346.. _Github App: https://developer.github.com/apps/
James E. Blaird134c6d2017-07-26 16:09:34 -0700347
348Requirements Configuration
349--------------------------
350
James E. Blair32c52482017-07-29 07:49:03 -0700351As described in :attr:`pipeline.require` and :attr:`pipeline.reject`,
352pipelines may specify that items meet certain conditions in order to
353be enqueued into the pipeline. These conditions vary according to the
354source of the project in question. To supply requirements for changes
James E. Blair02157ad2017-08-03 17:34:22 -0700355from a GitHub source named ``my-github``, create a congfiguration such
James E. Blair32c52482017-07-29 07:49:03 -0700356as the following::
James E. Blaird134c6d2017-07-26 16:09:34 -0700357
358 pipeline:
359 require:
360 my-github:
361 review:
362 - type: approval
363
364This indicates that changes originating from the GitHub connection
James E. Blair02157ad2017-08-03 17:34:22 -0700365named ``my-github`` must have an approved code review in order to be
James E. Blaird134c6d2017-07-26 16:09:34 -0700366enqueued into the pipeline.
367
James E. Blair94375912017-07-28 17:20:27 -0700368.. attr:: pipeline.require.<github source>
James E. Blaird134c6d2017-07-26 16:09:34 -0700369
370 The dictionary passed to the GitHub pipeline `require` attribute
371 supports the following attributes:
372
James E. Blair94375912017-07-28 17:20:27 -0700373 .. attr:: review
James E. Blaird134c6d2017-07-26 16:09:34 -0700374
375 This requires that a certain kind of code review be present for
376 the pull request (it could be added by the event in question).
377 It takes several sub-parameters, all of which are optional and
378 are combined together so that there must be a code review
379 matching all specified requirements.
380
James E. Blair94375912017-07-28 17:20:27 -0700381 .. attr:: username
James E. Blaird134c6d2017-07-26 16:09:34 -0700382
383 If present, a code review from this username is required. It
384 is treated as a regular expression.
385
James E. Blair94375912017-07-28 17:20:27 -0700386 .. attr:: email
James E. Blaird134c6d2017-07-26 16:09:34 -0700387
388 If present, a code review with this email address is
389 required. It is treated as a regular expression.
390
James E. Blair94375912017-07-28 17:20:27 -0700391 .. attr:: older-than
James E. Blaird134c6d2017-07-26 16:09:34 -0700392
393 If present, the code review must be older than this amount of
394 time to match. Provide a time interval as a number with a
395 suffix of "w" (weeks), "d" (days), "h" (hours), "m"
396 (minutes), "s" (seconds). Example ``48h`` or ``2d``.
397
James E. Blair94375912017-07-28 17:20:27 -0700398 .. attr:: newer-than
James E. Blaird134c6d2017-07-26 16:09:34 -0700399
400 If present, the code review must be newer than this amount of
401 time to match. Same format as "older-than".
402
James E. Blair94375912017-07-28 17:20:27 -0700403 .. attr:: type
James E. Blaird134c6d2017-07-26 16:09:34 -0700404
405 If present, the code review must match this type (or types).
406
407 .. TODO: what types are valid?
408
James E. Blair94375912017-07-28 17:20:27 -0700409 .. attr:: permission
James E. Blaird134c6d2017-07-26 16:09:34 -0700410
411 If present, the author of the code review must have this
412 permission (or permissions). The available values are
413 ``read``, ``write``, and ``admin``.
414
James E. Blair94375912017-07-28 17:20:27 -0700415 .. attr:: open
James E. Blaird134c6d2017-07-26 16:09:34 -0700416
417 A boolean value (``true`` or ``false``) that indicates whether
418 the change must be open or closed in order to be enqueued.
419
James E. Blair94375912017-07-28 17:20:27 -0700420 .. attr:: current-patchset
James E. Blaird134c6d2017-07-26 16:09:34 -0700421
422 A boolean value (``true`` or ``false``) that indicates whether
423 the item must be associated with the latest commit in the pull
424 request in order to be enqueued.
425
426 .. TODO: this could probably be expanded upon -- under what
427 circumstances might this happen with github
428
James E. Blair94375912017-07-28 17:20:27 -0700429 .. attr:: status
James E. Blaird134c6d2017-07-26 16:09:34 -0700430
431 A string value that corresponds with the status of the pull
432 request. The syntax is ``user:status:value``.
433
James E. Blair94375912017-07-28 17:20:27 -0700434 .. attr:: label
James E. Blaird134c6d2017-07-26 16:09:34 -0700435
436 A string value indicating that the pull request must have the
437 indicated label (or labels).
438
James E. Blair94375912017-07-28 17:20:27 -0700439.. attr:: pipeline.reject.<github source>
James E. Blaird134c6d2017-07-26 16:09:34 -0700440
441 The `reject` attribute is the mirror of the `require` attribute. It
442 also accepts a dictionary under the connection name. This
443 dictionary supports the following attributes:
444
James E. Blair94375912017-07-28 17:20:27 -0700445 .. attr:: review
James E. Blaird134c6d2017-07-26 16:09:34 -0700446
447 This takes a list of code reviews. If a code review matches the
448 provided criteria the pull request can not be entered into the
James E. Blair91fe4832017-07-28 17:28:26 -0700449 pipeline. It follows the same syntax as
450 :attr:`pipeline.require.<github source>.review`