blob: 7eebbdcb9d59257cc1327732dd7bfb564442fbfc [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
10.. TODO: make this section more user friendly
11
12Configure GitHub `webhook events
13<https://developer.github.com/webhooks/creating/>`_.
14
15Set *Payload URL* to
16``http://<zuul-hostname>/connection/<connection-name>/payload``.
17
18Set *Content Type* to ``application/json``.
19
20Select *Events* you are interested in. See below for the supported events.
21
22Connection Configuration
23------------------------
24
Monty Taylorae1f03a2017-07-27 14:43:32 -050025There are two forms of operation. Either the Zuul installation can be
26configured as a `Github App`_ or it can be configured as a Webhook.
27
28If 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``
30setting is required.
31
James E. Blair02157ad2017-08-03 17:34:22 -070032The supported options in ``zuul.conf`` connections are:
James E. Blaireff5a9d2017-06-20 00:00:37 -070033
James E. Blair02157ad2017-08-03 17:34:22 -070034.. attr:: <github connection>
James E. Blaireff5a9d2017-06-20 00:00:37 -070035
James E. Blair02157ad2017-08-03 17:34:22 -070036 .. attr:: driver
37 :required:
Monty Taylorae1f03a2017-07-27 14:43:32 -050038
James E. Blair02157ad2017-08-03 17:34:22 -070039 .. value:: github
Monty Taylorae1f03a2017-07-27 14:43:32 -050040
James E. Blair02157ad2017-08-03 17:34:22 -070041 The connection must set ``driver=github`` for GitHub connections.
James E. Blaireff5a9d2017-06-20 00:00:37 -070042
James E. Blair02157ad2017-08-03 17:34:22 -070043 .. attr:: app_id
James E. Blaireff5a9d2017-06-20 00:00:37 -070044
James E. Blair02157ad2017-08-03 17:34:22 -070045 App ID if you are using a *GitHub App*. Can be found under the
46 **Public Link** on the right hand side labeled **ID**.
James E. Blaireff5a9d2017-06-20 00:00:37 -070047
James E. Blair02157ad2017-08-03 17:34:22 -070048 .. attr:: app_key
James E. Blaireff5a9d2017-06-20 00:00:37 -070049
James E. Blair02157ad2017-08-03 17:34:22 -070050 Path to a file containing the secret key Zuul will use to create
51 tokens for the API interactions. In Github this is known as
52 **Private key** and must be collected when generated.
James E. Blair4d5dd252017-06-23 21:40:56 +010053
James E. Blair02157ad2017-08-03 17:34:22 -070054 .. attr:: api_token
55
56 API token for accessing GitHub if Zuul is configured with
57 Webhooks. See `Creating an access token for command-line use
58 <https://help.github.com/articles/creating-an-access-token-for-command-line-use/>`_.
59
60 .. attr:: webhook_token
61
62 Required token for validating the webhook event payloads. In
63 the GitHub App Configuration page, this is called **Webhook
64 secret**. See `Securing your webhooks
65 <https://developer.github.com/webhooks/securing/>`_.
66
67 .. attr:: sshkey
68 :default: ~/.ssh/id_rsa
69
70 Path to SSH key to use when cloning github repositories.
71
72 .. attr:: server
73 :default: github.com
74
75 Hostname of the github install (such as a GitHub Enterprise).
76
77 .. attr:: canonical_hostname
78
79 The canonical hostname associated with the git repos on the
80 GitHub server. Defaults to the value of :attr:`<github
81 connection>.server`. This is used to identify projects from
82 this connection by name and in preparing repos on the filesystem
83 for use by jobs. Note that Zuul will still only communicate
84 with the GitHub server identified by **server**; this option is
85 useful if users customarily use a different hostname to clone or
86 pull git repos so that when Zuul places them in the job's
87 working directory, they appear under this directory name.
88
89 .. attr:: verify_ssl
90 :default: true
91
92 Enable or disable ssl verification for GitHub Enterprise. This
93 is useful for a connection to a test installation.
Tobias Henkel65e0e8c2017-08-01 13:44:33 +020094
James E. Blaireff5a9d2017-06-20 00:00:37 -070095Trigger Configuration
96---------------------
97GitHub webhook events can be configured as triggers.
98
James E. Blair02157ad2017-08-03 17:34:22 -070099A connection name with the GitHub driver can take multiple events with
100the following options.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700101
James E. Blair02157ad2017-08-03 17:34:22 -0700102.. attr:: pipeline.trigger.<github source>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700103
James E. Blair02157ad2017-08-03 17:34:22 -0700104 The dictionary passed to the GitHub pipeline ``trigger`` attribute
105 supports the following attributes:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700106
James E. Blair02157ad2017-08-03 17:34:22 -0700107 .. attr:: event
108 :required:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700109
James E. Blair02157ad2017-08-03 17:34:22 -0700110 The event from github. Supported events are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700111
James E. Blair02157ad2017-08-03 17:34:22 -0700112 .. value:: pull_request
James E. Blaireff5a9d2017-06-20 00:00:37 -0700113
James E. Blair02157ad2017-08-03 17:34:22 -0700114 .. value:: pull_request_review
James E. Blaireff5a9d2017-06-20 00:00:37 -0700115
James E. Blair02157ad2017-08-03 17:34:22 -0700116 .. value:: push
James E. Blaireff5a9d2017-06-20 00:00:37 -0700117
James E. Blair02157ad2017-08-03 17:34:22 -0700118 .. attr:: action
James E. Blaireff5a9d2017-06-20 00:00:37 -0700119
James E. Blair02157ad2017-08-03 17:34:22 -0700120 A :value:`pipeline.trigger.<github source>.event.pull_request`
121 event will have associated action(s) to trigger from. The
122 supported actions are:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700123
James E. Blair02157ad2017-08-03 17:34:22 -0700124 .. value:: opened
James E. Blaireff5a9d2017-06-20 00:00:37 -0700125
James E. Blair02157ad2017-08-03 17:34:22 -0700126 Pull request opened.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700127
James E. Blair02157ad2017-08-03 17:34:22 -0700128 .. value:: changed
James E. Blaireff5a9d2017-06-20 00:00:37 -0700129
James E. Blair02157ad2017-08-03 17:34:22 -0700130 Pull request synchronized.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700131
James E. Blair02157ad2017-08-03 17:34:22 -0700132 .. value:: closed
James E. Blaireff5a9d2017-06-20 00:00:37 -0700133
James E. Blair02157ad2017-08-03 17:34:22 -0700134 Pull request closed.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700135
James E. Blair02157ad2017-08-03 17:34:22 -0700136 .. value:: reopened
James E. Blaireff5a9d2017-06-20 00:00:37 -0700137
James E. Blair02157ad2017-08-03 17:34:22 -0700138 Pull request reopened.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700139
James E. Blair02157ad2017-08-03 17:34:22 -0700140 .. value:: comment
James E. Blaireff5a9d2017-06-20 00:00:37 -0700141
James E. Blair02157ad2017-08-03 17:34:22 -0700142 Comment added to pull request.
143
144 .. value:: labeled
145
146 Label added to pull request.
147
148 .. value:: unlabeled
149
150 Label removed from pull request.
151
152 .. value:: status
153
154 Status set on commit.
155
156 A :value:`pipeline.trigger.<github
157 source>.event.pull_request_review` event will have associated
158 action(s) to trigger from. The supported actions are:
159
160 .. value:: submitted
161
162 Pull request review added.
163
164 .. value:: dismissed
165
166 Pull request review removed.
167
168 .. attr:: branch
169
170 The branch associated with the event. Example: ``master``. This
171 field is treated as a regular expression, and multiple branches
172 may be listed. Used for ``pull_request`` and
173 ``pull_request_review`` events.
174
175 .. attr:: comment
176
177 This is only used for ``pull_request`` ``comment`` actions. It
178 accepts a list of regexes that are searched for in the comment
179 string. If any of these regexes matches a portion of the comment
180 string the trigger is matched. ``comment: retrigger`` will
181 match when comments containing 'retrigger' somewhere in the
182 comment text are added to a pull request.
183
184 .. attr:: label
185
186 This is only used for ``labeled`` and ``unlabeled``
187 ``pull_request`` actions. It accepts a list of strings each of
188 which matches the label name in the event literally. ``label:
189 recheck`` will match a ``labeled`` action when pull request is
190 labeled with a ``recheck`` label. ``label: 'do not test'`` will
191 match a ``unlabeled`` action when a label with name ``do not
192 test`` is removed from the pull request.
193
194 .. attr:: state
195
196 This is only used for ``pull_request_review`` events. It
197 accepts a list of strings each of which is matched to the review
198 state, which can be one of ``approved``, ``comment``, or
199 ``request_changes``.
200
201 .. attr:: status
202
203 This is used for ``pull-request`` and ``status`` actions. It
204 accepts a list of strings each of which matches the user setting
205 the status, the status context, and the status itself in the
206 format of ``user:context:status``. For example,
207 ``zuul_github_ci_bot:check_pipeline:success``.
208
209 .. attr:: ref
210
211 This is only used for ``push`` events. This field is treated as
212 a regular expression and multiple refs may be listed. GitHub
213 always sends full ref name, eg. ``refs/tags/bar`` and this
214 string is matched against the regular expression.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700215
216Reporter Configuration
217----------------------
218Zuul reports back to GitHub via GitHub API. Available reports include a PR
219comment containing the build results, a commit status on start, success and
220failure, an issue label addition/removal on the PR, and a merge of the PR
221itself. Status name, description, and context is taken from the pipeline.
222
James E. Blair02157ad2017-08-03 17:34:22 -0700223.. attr:: pipeline.<reporter>.<github source>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700224
James E. Blair02157ad2017-08-03 17:34:22 -0700225 To report to GitHub, the dictionaries passed to any of the pipeline
226 :ref:`reporter<reporters>` attributes support the following
227 attributes:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700228
James E. Blair02157ad2017-08-03 17:34:22 -0700229 .. attr:: status
James E. Blaireff5a9d2017-06-20 00:00:37 -0700230
James E. Blair02157ad2017-08-03 17:34:22 -0700231 String value (``pending``, ``success``, ``failure``) that the
232 reporter should set as the commit status on github.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700233
James E. Blair02157ad2017-08-03 17:34:22 -0700234 .. TODO support role markup in :default: so we can xref
235 :attr:`webapp.status_url` below
James E. Blaireff5a9d2017-06-20 00:00:37 -0700236
James E. Blair02157ad2017-08-03 17:34:22 -0700237 .. attr:: status-url
238 :default: webapp.status_url or the empty string
James E. Blaireff5a9d2017-06-20 00:00:37 -0700239
James E. Blair02157ad2017-08-03 17:34:22 -0700240 String value for a link url to set in the github
241 status. Defaults to the zuul server status_url, or the empty
242 string if that is unset.
243
244 .. attr:: comment
245 :default: true
246
247 Boolean value that determines if the reporter should add a
248 comment to the pipeline status to the github pull request. Only
249 used for Pull Request based items.
250
251 .. attr:: merge
252 :default: false
253
254 Boolean value that determines if the reporter should merge the
255 pull reqeust. Only used for Pull Request based items.
256
257 .. attr:: label
258
259 List of strings each representing an exact label name which
260 should be added to the pull request by reporter. Only used for
261 Pull Request based items.
262
263 .. attr:: unlabel
264
265 List of strings each representing an exact label name which
266 should be removed from the pull request by reporter. Only used
267 for Pull Request based items.
Monty Taylorae1f03a2017-07-27 14:43:32 -0500268
269.. _Github App: https://developer.github.com/apps/
James E. Blaird134c6d2017-07-26 16:09:34 -0700270
271Requirements Configuration
272--------------------------
273
James E. Blair32c52482017-07-29 07:49:03 -0700274As described in :attr:`pipeline.require` and :attr:`pipeline.reject`,
275pipelines may specify that items meet certain conditions in order to
276be enqueued into the pipeline. These conditions vary according to the
277source of the project in question. To supply requirements for changes
James E. Blair02157ad2017-08-03 17:34:22 -0700278from a GitHub source named ``my-github``, create a congfiguration such
James E. Blair32c52482017-07-29 07:49:03 -0700279as the following::
James E. Blaird134c6d2017-07-26 16:09:34 -0700280
281 pipeline:
282 require:
283 my-github:
284 review:
285 - type: approval
286
287This indicates that changes originating from the GitHub connection
James E. Blair02157ad2017-08-03 17:34:22 -0700288named ``my-github`` must have an approved code review in order to be
James E. Blaird134c6d2017-07-26 16:09:34 -0700289enqueued into the pipeline.
290
James E. Blair94375912017-07-28 17:20:27 -0700291.. attr:: pipeline.require.<github source>
James E. Blaird134c6d2017-07-26 16:09:34 -0700292
293 The dictionary passed to the GitHub pipeline `require` attribute
294 supports the following attributes:
295
James E. Blair94375912017-07-28 17:20:27 -0700296 .. attr:: review
James E. Blaird134c6d2017-07-26 16:09:34 -0700297
298 This requires that a certain kind of code review be present for
299 the pull request (it could be added by the event in question).
300 It takes several sub-parameters, all of which are optional and
301 are combined together so that there must be a code review
302 matching all specified requirements.
303
James E. Blair94375912017-07-28 17:20:27 -0700304 .. attr:: username
James E. Blaird134c6d2017-07-26 16:09:34 -0700305
306 If present, a code review from this username is required. It
307 is treated as a regular expression.
308
James E. Blair94375912017-07-28 17:20:27 -0700309 .. attr:: email
James E. Blaird134c6d2017-07-26 16:09:34 -0700310
311 If present, a code review with this email address is
312 required. It is treated as a regular expression.
313
James E. Blair94375912017-07-28 17:20:27 -0700314 .. attr:: older-than
James E. Blaird134c6d2017-07-26 16:09:34 -0700315
316 If present, the code review must be older than this amount of
317 time to match. Provide a time interval as a number with a
318 suffix of "w" (weeks), "d" (days), "h" (hours), "m"
319 (minutes), "s" (seconds). Example ``48h`` or ``2d``.
320
James E. Blair94375912017-07-28 17:20:27 -0700321 .. attr:: newer-than
James E. Blaird134c6d2017-07-26 16:09:34 -0700322
323 If present, the code review must be newer than this amount of
324 time to match. Same format as "older-than".
325
James E. Blair94375912017-07-28 17:20:27 -0700326 .. attr:: type
James E. Blaird134c6d2017-07-26 16:09:34 -0700327
328 If present, the code review must match this type (or types).
329
330 .. TODO: what types are valid?
331
James E. Blair94375912017-07-28 17:20:27 -0700332 .. attr:: permission
James E. Blaird134c6d2017-07-26 16:09:34 -0700333
334 If present, the author of the code review must have this
335 permission (or permissions). The available values are
336 ``read``, ``write``, and ``admin``.
337
James E. Blair94375912017-07-28 17:20:27 -0700338 .. attr:: open
James E. Blaird134c6d2017-07-26 16:09:34 -0700339
340 A boolean value (``true`` or ``false``) that indicates whether
341 the change must be open or closed in order to be enqueued.
342
James E. Blair94375912017-07-28 17:20:27 -0700343 .. attr:: current-patchset
James E. Blaird134c6d2017-07-26 16:09:34 -0700344
345 A boolean value (``true`` or ``false``) that indicates whether
346 the item must be associated with the latest commit in the pull
347 request in order to be enqueued.
348
349 .. TODO: this could probably be expanded upon -- under what
350 circumstances might this happen with github
351
James E. Blair94375912017-07-28 17:20:27 -0700352 .. attr:: status
James E. Blaird134c6d2017-07-26 16:09:34 -0700353
354 A string value that corresponds with the status of the pull
355 request. The syntax is ``user:status:value``.
356
James E. Blair94375912017-07-28 17:20:27 -0700357 .. attr:: label
James E. Blaird134c6d2017-07-26 16:09:34 -0700358
359 A string value indicating that the pull request must have the
360 indicated label (or labels).
361
James E. Blair94375912017-07-28 17:20:27 -0700362.. attr:: pipeline.reject.<github source>
James E. Blaird134c6d2017-07-26 16:09:34 -0700363
364 The `reject` attribute is the mirror of the `require` attribute. It
365 also accepts a dictionary under the connection name. This
366 dictionary supports the following attributes:
367
James E. Blair94375912017-07-28 17:20:27 -0700368 .. attr:: review
James E. Blaird134c6d2017-07-26 16:09:34 -0700369
370 This takes a list of code reviews. If a code review matches the
371 provided criteria the pull request can not be entered into the
James E. Blair91fe4832017-07-28 17:28:26 -0700372 pipeline. It follows the same syntax as
373 :attr:`pipeline.require.<github source>.review`