blob: a89cfc6742c49c06351761d1134aac1606b44e49 [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
James E. Blairf09c2382018-02-08 16:50:31 -080043.. NOTE Duplicate content here and in zuul-from-scratch.rst. Keep them
44 in sync.
45
Joshua Heskethabac0d02017-12-11 13:35:56 +110046To create a `GitHub application
47<https://developer.github.com/apps/building-integrations/setting-up-and-registering-github-apps/registering-github-apps/>`_:
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000048
Joshua Heskethabac0d02017-12-11 13:35:56 +110049* Go to your organization settings page to create the application, e.g.:
50 https://github.com/organizations/my-org/settings/apps/new
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000051* Set GitHub App name to "my-org-zuul"
Joshua Heskethabac0d02017-12-11 13:35:56 +110052* Set Setup URL to your setup documentation, when user install the application
53 they are redirected to this url
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* Create a Webhook secret
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000057* Set permissions:
58
59 * Commit statuses: Read & Write
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000060 * Issues: Read & Write
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000061 * Pull requests: Read & Write
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000062 * Repository contents: Read & Write (write to let zuul merge change)
James E. Blairf09c2382018-02-08 16:50:31 -080063 * Repository administration: Read
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000064
65* Set events subscription:
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000066 * Label
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000067 * Status
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000068 * Issue comment
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000069 * Issues
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000070 * Pull request
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000071 * Pull request review
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000072 * Pull request review comment
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000073 * Commit comment
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000074 * Create
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000075 * Push
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000076 * Release
77
78* Set Where can this GitHub App be installed to "Any account"
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000079* Create the App
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000080* Generate a Private key in the app settings page
81
82Then in the zuul.conf, set webhook_token, app_id and app_key.
83After restarting zuul-scheduler, verify in the 'Advanced' tab that the
84Ping payload works (green tick and 200 response)
85
Joshua Heskethabac0d02017-12-11 13:35:56 +110086Users can now install the application using its public page, e.g.:
87https://github.com/apps/my-org-zuul
Tristan Cacqueray9d83c612017-11-23 02:09:53 +000088
89
James E. Blaireff5a9d2017-06-20 00:00:37 -070090Connection Configuration
91------------------------
92
Monty Taylorae1f03a2017-07-27 14:43:32 -050093There are two forms of operation. Either the Zuul installation can be
94configured as a `Github App`_ or it can be configured as a Webhook.
95
96If the `Github App`_ approach is taken, the config settings ``app_id`` and
97``app_key`` are required. If the Webhook approach is taken, the ``api_token``
98setting is required.
99
James E. Blair02157ad2017-08-03 17:34:22 -0700100The supported options in ``zuul.conf`` connections are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700101
James E. Blair02157ad2017-08-03 17:34:22 -0700102.. attr:: <github connection>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700103
James E. Blair02157ad2017-08-03 17:34:22 -0700104 .. attr:: driver
105 :required:
Monty Taylorae1f03a2017-07-27 14:43:32 -0500106
James E. Blair02157ad2017-08-03 17:34:22 -0700107 .. value:: github
Monty Taylorae1f03a2017-07-27 14:43:32 -0500108
James E. Blair02157ad2017-08-03 17:34:22 -0700109 The connection must set ``driver=github`` for GitHub connections.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700110
James E. Blair02157ad2017-08-03 17:34:22 -0700111 .. attr:: app_id
James E. Blaireff5a9d2017-06-20 00:00:37 -0700112
James E. Blair02157ad2017-08-03 17:34:22 -0700113 App ID if you are using a *GitHub App*. Can be found under the
114 **Public Link** on the right hand side labeled **ID**.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700115
James E. Blair02157ad2017-08-03 17:34:22 -0700116 .. attr:: app_key
James E. Blaireff5a9d2017-06-20 00:00:37 -0700117
James E. Blair02157ad2017-08-03 17:34:22 -0700118 Path to a file containing the secret key Zuul will use to create
119 tokens for the API interactions. In Github this is known as
120 **Private key** and must be collected when generated.
James E. Blair4d5dd252017-06-23 21:40:56 +0100121
James E. Blair02157ad2017-08-03 17:34:22 -0700122 .. attr:: api_token
123
124 API token for accessing GitHub if Zuul is configured with
125 Webhooks. See `Creating an access token for command-line use
126 <https://help.github.com/articles/creating-an-access-token-for-command-line-use/>`_.
127
128 .. attr:: webhook_token
129
130 Required token for validating the webhook event payloads. In
131 the GitHub App Configuration page, this is called **Webhook
132 secret**. See `Securing your webhooks
133 <https://developer.github.com/webhooks/securing/>`_.
134
135 .. attr:: sshkey
136 :default: ~/.ssh/id_rsa
137
138 Path to SSH key to use when cloning github repositories.
139
140 .. attr:: server
141 :default: github.com
142
143 Hostname of the github install (such as a GitHub Enterprise).
144
145 .. attr:: canonical_hostname
146
147 The canonical hostname associated with the git repos on the
148 GitHub server. Defaults to the value of :attr:`<github
149 connection>.server`. This is used to identify projects from
150 this connection by name and in preparing repos on the filesystem
151 for use by jobs. Note that Zuul will still only communicate
152 with the GitHub server identified by **server**; this option is
153 useful if users customarily use a different hostname to clone or
154 pull git repos so that when Zuul places them in the job's
155 working directory, they appear under this directory name.
156
157 .. attr:: verify_ssl
158 :default: true
159
160 Enable or disable ssl verification for GitHub Enterprise. This
161 is useful for a connection to a test installation.
Tobias Henkel65e0e8c2017-08-01 13:44:33 +0200162
James E. Blaireff5a9d2017-06-20 00:00:37 -0700163Trigger Configuration
164---------------------
165GitHub webhook events can be configured as triggers.
166
James E. Blair02157ad2017-08-03 17:34:22 -0700167A connection name with the GitHub driver can take multiple events with
168the following options.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700169
James E. Blair02157ad2017-08-03 17:34:22 -0700170.. attr:: pipeline.trigger.<github source>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700171
James E. Blair02157ad2017-08-03 17:34:22 -0700172 The dictionary passed to the GitHub pipeline ``trigger`` attribute
173 supports the following attributes:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700174
James E. Blair02157ad2017-08-03 17:34:22 -0700175 .. attr:: event
176 :required:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700177
James E. Blair02157ad2017-08-03 17:34:22 -0700178 The event from github. Supported events are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700179
James E. Blair02157ad2017-08-03 17:34:22 -0700180 .. value:: pull_request
James E. Blaireff5a9d2017-06-20 00:00:37 -0700181
James E. Blair02157ad2017-08-03 17:34:22 -0700182 .. value:: pull_request_review
James E. Blaireff5a9d2017-06-20 00:00:37 -0700183
James E. Blair02157ad2017-08-03 17:34:22 -0700184 .. value:: push
James E. Blaireff5a9d2017-06-20 00:00:37 -0700185
James E. Blair02157ad2017-08-03 17:34:22 -0700186 .. attr:: action
James E. Blaireff5a9d2017-06-20 00:00:37 -0700187
James E. Blair02157ad2017-08-03 17:34:22 -0700188 A :value:`pipeline.trigger.<github source>.event.pull_request`
189 event will have associated action(s) to trigger from. The
190 supported actions are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700191
James E. Blair02157ad2017-08-03 17:34:22 -0700192 .. value:: opened
James E. Blaireff5a9d2017-06-20 00:00:37 -0700193
James E. Blair02157ad2017-08-03 17:34:22 -0700194 Pull request opened.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700195
James E. Blair02157ad2017-08-03 17:34:22 -0700196 .. value:: changed
James E. Blaireff5a9d2017-06-20 00:00:37 -0700197
James E. Blair02157ad2017-08-03 17:34:22 -0700198 Pull request synchronized.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700199
James E. Blair02157ad2017-08-03 17:34:22 -0700200 .. value:: closed
James E. Blaireff5a9d2017-06-20 00:00:37 -0700201
James E. Blair02157ad2017-08-03 17:34:22 -0700202 Pull request closed.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700203
James E. Blair02157ad2017-08-03 17:34:22 -0700204 .. value:: reopened
James E. Blaireff5a9d2017-06-20 00:00:37 -0700205
James E. Blair02157ad2017-08-03 17:34:22 -0700206 Pull request reopened.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700207
James E. Blair02157ad2017-08-03 17:34:22 -0700208 .. value:: comment
James E. Blaireff5a9d2017-06-20 00:00:37 -0700209
James E. Blair02157ad2017-08-03 17:34:22 -0700210 Comment added to pull request.
211
212 .. value:: labeled
213
214 Label added to pull request.
215
216 .. value:: unlabeled
217
218 Label removed from pull request.
219
220 .. value:: status
221
222 Status set on commit.
223
224 A :value:`pipeline.trigger.<github
225 source>.event.pull_request_review` event will have associated
226 action(s) to trigger from. The supported actions are:
227
228 .. value:: submitted
229
230 Pull request review added.
231
232 .. value:: dismissed
233
234 Pull request review removed.
235
236 .. attr:: branch
237
238 The branch associated with the event. Example: ``master``. This
239 field is treated as a regular expression, and multiple branches
240 may be listed. Used for ``pull_request`` and
241 ``pull_request_review`` events.
242
243 .. attr:: comment
244
245 This is only used for ``pull_request`` ``comment`` actions. It
246 accepts a list of regexes that are searched for in the comment
247 string. If any of these regexes matches a portion of the comment
248 string the trigger is matched. ``comment: retrigger`` will
249 match when comments containing 'retrigger' somewhere in the
250 comment text are added to a pull request.
251
252 .. attr:: label
253
254 This is only used for ``labeled`` and ``unlabeled``
255 ``pull_request`` actions. It accepts a list of strings each of
256 which matches the label name in the event literally. ``label:
257 recheck`` will match a ``labeled`` action when pull request is
258 labeled with a ``recheck`` label. ``label: 'do not test'`` will
259 match a ``unlabeled`` action when a label with name ``do not
260 test`` is removed from the pull request.
261
262 .. attr:: state
263
264 This is only used for ``pull_request_review`` events. It
265 accepts a list of strings each of which is matched to the review
266 state, which can be one of ``approved``, ``comment``, or
267 ``request_changes``.
268
269 .. attr:: status
270
271 This is used for ``pull-request`` and ``status`` actions. It
272 accepts a list of strings each of which matches the user setting
273 the status, the status context, and the status itself in the
274 format of ``user:context:status``. For example,
275 ``zuul_github_ci_bot:check_pipeline:success``.
276
277 .. attr:: ref
278
279 This is only used for ``push`` events. This field is treated as
280 a regular expression and multiple refs may be listed. GitHub
281 always sends full ref name, eg. ``refs/tags/bar`` and this
282 string is matched against the regular expression.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700283
284Reporter Configuration
285----------------------
286Zuul reports back to GitHub via GitHub API. Available reports include a PR
287comment containing the build results, a commit status on start, success and
288failure, an issue label addition/removal on the PR, and a merge of the PR
289itself. Status name, description, and context is taken from the pipeline.
290
James E. Blair02157ad2017-08-03 17:34:22 -0700291.. attr:: pipeline.<reporter>.<github source>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700292
James E. Blair02157ad2017-08-03 17:34:22 -0700293 To report to GitHub, the dictionaries passed to any of the pipeline
294 :ref:`reporter<reporters>` attributes support the following
295 attributes:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700296
James E. Blair02157ad2017-08-03 17:34:22 -0700297 .. attr:: status
James E. Blaireff5a9d2017-06-20 00:00:37 -0700298
James E. Blair02157ad2017-08-03 17:34:22 -0700299 String value (``pending``, ``success``, ``failure``) that the
300 reporter should set as the commit status on github.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700301
James E. Blair02157ad2017-08-03 17:34:22 -0700302 .. TODO support role markup in :default: so we can xref
Tobias Henkel940da002018-01-23 12:17:27 +0100303 :attr:`web.status_url` below
James E. Blaireff5a9d2017-06-20 00:00:37 -0700304
James E. Blair02157ad2017-08-03 17:34:22 -0700305 .. attr:: status-url
Tobias Henkel940da002018-01-23 12:17:27 +0100306 :default: web.status_url or the empty string
James E. Blaireff5a9d2017-06-20 00:00:37 -0700307
James E. Blair02157ad2017-08-03 17:34:22 -0700308 String value for a link url to set in the github
309 status. Defaults to the zuul server status_url, or the empty
310 string if that is unset.
311
312 .. attr:: comment
313 :default: true
314
315 Boolean value that determines if the reporter should add a
316 comment to the pipeline status to the github pull request. Only
317 used for Pull Request based items.
318
319 .. attr:: merge
320 :default: false
321
322 Boolean value that determines if the reporter should merge the
323 pull reqeust. Only used for Pull Request based items.
324
325 .. attr:: label
326
327 List of strings each representing an exact label name which
328 should be added to the pull request by reporter. Only used for
329 Pull Request based items.
330
331 .. attr:: unlabel
332
333 List of strings each representing an exact label name which
334 should be removed from the pull request by reporter. Only used
335 for Pull Request based items.
Monty Taylorae1f03a2017-07-27 14:43:32 -0500336
337.. _Github App: https://developer.github.com/apps/
James E. Blaird134c6d2017-07-26 16:09:34 -0700338
339Requirements Configuration
340--------------------------
341
James E. Blair32c52482017-07-29 07:49:03 -0700342As described in :attr:`pipeline.require` and :attr:`pipeline.reject`,
343pipelines may specify that items meet certain conditions in order to
344be enqueued into the pipeline. These conditions vary according to the
345source of the project in question. To supply requirements for changes
James E. Blair02157ad2017-08-03 17:34:22 -0700346from a GitHub source named ``my-github``, create a congfiguration such
James E. Blair32c52482017-07-29 07:49:03 -0700347as the following::
James E. Blaird134c6d2017-07-26 16:09:34 -0700348
349 pipeline:
350 require:
351 my-github:
352 review:
353 - type: approval
354
355This indicates that changes originating from the GitHub connection
James E. Blair02157ad2017-08-03 17:34:22 -0700356named ``my-github`` must have an approved code review in order to be
James E. Blaird134c6d2017-07-26 16:09:34 -0700357enqueued into the pipeline.
358
James E. Blair94375912017-07-28 17:20:27 -0700359.. attr:: pipeline.require.<github source>
James E. Blaird134c6d2017-07-26 16:09:34 -0700360
361 The dictionary passed to the GitHub pipeline `require` attribute
362 supports the following attributes:
363
James E. Blair94375912017-07-28 17:20:27 -0700364 .. attr:: review
James E. Blaird134c6d2017-07-26 16:09:34 -0700365
366 This requires that a certain kind of code review be present for
367 the pull request (it could be added by the event in question).
368 It takes several sub-parameters, all of which are optional and
369 are combined together so that there must be a code review
370 matching all specified requirements.
371
James E. Blair94375912017-07-28 17:20:27 -0700372 .. attr:: username
James E. Blaird134c6d2017-07-26 16:09:34 -0700373
374 If present, a code review from this username is required. It
375 is treated as a regular expression.
376
James E. Blair94375912017-07-28 17:20:27 -0700377 .. attr:: email
James E. Blaird134c6d2017-07-26 16:09:34 -0700378
379 If present, a code review with this email address is
380 required. It is treated as a regular expression.
381
James E. Blair94375912017-07-28 17:20:27 -0700382 .. attr:: older-than
James E. Blaird134c6d2017-07-26 16:09:34 -0700383
384 If present, the code review must be older than this amount of
385 time to match. Provide a time interval as a number with a
386 suffix of "w" (weeks), "d" (days), "h" (hours), "m"
387 (minutes), "s" (seconds). Example ``48h`` or ``2d``.
388
James E. Blair94375912017-07-28 17:20:27 -0700389 .. attr:: newer-than
James E. Blaird134c6d2017-07-26 16:09:34 -0700390
391 If present, the code review must be newer than this amount of
392 time to match. Same format as "older-than".
393
James E. Blair94375912017-07-28 17:20:27 -0700394 .. attr:: type
James E. Blaird134c6d2017-07-26 16:09:34 -0700395
396 If present, the code review must match this type (or types).
397
398 .. TODO: what types are valid?
399
James E. Blair94375912017-07-28 17:20:27 -0700400 .. attr:: permission
James E. Blaird134c6d2017-07-26 16:09:34 -0700401
402 If present, the author of the code review must have this
403 permission (or permissions). The available values are
404 ``read``, ``write``, and ``admin``.
405
James E. Blair94375912017-07-28 17:20:27 -0700406 .. attr:: open
James E. Blaird134c6d2017-07-26 16:09:34 -0700407
408 A boolean value (``true`` or ``false``) that indicates whether
409 the change must be open or closed in order to be enqueued.
410
James E. Blair94375912017-07-28 17:20:27 -0700411 .. attr:: current-patchset
James E. Blaird134c6d2017-07-26 16:09:34 -0700412
413 A boolean value (``true`` or ``false``) that indicates whether
414 the item must be associated with the latest commit in the pull
415 request in order to be enqueued.
416
417 .. TODO: this could probably be expanded upon -- under what
418 circumstances might this happen with github
419
James E. Blair94375912017-07-28 17:20:27 -0700420 .. attr:: status
James E. Blaird134c6d2017-07-26 16:09:34 -0700421
422 A string value that corresponds with the status of the pull
423 request. The syntax is ``user:status:value``.
424
James E. Blair94375912017-07-28 17:20:27 -0700425 .. attr:: label
James E. Blaird134c6d2017-07-26 16:09:34 -0700426
427 A string value indicating that the pull request must have the
428 indicated label (or labels).
429
James E. Blair94375912017-07-28 17:20:27 -0700430.. attr:: pipeline.reject.<github source>
James E. Blaird134c6d2017-07-26 16:09:34 -0700431
432 The `reject` attribute is the mirror of the `require` attribute. It
433 also accepts a dictionary under the connection name. This
434 dictionary supports the following attributes:
435
James E. Blair94375912017-07-28 17:20:27 -0700436 .. attr:: review
James E. Blaird134c6d2017-07-26 16:09:34 -0700437
438 This takes a list of code reviews. If a code review matches the
439 provided criteria the pull request can not be entered into the
James E. Blair91fe4832017-07-28 17:28:26 -0700440 pipeline. It follows the same syntax as
441 :attr:`pipeline.require.<github source>.review`