octokit 4.6.2 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +14 -13
- data/LICENSE.md +1 -1
- data/README.md +218 -109
- data/Rakefile +5 -3
- data/lib/ext/sawyer/relation.rb +4 -2
- data/lib/octokit/arguments.rb +2 -2
- data/lib/octokit/authentication.rb +20 -14
- data/lib/octokit/client/actions_secrets.rb +57 -0
- data/lib/octokit/client/actions_workflow_jobs.rb +61 -0
- data/lib/octokit/client/actions_workflow_runs.rb +121 -0
- data/lib/octokit/client/actions_workflows.rb +66 -0
- data/lib/octokit/client/apps.rb +222 -0
- data/lib/octokit/client/authorizations.rb +30 -89
- data/lib/octokit/client/checks.rb +200 -0
- data/lib/octokit/client/commit_branches.rb +20 -0
- data/lib/octokit/client/commit_comments.rb +8 -8
- data/lib/octokit/client/commit_pulls.rb +20 -0
- data/lib/octokit/client/commits.rb +31 -34
- data/lib/octokit/client/community_profile.rb +21 -0
- data/lib/octokit/client/contents.rb +25 -20
- data/lib/octokit/client/deployments.rb +25 -5
- data/lib/octokit/client/downloads.rb +5 -6
- data/lib/octokit/client/emojis.rb +3 -3
- data/lib/octokit/client/events.rb +4 -4
- data/lib/octokit/client/feeds.rb +4 -5
- data/lib/octokit/client/gists.rb +7 -6
- data/lib/octokit/client/gitignore.rb +3 -3
- data/lib/octokit/client/hooks.rb +10 -10
- data/lib/octokit/client/issues.rb +60 -14
- data/lib/octokit/client/labels.rb +17 -17
- data/lib/octokit/client/legacy_search.rb +3 -3
- data/lib/octokit/client/licenses.rb +4 -7
- data/lib/octokit/client/markdown.rb +3 -3
- data/lib/octokit/client/marketplace.rb +56 -0
- data/lib/octokit/client/meta.rb +4 -5
- data/lib/octokit/client/milestones.rb +5 -5
- data/lib/octokit/client/notifications.rb +6 -10
- data/lib/octokit/client/oauth_applications.rb +116 -0
- data/lib/octokit/client/objects.rb +14 -14
- data/lib/octokit/client/organizations.rb +181 -61
- data/lib/octokit/client/pages.rb +5 -7
- data/lib/octokit/client/projects.rb +49 -69
- data/lib/octokit/client/pub_sub_hubbub.rb +16 -16
- data/lib/octokit/client/pull_requests.rb +47 -46
- data/lib/octokit/client/rate_limit.rb +11 -13
- data/lib/octokit/client/reactions.rb +6 -11
- data/lib/octokit/client/refs.rb +33 -18
- data/lib/octokit/client/releases.rb +14 -13
- data/lib/octokit/client/repositories.rb +194 -53
- data/lib/octokit/client/repository_invitations.rb +4 -11
- data/lib/octokit/client/reviews.rb +227 -0
- data/lib/octokit/client/say.rb +4 -5
- data/lib/octokit/client/search.rb +45 -17
- data/lib/octokit/client/service_status.rb +19 -9
- data/lib/octokit/client/source_import.rb +8 -13
- data/lib/octokit/client/stats.rb +12 -9
- data/lib/octokit/client/statuses.rb +6 -6
- data/lib/octokit/client/traffic.rb +6 -11
- data/lib/octokit/client/users.rb +106 -25
- data/lib/octokit/client.rb +60 -15
- data/lib/octokit/configurable.rb +42 -30
- data/lib/octokit/connection.rb +34 -20
- data/lib/octokit/default.rb +61 -34
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +14 -15
- data/lib/octokit/enterprise_admin_client/license.rb +4 -5
- data/lib/octokit/enterprise_admin_client/orgs.rb +5 -6
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +8 -9
- data/lib/octokit/enterprise_admin_client/users.rb +17 -16
- data/lib/octokit/enterprise_admin_client.rb +9 -3
- data/lib/octokit/enterprise_management_console_client/management_console.rb +33 -33
- data/lib/octokit/enterprise_management_console_client.rb +9 -3
- data/lib/octokit/error.rb +106 -25
- data/lib/octokit/gist.rb +3 -4
- data/lib/octokit/middleware/follow_redirects.rb +17 -13
- data/lib/octokit/organization.rb +3 -1
- data/lib/octokit/rate_limit.rb +6 -6
- data/lib/octokit/repo_arguments.rb +2 -3
- data/lib/octokit/repository.rb +27 -25
- data/lib/octokit/response/base_middleware.rb +10 -0
- data/lib/octokit/response/feed_parser.rb +5 -9
- data/lib/octokit/response/raise_error.rb +4 -6
- data/lib/octokit/user.rb +4 -2
- data/lib/octokit/version.rb +5 -3
- data/lib/octokit/warnable.rb +4 -5
- data/lib/octokit.rb +15 -8
- data/octokit.gemspec +13 -10
- metadata +52 -21
- data/lib/octokit/preview.rb +0 -35
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# Octokit
|
2
2
|
|
3
|
+
> **Note**
|
4
|
+
> We've recently renamed the `4-stable` branch to `main`. This might affect you if you're making changes to Octokit's code locally. For more details and for the steps to reconfigure your local clone for the new branch name, check out [this post](https://github.com/octokit/octokit.rb/discussions/1455).
|
5
|
+
|
3
6
|
Ruby toolkit for the GitHub API.
|
4
7
|
|
5
|
-
![
|
6
|
-
[logo]: http://cl.ly/image/3Y013H0A2z3z/gundam-ruby.png
|
8
|
+
![logo](https://docs.github.com/assets/images/gundamcat.png)
|
7
9
|
|
8
10
|
Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
|
9
11
|
[major version][semver].
|
@@ -11,26 +13,29 @@ Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
|
|
11
13
|
## Table of Contents
|
12
14
|
|
13
15
|
1. [Philosophy](#philosophy)
|
14
|
-
2. [
|
16
|
+
2. [Installation](#quick-start)
|
15
17
|
3. [Making requests](#making-requests)
|
18
|
+
1. [Additional Query Parameters](#additional-query-parameters)
|
16
19
|
4. [Consuming resources](#consuming-resources)
|
17
20
|
5. [Accessing HTTP responses](#accessing-http-responses)
|
18
|
-
6. [
|
21
|
+
6. [Handling errors](#handling-errors)
|
22
|
+
7. [Authentication](#authentication)
|
19
23
|
1. [Basic Authentication](#basic-authentication)
|
20
24
|
2. [OAuth access tokens](#oauth-access-tokens)
|
21
25
|
3. [Two-Factor Authentication](#two-factor-authentication)
|
22
26
|
4. [Using a .netrc file](#using-a-netrc-file)
|
23
27
|
5. [Application authentication](#application-authentication)
|
24
|
-
|
28
|
+
8. [Pagination](#pagination)
|
25
29
|
1. [Auto pagination](#auto-pagination)
|
26
|
-
|
30
|
+
9. [Working with GitHub Enterprise](#working-with-github-enterprise)
|
27
31
|
1. [Interacting with the GitHub.com APIs in GitHub Enterprise](#interacting-with-the-githubcom-apis-in-github-enterprise)
|
28
32
|
2. [Interacting with the GitHub Enterprise Admin APIs](#interacting-with-the-github-enterprise-admin-apis)
|
29
33
|
3. [Interacting with the GitHub Enterprise Management Console APIs](#interacting-with-the-github-enterprise-management-console-apis)
|
30
|
-
|
34
|
+
4. [SSL Connection Errors](#ssl-connection-errors)
|
31
35
|
10. [Configuration and defaults](#configuration-and-defaults)
|
32
36
|
1. [Configuring module defaults](#configuring-module-defaults)
|
33
37
|
2. [Using ENV variables](#using-env-variables)
|
38
|
+
3. [Timeouts](#timeouts)
|
34
39
|
11. [Hypermedia agent](#hypermedia-agent)
|
35
40
|
1. [Hypermedia in Octokit](#hypermedia-in-octokit)
|
36
41
|
2. [URI templates](#uri-templates)
|
@@ -41,10 +46,12 @@ Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
|
|
41
46
|
1. [Debugging](#debugging)
|
42
47
|
2. [Caching](#caching)
|
43
48
|
14. [Hacking on Octokit.rb](#hacking-on-octokitrb)
|
44
|
-
1. [
|
49
|
+
1. [Code of Conduct](#code-of-conduct)
|
50
|
+
2. [Running and writing new tests](#running-and-writing-new-tests)
|
45
51
|
15. [Supported Ruby Versions](#supported-ruby-versions)
|
46
52
|
16. [Versioning](#versioning)
|
47
|
-
17. [
|
53
|
+
17. [Making Repeating Requests](#making-repeating-requests)
|
54
|
+
18. [License](#license)
|
48
55
|
|
49
56
|
## Philosophy
|
50
57
|
|
@@ -55,15 +62,16 @@ Most methods have positional arguments for required input and an options hash
|
|
55
62
|
for optional parameters, headers, or other options:
|
56
63
|
|
57
64
|
```ruby
|
65
|
+
client = Octokit::Client.new
|
66
|
+
|
58
67
|
# Fetch a README with Accept header for HTML format
|
59
|
-
|
68
|
+
client.readme 'al3x/sovereign', :accept => 'application/vnd.github.html'
|
60
69
|
```
|
61
70
|
|
62
|
-
|
63
71
|
[wrappers]: http://wynnnetherland.com/journal/what-makes-a-good-api-wrapper
|
64
|
-
[github-api]:
|
72
|
+
[github-api]: https://developer.github.com/v3/
|
65
73
|
|
66
|
-
##
|
74
|
+
## Installation
|
67
75
|
|
68
76
|
Install via Rubygems
|
69
77
|
|
@@ -73,40 +81,51 @@ Install via Rubygems
|
|
73
81
|
|
74
82
|
gem "octokit", "~> 4.0"
|
75
83
|
|
76
|
-
|
84
|
+
Access the library in Ruby:
|
85
|
+
|
86
|
+
require 'octokit'
|
87
|
+
|
88
|
+
## Making requests
|
77
89
|
|
78
|
-
[API methods][] are available as
|
79
|
-
configuration) or as client instance methods.
|
90
|
+
[API methods][] are available as client instance methods.
|
80
91
|
|
81
92
|
```ruby
|
82
93
|
# Provide authentication credentials
|
83
|
-
Octokit.
|
84
|
-
|
85
|
-
|
86
|
-
|
94
|
+
client = Octokit::Client.new(:access_token => 'personal_access_token')
|
95
|
+
|
96
|
+
# You can still use the username/password syntax by replacing the password value with your PAT.
|
97
|
+
# client = Octokit::Client.new(:login => 'defunkt', :password => 'personal_access_token')
|
87
98
|
|
88
99
|
# Fetch the current user
|
89
|
-
|
100
|
+
client.user
|
90
101
|
```
|
91
|
-
|
102
|
+
|
103
|
+
### Additional query parameters
|
104
|
+
|
105
|
+
When passing additional parameters to GET based request use the following syntax:
|
92
106
|
|
93
107
|
```ruby
|
94
|
-
#
|
95
|
-
|
96
|
-
|
97
|
-
|
108
|
+
# query: { parameter_name: 'value' }
|
109
|
+
# Example: Get repository listing by owner in ascending order
|
110
|
+
client.repos({}, query: {type: 'owner', sort: 'asc'})
|
111
|
+
|
112
|
+
# Example: Get contents of a repository by ref
|
113
|
+
# https://api.github.com/repos/octokit/octokit.rb/contents/path/to/file.rb?ref=some-other-branch
|
114
|
+
client.contents('octokit/octokit.rb', path: 'path/to/file.rb', query: {ref: 'some-other-branch'})
|
98
115
|
```
|
99
116
|
|
100
|
-
[
|
117
|
+
[api methods]: http://octokit.github.io/octokit.rb/method_list.html
|
101
118
|
|
102
|
-
|
119
|
+
## Consuming resources
|
103
120
|
|
104
121
|
Most methods return a `Resource` object which provides dot notation and `[]`
|
105
122
|
access for fields returned in the API response.
|
106
123
|
|
107
124
|
```ruby
|
125
|
+
client = Octokit::Client.new
|
126
|
+
|
108
127
|
# Fetch a user
|
109
|
-
user =
|
128
|
+
user = client.user 'jbarnette'
|
110
129
|
puts user.name
|
111
130
|
# => "John Barnette"
|
112
131
|
puts user.fields
|
@@ -120,18 +139,35 @@ user.rels[:gists].href
|
|
120
139
|
**Note:** URL fields are culled into a separate `.rels` collection for easier
|
121
140
|
[Hypermedia](#hypermedia-agent) support.
|
122
141
|
|
123
|
-
|
142
|
+
## Accessing HTTP responses
|
124
143
|
|
125
144
|
While most methods return a `Resource` object or a Boolean, sometimes you may
|
126
145
|
need access to the raw HTTP response headers. You can access the last HTTP
|
127
146
|
response with `Client#last_response`:
|
128
147
|
|
129
148
|
```ruby
|
130
|
-
user =
|
131
|
-
response =
|
149
|
+
user = client.user 'andrewpthorp'
|
150
|
+
response = client.last_response
|
132
151
|
etag = response.headers[:etag]
|
133
152
|
```
|
134
153
|
|
154
|
+
## Handling errors
|
155
|
+
|
156
|
+
When the API returns an error response, Octokit will raise a Ruby exception.
|
157
|
+
|
158
|
+
A range of different exceptions can be raised depending on the error returned
|
159
|
+
by the API - for example:
|
160
|
+
|
161
|
+
* A `400 Bad Request` response will lead to an `Octokit::BadRequest` error
|
162
|
+
* A `403 Forbidden` error with a "rate limited exceeded" message will lead
|
163
|
+
to a `Octokit::TooManyRequests` error
|
164
|
+
|
165
|
+
All of the different exception classes inherit from `Octokit::Error` and
|
166
|
+
expose the `#response_status`, `#response_headers` and `#response_body`.
|
167
|
+
For validation errors, `#errors` will return an `Array` of `Hash`es
|
168
|
+
with the detailed information
|
169
|
+
[returned by the API](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#client-errors).
|
170
|
+
|
135
171
|
## Authentication
|
136
172
|
|
137
173
|
Octokit supports the various [authentication methods supported by the GitHub
|
@@ -143,14 +179,13 @@ Using your GitHub username and password is the easiest way to get started
|
|
143
179
|
making authenticated requests:
|
144
180
|
|
145
181
|
```ruby
|
146
|
-
client = Octokit::Client.new
|
147
|
-
:login => 'defunkt',
|
148
|
-
:password => 'c0d3b4ssssss!'
|
182
|
+
client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!')
|
149
183
|
|
150
184
|
user = client.user
|
151
185
|
user.login
|
152
186
|
# => "defunkt"
|
153
187
|
```
|
188
|
+
|
154
189
|
While Basic Authentication allows you to get started quickly, OAuth access
|
155
190
|
tokens are the preferred way to authenticate on behalf of users.
|
156
191
|
|
@@ -159,9 +194,9 @@ tokens are the preferred way to authenticate on behalf of users.
|
|
159
194
|
[OAuth access tokens][oauth] provide two main benefits over using your username
|
160
195
|
and password:
|
161
196
|
|
162
|
-
|
197
|
+
- **Revocable access**. Access tokens can be revoked, removing access for only
|
163
198
|
that token without having to change your password everywhere.
|
164
|
-
|
199
|
+
- **Limited access**. Access tokens have [access scopes][] which allow for more
|
165
200
|
granular access to API resources. For instance, you can grant a third party
|
166
201
|
access to your gists but not your private repositories.
|
167
202
|
|
@@ -180,9 +215,7 @@ You can [create access tokens through your GitHub Account Settings](https://help
|
|
180
215
|
or with a basic authenticated Octokit client:
|
181
216
|
|
182
217
|
```ruby
|
183
|
-
client = Octokit::Client.new
|
184
|
-
:login => 'defunkt',
|
185
|
-
:password => 'c0d3b4ssssss!'
|
218
|
+
client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!')
|
186
219
|
|
187
220
|
client.create_authorization(:scopes => ["user"], :note => "Name of token")
|
188
221
|
# => <your new oauth token>
|
@@ -202,7 +235,7 @@ client = Octokit::Client.new \
|
|
202
235
|
user = client.user("defunkt", :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
|
203
236
|
```
|
204
237
|
|
205
|
-
As you can imagine, this gets annoying
|
238
|
+
As you can imagine, this gets annoying quickly since two-factor auth tokens are very short lived. So it is recommended to create an oauth token for the user to communicate with the API:
|
206
239
|
|
207
240
|
```ruby
|
208
241
|
client = Octokit::Client.new \
|
@@ -217,13 +250,14 @@ client.create_authorization(:scopes => ["user"], :note => "Name of token",
|
|
217
250
|
### Using a .netrc file
|
218
251
|
|
219
252
|
Octokit supports reading credentials from a netrc file (defaulting to
|
220
|
-
`~/.netrc`).
|
253
|
+
`~/.netrc`). Given these lines in your netrc:
|
221
254
|
|
222
255
|
```
|
223
256
|
machine api.github.com
|
224
257
|
login defunkt
|
225
258
|
password c0d3b4ssssss!
|
226
259
|
```
|
260
|
+
|
227
261
|
You can now create a client with those credentials:
|
228
262
|
|
229
263
|
```ruby
|
@@ -231,6 +265,7 @@ client = Octokit::Client.new(:netrc => true)
|
|
231
265
|
client.login
|
232
266
|
# => "defunkt"
|
233
267
|
```
|
268
|
+
|
234
269
|
But _I want to use OAuth_ you say. Since the GitHub API supports using an OAuth
|
235
270
|
token as a Basic password, you totally can:
|
236
271
|
|
@@ -263,6 +298,14 @@ user = client.user 'defunkt'
|
|
263
298
|
[access scopes]: http://developer.github.com/v3/oauth/#scopes
|
264
299
|
[app-creds]: http://developer.github.com/v3/#increasing-the-unauthenticated-rate-limit-for-oauth-applications
|
265
300
|
|
301
|
+
## Default results per_page
|
302
|
+
|
303
|
+
Default results from the GitHub API are 30, if you wish to add more you must do so during Octokit configuration.
|
304
|
+
|
305
|
+
```ruby
|
306
|
+
Octokit::Client.new(access_token: "<your 40 char token>", per_page: 100)
|
307
|
+
```
|
308
|
+
|
266
309
|
## Pagination
|
267
310
|
|
268
311
|
Many GitHub API resources are [paginated][]. While you may be tempted to start
|
@@ -271,8 +314,8 @@ previous, and last pages for you in the `Link` response header as [Hypermedia
|
|
271
314
|
link relations](#hypermedia-agent).
|
272
315
|
|
273
316
|
```ruby
|
274
|
-
issues =
|
275
|
-
issues.concat
|
317
|
+
issues = client.issues 'rails/rails'
|
318
|
+
issues.concat client.get(client.last_response.rels[:next].href)
|
276
319
|
```
|
277
320
|
|
278
321
|
### Auto pagination
|
@@ -282,13 +325,21 @@ enabled, calls for paginated resources will fetch and concatenate the results
|
|
282
325
|
from every page into a single array:
|
283
326
|
|
284
327
|
```ruby
|
285
|
-
|
286
|
-
issues =
|
328
|
+
client.auto_paginate = true
|
329
|
+
issues = client.issues 'rails/rails'
|
287
330
|
issues.length
|
288
331
|
|
289
332
|
# => 702
|
290
333
|
```
|
291
334
|
|
335
|
+
You can also enable auto pagination for all Octokit client instances:
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
Octokit.configure do |c|
|
339
|
+
c.auto_paginate = true
|
340
|
+
end
|
341
|
+
```
|
342
|
+
|
292
343
|
**Note:** While Octokit auto pagination will set the page size to the maximum
|
293
344
|
`100`, and seek to not overstep your rate limit, you probably want to use a
|
294
345
|
custom pattern for traversing large lists.
|
@@ -297,16 +348,17 @@ custom pattern for traversing large lists.
|
|
297
348
|
|
298
349
|
## Working with GitHub Enterprise
|
299
350
|
|
300
|
-
With a bit of setup, you can also use Octokit with your
|
351
|
+
With a bit of setup, you can also use Octokit with your GitHub Enterprise instance.
|
301
352
|
|
302
353
|
### Interacting with the GitHub.com APIs in GitHub Enterprise
|
303
354
|
|
304
355
|
To interact with the "regular" GitHub.com APIs in GitHub Enterprise, simply configure the `api_endpoint` to match your hostname. For example:
|
305
356
|
|
306
|
-
```
|
357
|
+
```ruby
|
307
358
|
Octokit.configure do |c|
|
308
359
|
c.api_endpoint = "https://<hostname>/api/v3/"
|
309
360
|
end
|
361
|
+
|
310
362
|
client = Octokit::Client.new(:access_token => "<your 40 char token>")
|
311
363
|
```
|
312
364
|
|
@@ -314,40 +366,45 @@ client = Octokit::Client.new(:access_token => "<your 40 char token>")
|
|
314
366
|
|
315
367
|
The GitHub Enterprise Admin APIs are under a different client: `EnterpriseAdminClient`. You'll need to have an administrator account in order to use these APIs.
|
316
368
|
|
317
|
-
```
|
318
|
-
admin_client = Octokit::EnterpriseAdminClient.new
|
319
|
-
|
320
|
-
|
369
|
+
```ruby
|
370
|
+
admin_client = Octokit::EnterpriseAdminClient.new(
|
371
|
+
:access_token => "<your 40 char token>",
|
372
|
+
:api_endpoint => "https://<hostname>/api/v3/"
|
373
|
+
)
|
321
374
|
|
322
375
|
# or
|
323
376
|
Octokit.configure do |c|
|
324
377
|
c.api_endpoint = "https://<hostname>/api/v3/"
|
325
378
|
c.access_token = "<your 40 char token>"
|
326
379
|
end
|
327
|
-
|
380
|
+
|
381
|
+
admin_client = Octokit.enterprise_admin_client.new
|
328
382
|
```
|
329
383
|
|
330
384
|
### Interacting with the GitHub Enterprise Management Console APIs
|
331
385
|
|
332
|
-
The GitHub Enterprise Management Console APIs are also under a separate client: `EnterpriseManagementConsoleClient`. In order to use it, you'll need to provide both your management console password as well as the endpoint to your management console. This is different
|
386
|
+
The GitHub Enterprise Management Console APIs are also under a separate client: `EnterpriseManagementConsoleClient`. In order to use it, you'll need to provide both your management console password as well as the endpoint to your management console. This is different from the API endpoint provided above.
|
387
|
+
|
388
|
+
```ruby
|
389
|
+
management_console_client = Octokit::EnterpriseManagementConsoleClient.new(
|
390
|
+
:management_console_password => "secret",
|
391
|
+
:management_console_endpoint = "https://hostname:8633"
|
392
|
+
)
|
333
393
|
|
334
|
-
``` ruby
|
335
|
-
management_console_client = Octokit::EnterpriseManagementConsoleClient.new \
|
336
|
-
:management_console_password => "secret",
|
337
|
-
:management_console_endpoint = "https://hostname:8633"
|
338
394
|
# or
|
339
395
|
Octokit.configure do |c|
|
340
396
|
c.management_console_endpoint = "https://hostname:8633"
|
341
397
|
c.management_console_password = "secret"
|
342
398
|
end
|
343
|
-
|
399
|
+
|
400
|
+
management_console_client = Octokit.enterprise_management_console_client.new
|
344
401
|
```
|
345
402
|
|
346
403
|
### SSL Connection Errors
|
347
404
|
|
348
|
-
You
|
405
|
+
You _may_ need to disable SSL temporarily while first setting up your GitHub Enterprise install. You can do that with the following configuration:
|
349
406
|
|
350
|
-
```
|
407
|
+
```ruby
|
351
408
|
client.connection_options[:ssl] = { :verify => false }
|
352
409
|
```
|
353
410
|
|
@@ -388,7 +445,7 @@ Octokit's default.
|
|
388
445
|
|
389
446
|
```ruby
|
390
447
|
# Given $OCTOKIT_API_ENDPOINT is "http://api.github.dev"
|
391
|
-
|
448
|
+
client.api_endpoint
|
392
449
|
|
393
450
|
# => "http://api.github.dev"
|
394
451
|
```
|
@@ -397,6 +454,28 @@ Deprecation warnings and API endpoints in development preview warnings are
|
|
397
454
|
printed to STDOUT by default, these can be disabled by setting the ENV
|
398
455
|
`OCTOKIT_SILENT=true`.
|
399
456
|
|
457
|
+
### Timeouts
|
458
|
+
|
459
|
+
By default, Octokit does not timeout network requests. To set a timeout, pass in Faraday timeout settings to Octokit's `connection_options` setting.
|
460
|
+
|
461
|
+
```ruby
|
462
|
+
Octokit.configure do |c|
|
463
|
+
c.api_endpoint = ENV.fetch('GITHUB_API_ENDPOINT', 'https://api.github.com/')
|
464
|
+
c.connection_options = {
|
465
|
+
request: {
|
466
|
+
open_timeout: 5,
|
467
|
+
timeout: 5
|
468
|
+
}
|
469
|
+
}
|
470
|
+
end
|
471
|
+
```
|
472
|
+
|
473
|
+
You should set a timeout in order to avoid Ruby’s Timeout module, which can hose your server. Here are some resources for more information on this:
|
474
|
+
|
475
|
+
- [The Oldest Bug In Ruby - Why Rack::Timeout Might Hose your Server](https://www.schneems.com/2017/02/21/the-oldest-bug-in-ruby-why-racktimeout-might-hose-your-server/)
|
476
|
+
- [Timeout: Ruby's Most Dangerous API](https://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/)
|
477
|
+
- [The Ultimate Guide to Ruby Timeouts](https://github.com/ankane/the-ultimate-guide-to-ruby-timeouts)
|
478
|
+
|
400
479
|
## Hypermedia agent
|
401
480
|
|
402
481
|
Starting in version 2.0, Octokit is [hypermedia][]-enabled. Under the hood,
|
@@ -408,7 +487,7 @@ Resources returned by Octokit methods contain not only data but hypermedia
|
|
408
487
|
link relations:
|
409
488
|
|
410
489
|
```ruby
|
411
|
-
user =
|
490
|
+
user = client.user 'technoweenie'
|
412
491
|
|
413
492
|
# Get the repos rel, returned from the API
|
414
493
|
# as repos_url in the resource
|
@@ -420,7 +499,7 @@ repos.last.name
|
|
420
499
|
# => "faraday-zeromq"
|
421
500
|
```
|
422
501
|
|
423
|
-
When processing API responses, all `*_url` attributes are culled
|
502
|
+
When processing API responses, all `*_url` attributes are culled into the link
|
424
503
|
relations collection. Any `url` attribute becomes `.rels[:self]`.
|
425
504
|
|
426
505
|
### URI templates
|
@@ -429,7 +508,7 @@ You might notice many link relations have variable placeholders. Octokit
|
|
429
508
|
supports [URI Templates][uri-templates] for parameterized URI expansion:
|
430
509
|
|
431
510
|
```ruby
|
432
|
-
repo =
|
511
|
+
repo = client.repo 'pengwynn/pingwynn'
|
433
512
|
rel = repo.rels[:issues]
|
434
513
|
# => #<Sawyer::Relation: issues: get https://api.github.com/repos/pengwynn/pingwynn/issues{/number}>
|
435
514
|
|
@@ -446,7 +525,7 @@ If you want to use Octokit as a pure hypermedia API client, you can start at
|
|
446
525
|
the API root and follow link relations from there:
|
447
526
|
|
448
527
|
```ruby
|
449
|
-
root =
|
528
|
+
root = client.root
|
450
529
|
root.rels[:repository].get :uri => {:owner => "octokit", :repo => "octokit.rb" }
|
451
530
|
root.rels[:user_repositories].get :uri => { :user => "octokit" },
|
452
531
|
:query => { :type => "owner" }
|
@@ -456,8 +535,8 @@ Octokit 3.0 aims to be hypermedia-driven, removing the internal URL
|
|
456
535
|
construction currently used throughout the client.
|
457
536
|
|
458
537
|
[hypermedia]: http://en.wikipedia.org/wiki/Hypermedia
|
459
|
-
[
|
460
|
-
[
|
538
|
+
[sawyer]: https://github.com/lostisland/sawyer
|
539
|
+
[faraday]: https://github.com/lostisland/faraday
|
461
540
|
[uri-templates]: http://tools.ietf.org/html/rfc6570
|
462
541
|
|
463
542
|
## Upgrading guide
|
@@ -465,8 +544,8 @@ construction currently used throughout the client.
|
|
465
544
|
Version 4.0
|
466
545
|
|
467
546
|
- **removes support for a [long-deprecated overload][list-pulls] for
|
468
|
-
passing state as a positional argument** when listing pull requests. Instead,
|
469
|
-
pass `state` in the method options.
|
547
|
+
passing state as a positional argument** when listing pull requests. Instead,
|
548
|
+
pass `state` in the method options.
|
470
549
|
- **drops support for Ruby < 2.0**.
|
471
550
|
- adds support for new [Enterprise-only APIs](#working-with-github-enterprise).
|
472
551
|
- adds support for [Repository redirects][redirects].
|
@@ -483,10 +562,11 @@ for the client:
|
|
483
562
|
```ruby
|
484
563
|
Octokit.default_media_type = "application/vnd.github.beta+json"
|
485
564
|
```
|
565
|
+
|
486
566
|
or per-request
|
487
567
|
|
488
568
|
```ruby
|
489
|
-
|
569
|
+
client.emails(:accept => "application/vnd.github.beta+json")
|
490
570
|
```
|
491
571
|
|
492
572
|
The long-deprecated `Octokit::Client#create_download` method has been removed.
|
@@ -499,21 +579,20 @@ Version 2.0 includes a completely rewritten `Client` factory that now memoizes
|
|
499
579
|
client instances based on unique configuration options. Breaking changes also
|
500
580
|
include:
|
501
581
|
|
502
|
-
|
503
|
-
|
504
|
-
|
582
|
+
- `:oauth_token` is now `:access_token`
|
583
|
+
- `:auto_traversal` is now `:auto_paginate`
|
584
|
+
- `Hashie::Mash` has been removed. Responses now return a `Sawyer::Resource`
|
505
585
|
object. This new type behaves mostly like a Ruby `Hash`, but does not fully
|
506
586
|
support the `Hashie::Mash` API.
|
507
|
-
|
587
|
+
- Two new client error types are raised where appropriate:
|
508
588
|
`Octokit::TooManyRequests` and `Octokit::TooManyLoginAttempts`
|
509
|
-
|
510
|
-
|
589
|
+
- The `search_*` methods from v1.x are now found at `legacy_search_*`
|
590
|
+
- Support for netrc requires including the [netrc gem][] in your Gemfile or
|
511
591
|
gemspec.
|
512
|
-
|
592
|
+
- DateTime fields are now proper `DateTime` objects. Previous versions outputted DateTime fields as 'String' objects.
|
513
593
|
|
514
594
|
[netrc gem]: https://rubygems.org/gems/netrc
|
515
595
|
|
516
|
-
|
517
596
|
## Advanced usage
|
518
597
|
|
519
598
|
Since Octokit employs [Faraday][faraday] under the hood, some behavior can be
|
@@ -527,13 +606,21 @@ traffic:
|
|
527
606
|
|
528
607
|
```ruby
|
529
608
|
stack = Faraday::RackBuilder.new do |builder|
|
530
|
-
builder.
|
609
|
+
builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError] # or Faraday::Request::Retry for Faraday < 2.0
|
610
|
+
builder.use Octokit::Middleware::FollowRedirects
|
531
611
|
builder.use Octokit::Response::RaiseError
|
612
|
+
builder.use Octokit::Response::FeedParser
|
613
|
+
builder.response :logger do |logger|
|
614
|
+
logger.filter(/(Authorization: "(token|Bearer) )(\w+)/, '\1[REMOVED]')
|
615
|
+
end
|
532
616
|
builder.adapter Faraday.default_adapter
|
533
617
|
end
|
534
618
|
Octokit.middleware = stack
|
535
|
-
|
619
|
+
|
620
|
+
client = Octokit::Client.new
|
621
|
+
client.user 'pengwynn'
|
536
622
|
```
|
623
|
+
|
537
624
|
```
|
538
625
|
I, [2013-08-22T15:54:38.583300 #88227] INFO -- : get https://api.github.com/users/pengwynn
|
539
626
|
D, [2013-08-22T15:54:38.583401 #88227] DEBUG -- request: Accept: "application/vnd.github.beta+json"
|
@@ -577,7 +664,6 @@ Once configured, the middleware will store responses in cache based on ETag
|
|
577
664
|
fingerprint and serve those back up for future `304` responses for the same
|
578
665
|
resource. See the [project README][cache] for advanced usage.
|
579
666
|
|
580
|
-
|
581
667
|
[cache]: https://github.com/plataformatec/faraday-http-cache
|
582
668
|
[faraday]: https://github.com/lostisland/faraday
|
583
669
|
|
@@ -593,8 +679,13 @@ to run a Ruby console to poke on Octokit, you can crank one up with:
|
|
593
679
|
|
594
680
|
script/console
|
595
681
|
|
596
|
-
Using the scripts in `./
|
597
|
-
|
682
|
+
Using the scripts in `./script` instead of `bundle exec rspec`, `bundle console`, etc. ensures your dependencies are up-to-date.
|
683
|
+
|
684
|
+
### Code of Conduct
|
685
|
+
|
686
|
+
We want both the Octokit.rb and larger Octokit communities to be open
|
687
|
+
and welcoming environments. Please read and follow both in spirit and
|
688
|
+
letter [Code of Conduct](CODE_OF_CONDUCT.md).
|
598
689
|
|
599
690
|
### Running and writing new tests
|
600
691
|
|
@@ -609,50 +700,52 @@ Octokit uses environmental variables for storing credentials used in testing.
|
|
609
700
|
If you are testing an API endpoint that doesn't require authentication, you
|
610
701
|
can get away without any additional configuration. For the most part, tests
|
611
702
|
use an authenticated client, using a token stored in `ENV['OCTOKIT_TEST_GITHUB_TOKEN']`.
|
612
|
-
There are several different
|
703
|
+
There are several different authentication methods used across the api.
|
613
704
|
Here is the full list of configurable environmental variables for testing
|
614
705
|
Octokit:
|
615
706
|
|
616
|
-
ENV Variable
|
617
|
-
|
618
|
-
`OCTOKIT_TEST_GITHUB_LOGIN
|
619
|
-
`OCTOKIT_TEST_GITHUB_PASSWORD
|
620
|
-
`OCTOKIT_TEST_GITHUB_TOKEN`
|
621
|
-
`OCTOKIT_TEST_GITHUB_CLIENT_ID`
|
622
|
-
`OCTOKIT_TEST_GITHUB_CLIENT_SECRET`
|
623
|
-
`OCTOKIT_TEST_GITHUB_REPOSITORY`
|
624
|
-
`OCTOKIT_TEST_GITHUB_ORGANIZATION`
|
625
|
-
`OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN`
|
626
|
-
`OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN`
|
627
|
-
`OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD` | GitHub Enterprise management console password
|
628
|
-
`OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT`
|
629
|
-
`OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT` | GitHub Enterprise Management Console endpoint
|
707
|
+
| ENV Variable | Description |
|
708
|
+
| :----------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
709
|
+
| `OCTOKIT_TEST_GITHUB_LOGIN` | GitHub login name (preferably one created specifically for testing against). |
|
710
|
+
| `OCTOKIT_TEST_GITHUB_PASSWORD` | Password for the test GitHub login. |
|
711
|
+
| `OCTOKIT_TEST_GITHUB_TOKEN` | [Personal Access Token](https://github.com/blog/1509-personal-api-tokens) for the test GitHub login. |
|
712
|
+
| `OCTOKIT_TEST_GITHUB_CLIENT_ID` | Test OAuth application client id. |
|
713
|
+
| `OCTOKIT_TEST_GITHUB_CLIENT_SECRET` | Test OAuth application client secret. |
|
714
|
+
| `OCTOKIT_TEST_GITHUB_REPOSITORY` | Test repository to perform destructive actions against, this should not be set to any repository of importance. **Automatically created by the test suite if nonexistent** Default: `api-sandbox` |
|
715
|
+
| `OCTOKIT_TEST_GITHUB_ORGANIZATION` | Test organization. |
|
716
|
+
| `OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN` | GitHub Enterprise login name. |
|
717
|
+
| `OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN` | GitHub Enterprise token. |
|
718
|
+
| `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD` | GitHub Enterprise management console password. |
|
719
|
+
| `OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT` | GitHub Enterprise hostname. |
|
720
|
+
| `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT` | GitHub Enterprise Management Console endpoint. |
|
721
|
+
| `OCTOKIT_TEST_GITHUB_INTEGRATION` | [GitHub Integration](https://developer.github.com/early-access/integrations/) owned by your test organization. |
|
722
|
+
| `OCTOKIT_TEST_GITHUB_INTEGRATION_INSTALLATION` | Installation of the GitHub Integration specified above. |
|
723
|
+
| `OCTOKIT_TEST_INTEGRATION_PEM_KEY` | File path to the private key generated from your integration. |
|
630
724
|
|
631
725
|
Since we periodically refresh our cassettes, please keep some points in mind
|
632
726
|
when writing new specs.
|
633
727
|
|
634
|
-
|
728
|
+
- **Specs should be idempotent**. The HTTP calls made during a spec should be
|
635
729
|
able to be run over and over. This means deleting a known resource prior to
|
636
730
|
creating it if the name has to be unique.
|
637
|
-
|
731
|
+
- **Specs should be able to be run in random order.** If a spec depends on
|
638
732
|
another resource as a fixture, make sure that's created in the scope of the
|
639
733
|
spec and not depend on a previous spec to create the data needed.
|
640
|
-
|
734
|
+
- **Do not depend on authenticated user info.** Instead of asserting
|
641
735
|
actual values in resources, try to assert the existence of a key or that a
|
642
736
|
response is an Array. We're testing the client, not the API.
|
643
737
|
|
644
738
|
[bootstrapping]: http://wynnnetherland.com/linked/2013012801/bootstrapping-consistency
|
645
|
-
[
|
739
|
+
[vcr]: https://github.com/vcr/vcr
|
646
740
|
|
647
741
|
## Supported Ruby Versions
|
648
742
|
|
649
|
-
This library aims to support and is [tested against][
|
743
|
+
This library aims to support and is [tested against][actions] the following Ruby
|
650
744
|
implementations:
|
651
745
|
|
652
|
-
* Ruby 2.
|
653
|
-
* Ruby
|
654
|
-
* Ruby
|
655
|
-
* Ruby 2.3
|
746
|
+
* Ruby 2.7
|
747
|
+
* Ruby 3.0
|
748
|
+
* Ruby 3.1
|
656
749
|
|
657
750
|
If something doesn't work on one of these Ruby versions, it's a bug.
|
658
751
|
|
@@ -667,7 +760,7 @@ implementation, you will be responsible for providing patches in a timely
|
|
667
760
|
fashion. If critical issues for a particular implementation exist at the time
|
668
761
|
of a major release, support for that Ruby version may be dropped.
|
669
762
|
|
670
|
-
[
|
763
|
+
[actions]: https://github.com/octokit/octokit.rb/actions
|
671
764
|
|
672
765
|
## Versioning
|
673
766
|
|
@@ -688,6 +781,22 @@ The changes made between versions can be seen on the [project releases page][rel
|
|
688
781
|
[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
689
782
|
[releases]: https://github.com/octokit/octokit.rb/releases
|
690
783
|
|
784
|
+
## Making Repeating Requests
|
785
|
+
|
786
|
+
In most cases it would be best to use [webhooks](https://developer.github.com/webhooks/), but sometimes webhooks don't provide all of the information needed. In those cases where one might need to poll for progress or retry a request on failure, we designed [Octopoller](https://github.com/octokit/octopoller.rb). Octopoller is a micro gem perfect for making repeating requests.
|
787
|
+
|
788
|
+
```ruby
|
789
|
+
Octopoller.poll(timeout: 15.seconds) do
|
790
|
+
begin
|
791
|
+
client.request_progress # ex. request a long running job's status
|
792
|
+
rescue Error
|
793
|
+
:re_poll
|
794
|
+
end
|
795
|
+
end
|
796
|
+
```
|
797
|
+
|
798
|
+
This is useful when making requests for a long running job's progress (ex. requesting a [Source Import's progress](https://developer.github.com/v3/migrations/source_imports/#get-import-progress)).
|
799
|
+
|
691
800
|
## License
|
692
801
|
|
693
802
|
Copyright (c) 2009-2014 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober
|