octokit 4.20.0 → 4.23.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of octokit might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66d0ffe1bcb61d7c4661b0eed991cf4d8bc84c8d0460fe508f064bfc42e08bdf
4
- data.tar.gz: fd2d7fb934734c88577d07c719ebdba6b8585738fb8e329a05b35e010b6b6b51
3
+ metadata.gz: 7abf6a2c9179b01ec754c12ea122c53010ce0cedc46631e3a3a725daec1ed409
4
+ data.tar.gz: 13e23b71f45c6a36f330221d6bb9ee0769974ca77f07c32138262c65f84b59d7
5
5
  SHA512:
6
- metadata.gz: 795b13dc5aa33251042cb0a216e547c9f39fc063ee7ae0f0c009a50838459cb9da52bdd3dcb3883207173bd1fb19c922d86fd74380c8aa02cf51807f8c3420b0
7
- data.tar.gz: ebe0c7d8d8290aa2a3ad6b55b27d7bd23eff2c0b4f479654aeac2eb5b760cd00174fea8ffcc3ebb5a7bfb4375690fb9096aa74c282780b260a480e23d1a06752
6
+ metadata.gz: ae5965ed9aa64796fdb7073c9d2ea4d977df22dd428f21674504e6a46b32b743a63b8e22ad53991b6b0db5cc8eb0586250f733f7bd6e30ca11d632960b44d75c
7
+ data.tar.gz: e50fb32abc9045813a533bd28e8b69890d9fdac9f8fe05fca37f1064f14708c654fe0086d78172fb9ab134ab35fcedbd5d58867c54d6c8bfa651a143d38a6fb4
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Ruby toolkit for the GitHub API.
4
4
 
5
- ![logo](http://cl.ly/image/3Y013H0A2z3z/gundam-ruby.png)
5
+ ![logo](https://docs.github.com/assets/images/gundamcat.png)
6
6
 
7
7
  Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
8
8
  [major version][semver].
@@ -10,23 +10,25 @@ Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
10
10
  ## Table of Contents
11
11
 
12
12
  1. [Philosophy](#philosophy)
13
- 2. [Quick start](#quick-start)
13
+ 2. [Installation](#quick-start)
14
14
  3. [Making requests](#making-requests)
15
+ 1. [Additional Query Parameters](#additional-query-parameters)
15
16
  4. [Consuming resources](#consuming-resources)
16
17
  5. [Accessing HTTP responses](#accessing-http-responses)
17
- 6. [Authentication](#authentication)
18
+ 6. [Handling errors](#handling-errors)
19
+ 7. [Authentication](#authentication)
18
20
  1. [Basic Authentication](#basic-authentication)
19
21
  2. [OAuth access tokens](#oauth-access-tokens)
20
22
  3. [Two-Factor Authentication](#two-factor-authentication)
21
23
  4. [Using a .netrc file](#using-a-netrc-file)
22
24
  5. [Application authentication](#application-authentication)
23
- 7. [Pagination](#pagination)
25
+ 8. [Pagination](#pagination)
24
26
  1. [Auto pagination](#auto-pagination)
25
- 8. [Working with GitHub Enterprise](#working-with-github-enterprise)
27
+ 9. [Working with GitHub Enterprise](#working-with-github-enterprise)
26
28
  1. [Interacting with the GitHub.com APIs in GitHub Enterprise](#interacting-with-the-githubcom-apis-in-github-enterprise)
27
29
  2. [Interacting with the GitHub Enterprise Admin APIs](#interacting-with-the-github-enterprise-admin-apis)
28
30
  3. [Interacting with the GitHub Enterprise Management Console APIs](#interacting-with-the-github-enterprise-management-console-apis)
29
- 9. [SSL Connection Errors](#ssl-connection-errors)
31
+ 4. [SSL Connection Errors](#ssl-connection-errors)
30
32
  10. [Configuration and defaults](#configuration-and-defaults)
31
33
  1. [Configuring module defaults](#configuring-module-defaults)
32
34
  2. [Using ENV variables](#using-env-variables)
@@ -66,7 +68,7 @@ client.readme 'al3x/sovereign', :accept => 'application/vnd.github.html'
66
68
  [wrappers]: http://wynnnetherland.com/journal/what-makes-a-good-api-wrapper
67
69
  [github-api]: https://developer.github.com/v3/
68
70
 
69
- ## Quick start
71
+ ## Installation
70
72
 
71
73
  Install via Rubygems
72
74
 
@@ -80,22 +82,22 @@ Access the library in Ruby:
80
82
 
81
83
  require 'octokit'
82
84
 
83
- ### Making requests
85
+ ## Making requests
84
86
 
85
87
  [API methods][] are available as client instance methods.
86
88
 
87
89
  ```ruby
88
90
  # Provide authentication credentials
89
- client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!')
91
+ client = Octokit::Client.new(:access_token => 'personal_access_token')
90
92
 
91
- # Set access_token instead of login and password if you use personal access token
92
- # client = Octokit::Client.new(:access_token => '[personal_access_token]!')
93
+ # You can still use the username/password syntax by replacing the password value with your PAT.
94
+ # client = Octokit::Client.new(:login => 'defunkt', :password => 'personal_access_token')
93
95
 
94
96
  # Fetch the current user
95
97
  client.user
96
98
  ```
97
99
 
98
- ### Additional Query Parameters
100
+ ### Additional query parameters
99
101
 
100
102
  When passing additional parameters to GET based request use the following syntax:
101
103
 
@@ -109,9 +111,9 @@ When passing additional parameters to GET based request use the following syntax
109
111
  client.contents('octokit/octokit.rb', path: 'path/to/file.rb', query: {ref: 'some-other-branch'})
110
112
  ```
111
113
 
112
- [API methods]: http://octokit.github.io/octokit.rb/method_list.html
114
+ [api methods]: http://octokit.github.io/octokit.rb/method_list.html
113
115
 
114
- ### Consuming resources
116
+ ## Consuming resources
115
117
 
116
118
  Most methods return a `Resource` object which provides dot notation and `[]`
117
119
  access for fields returned in the API response.
@@ -134,7 +136,7 @@ user.rels[:gists].href
134
136
  **Note:** URL fields are culled into a separate `.rels` collection for easier
135
137
  [Hypermedia](#hypermedia-agent) support.
136
138
 
137
- ### Accessing HTTP responses
139
+ ## Accessing HTTP responses
138
140
 
139
141
  While most methods return a `Resource` object or a Boolean, sometimes you may
140
142
  need access to the raw HTTP response headers. You can access the last HTTP
@@ -146,6 +148,23 @@ response = client.last_response
146
148
  etag = response.headers[:etag]
147
149
  ```
148
150
 
151
+ ## Handling errors
152
+
153
+ When the API returns an error response, Octokit will raise a Ruby exception.
154
+
155
+ A range of different exceptions can be raised depending on the error returned
156
+ by the API - for example:
157
+
158
+ * A `400 Bad Request` response will lead to an `Octokit::BadRequest` error
159
+ * A `403 Forbidden` error with a "rate limited exceeded" message will lead
160
+ to a `Octokit::TooManyRequests` error
161
+
162
+ All of the different exception classes inherit from `Octokit::Error` and
163
+ expose the `#response_status`, `#response_headers` and `#response_body`.
164
+ For validation errors, `#errors` will return an `Array` of `Hash`es
165
+ with the detailed information
166
+ [returned by the API](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#client-errors).
167
+
149
168
  ## Authentication
150
169
 
151
170
  Octokit supports the various [authentication methods supported by the GitHub
@@ -163,6 +182,7 @@ user = client.user
163
182
  user.login
164
183
  # => "defunkt"
165
184
  ```
185
+
166
186
  While Basic Authentication allows you to get started quickly, OAuth access
167
187
  tokens are the preferred way to authenticate on behalf of users.
168
188
 
@@ -171,9 +191,9 @@ tokens are the preferred way to authenticate on behalf of users.
171
191
  [OAuth access tokens][oauth] provide two main benefits over using your username
172
192
  and password:
173
193
 
174
- * **Revokable access**. Access tokens can be revoked, removing access for only
194
+ - **Revocable access**. Access tokens can be revoked, removing access for only
175
195
  that token without having to change your password everywhere.
176
- * **Limited access**. Access tokens have [access scopes][] which allow for more
196
+ - **Limited access**. Access tokens have [access scopes][] which allow for more
177
197
  granular access to API resources. For instance, you can grant a third party
178
198
  access to your gists but not your private repositories.
179
199
 
@@ -212,7 +232,7 @@ client = Octokit::Client.new \
212
232
  user = client.user("defunkt", :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
213
233
  ```
214
234
 
215
- As you can imagine, this gets annoying quick 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:
235
+ 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:
216
236
 
217
237
  ```ruby
218
238
  client = Octokit::Client.new \
@@ -227,13 +247,14 @@ client.create_authorization(:scopes => ["user"], :note => "Name of token",
227
247
  ### Using a .netrc file
228
248
 
229
249
  Octokit supports reading credentials from a netrc file (defaulting to
230
- `~/.netrc`). Given these lines in your netrc:
250
+ `~/.netrc`). Given these lines in your netrc:
231
251
 
232
252
  ```
233
253
  machine api.github.com
234
254
  login defunkt
235
255
  password c0d3b4ssssss!
236
256
  ```
257
+
237
258
  You can now create a client with those credentials:
238
259
 
239
260
  ```ruby
@@ -241,6 +262,7 @@ client = Octokit::Client.new(:netrc => true)
241
262
  client.login
242
263
  # => "defunkt"
243
264
  ```
265
+
244
266
  But _I want to use OAuth_ you say. Since the GitHub API supports using an OAuth
245
267
  token as a Basic password, you totally can:
246
268
 
@@ -323,13 +345,13 @@ custom pattern for traversing large lists.
323
345
 
324
346
  ## Working with GitHub Enterprise
325
347
 
326
- With a bit of setup, you can also use Octokit with your Github Enterprise instance.
348
+ With a bit of setup, you can also use Octokit with your GitHub Enterprise instance.
327
349
 
328
350
  ### Interacting with the GitHub.com APIs in GitHub Enterprise
329
351
 
330
352
  To interact with the "regular" GitHub.com APIs in GitHub Enterprise, simply configure the `api_endpoint` to match your hostname. For example:
331
353
 
332
- ``` ruby
354
+ ```ruby
333
355
  Octokit.configure do |c|
334
356
  c.api_endpoint = "https://<hostname>/api/v3/"
335
357
  end
@@ -341,7 +363,7 @@ client = Octokit::Client.new(:access_token => "<your 40 char token>")
341
363
 
342
364
  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.
343
365
 
344
- ``` ruby
366
+ ```ruby
345
367
  admin_client = Octokit::EnterpriseAdminClient.new(
346
368
  :access_token => "<your 40 char token>",
347
369
  :api_endpoint => "https://<hostname>/api/v3/"
@@ -358,9 +380,9 @@ admin_client = Octokit.enterprise_admin_client.new
358
380
 
359
381
  ### Interacting with the GitHub Enterprise Management Console APIs
360
382
 
361
- 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 than the API endpoint provided above.
383
+ 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.
362
384
 
363
- ``` ruby
385
+ ```ruby
364
386
  management_console_client = Octokit::EnterpriseManagementConsoleClient.new(
365
387
  :management_console_password => "secret",
366
388
  :management_console_endpoint = "https://hostname:8633"
@@ -377,9 +399,9 @@ management_console_client = Octokit.enterprise_management_console_client.new
377
399
 
378
400
  ### SSL Connection Errors
379
401
 
380
- You *may* need to disable SSL temporarily while first setting up your GitHub Enterprise install. You can do that with the following configuration:
402
+ You _may_ need to disable SSL temporarily while first setting up your GitHub Enterprise install. You can do that with the following configuration:
381
403
 
382
- ``` ruby
404
+ ```ruby
383
405
  client.connection_options[:ssl] = { :verify => false }
384
406
  ```
385
407
 
@@ -444,6 +466,7 @@ Octokit.configure do |c|
444
466
  }
445
467
  end
446
468
  ```
469
+
447
470
  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:
448
471
 
449
472
  - [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/)
@@ -473,7 +496,7 @@ repos.last.name
473
496
  # => "faraday-zeromq"
474
497
  ```
475
498
 
476
- When processing API responses, all `*_url` attributes are culled in to the link
499
+ When processing API responses, all `*_url` attributes are culled into the link
477
500
  relations collection. Any `url` attribute becomes `.rels[:self]`.
478
501
 
479
502
  ### URI templates
@@ -509,8 +532,8 @@ Octokit 3.0 aims to be hypermedia-driven, removing the internal URL
509
532
  construction currently used throughout the client.
510
533
 
511
534
  [hypermedia]: http://en.wikipedia.org/wiki/Hypermedia
512
- [Sawyer]: https://github.com/lostisland/sawyer
513
- [Faraday]: https://github.com/lostisland/faraday
535
+ [sawyer]: https://github.com/lostisland/sawyer
536
+ [faraday]: https://github.com/lostisland/faraday
514
537
  [uri-templates]: http://tools.ietf.org/html/rfc6570
515
538
 
516
539
  ## Upgrading guide
@@ -518,8 +541,8 @@ construction currently used throughout the client.
518
541
  Version 4.0
519
542
 
520
543
  - **removes support for a [long-deprecated overload][list-pulls] for
521
- passing state as a positional argument** when listing pull requests. Instead,
522
- pass `state` in the method options.
544
+ passing state as a positional argument** when listing pull requests. Instead,
545
+ pass `state` in the method options.
523
546
  - **drops support for Ruby < 2.0**.
524
547
  - adds support for new [Enterprise-only APIs](#working-with-github-enterprise).
525
548
  - adds support for [Repository redirects][redirects].
@@ -536,6 +559,7 @@ for the client:
536
559
  ```ruby
537
560
  Octokit.default_media_type = "application/vnd.github.beta+json"
538
561
  ```
562
+
539
563
  or per-request
540
564
 
541
565
  ```ruby
@@ -552,21 +576,20 @@ Version 2.0 includes a completely rewritten `Client` factory that now memoizes
552
576
  client instances based on unique configuration options. Breaking changes also
553
577
  include:
554
578
 
555
- * `:oauth_token` is now `:access_token`
556
- * `:auto_traversal` is now `:auto_paginate`
557
- * `Hashie::Mash` has been removed. Responses now return a `Sawyer::Resource`
579
+ - `:oauth_token` is now `:access_token`
580
+ - `:auto_traversal` is now `:auto_paginate`
581
+ - `Hashie::Mash` has been removed. Responses now return a `Sawyer::Resource`
558
582
  object. This new type behaves mostly like a Ruby `Hash`, but does not fully
559
583
  support the `Hashie::Mash` API.
560
- * Two new client error types are raised where appropriate:
584
+ - Two new client error types are raised where appropriate:
561
585
  `Octokit::TooManyRequests` and `Octokit::TooManyLoginAttempts`
562
- * The `search_*` methods from v1.x are now found at `legacy_search_*`
563
- * Support for netrc requires including the [netrc gem][] in your Gemfile or
586
+ - The `search_*` methods from v1.x are now found at `legacy_search_*`
587
+ - Support for netrc requires including the [netrc gem][] in your Gemfile or
564
588
  gemspec.
565
- * DateTime fields are now proper `DateTime` objects. Previous versions outputted DateTime fields as 'String' objects.
589
+ - DateTime fields are now proper `DateTime` objects. Previous versions outputted DateTime fields as 'String' objects.
566
590
 
567
591
  [netrc gem]: https://rubygems.org/gems/netrc
568
592
 
569
-
570
593
  ## Advanced usage
571
594
 
572
595
  Since Octokit employs [Faraday][faraday] under the hood, some behavior can be
@@ -580,11 +603,13 @@ traffic:
580
603
 
581
604
  ```ruby
582
605
  stack = Faraday::RackBuilder.new do |builder|
583
- builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError]
606
+ builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError] # or Faraday::Request::Retry for Faraday < 2.0
584
607
  builder.use Octokit::Middleware::FollowRedirects
585
608
  builder.use Octokit::Response::RaiseError
586
609
  builder.use Octokit::Response::FeedParser
587
- builder.response :logger
610
+ builder.response :logger do |logger|
611
+ logger.filter(/(Authorization: "(token|Bearer) )(\w+)/, '\1[REMOVED]')
612
+ end
588
613
  builder.adapter Faraday.default_adapter
589
614
  end
590
615
  Octokit.middleware = stack
@@ -592,6 +617,7 @@ Octokit.middleware = stack
592
617
  client = Octokit::Client.new
593
618
  client.user 'pengwynn'
594
619
  ```
620
+
595
621
  ```
596
622
  I, [2013-08-22T15:54:38.583300 #88227] INFO -- : get https://api.github.com/users/pengwynn
597
623
  D, [2013-08-22T15:54:38.583401 #88227] DEBUG -- request: Accept: "application/vnd.github.beta+json"
@@ -635,7 +661,6 @@ Once configured, the middleware will store responses in cache based on ETag
635
661
  fingerprint and serve those back up for future `304` responses for the same
636
662
  resource. See the [project README][cache] for advanced usage.
637
663
 
638
-
639
664
  [cache]: https://github.com/plataformatec/faraday-http-cache
640
665
  [faraday]: https://github.com/lostisland/faraday
641
666
 
@@ -651,12 +676,11 @@ to run a Ruby console to poke on Octokit, you can crank one up with:
651
676
 
652
677
  script/console
653
678
 
654
- Using the scripts in `./script` instead of `bundle exec rspec`, `bundle
655
- console`, etc. ensures your dependencies are up-to-date.
679
+ Using the scripts in `./script` instead of `bundle exec rspec`, `bundle console`, etc. ensures your dependencies are up-to-date.
656
680
 
657
681
  ### Code of Conduct
658
682
 
659
- We want both the Octokit.rb and larger Octokit communities to be an open
683
+ We want both the Octokit.rb and larger Octokit communities to be open
660
684
  and welcoming environments. Please read and follow both in spirit and
661
685
  letter [Code of Conduct](CODE_OF_CONDUCT.md).
662
686
 
@@ -673,43 +697,43 @@ Octokit uses environmental variables for storing credentials used in testing.
673
697
  If you are testing an API endpoint that doesn't require authentication, you
674
698
  can get away without any additional configuration. For the most part, tests
675
699
  use an authenticated client, using a token stored in `ENV['OCTOKIT_TEST_GITHUB_TOKEN']`.
676
- There are several different authenticating method's used across the api.
700
+ There are several different authentication methods used across the api.
677
701
  Here is the full list of configurable environmental variables for testing
678
702
  Octokit:
679
703
 
680
- ENV Variable | Description |
681
- :-------------------|:-----------------|
682
- `OCTOKIT_TEST_GITHUB_LOGIN`| GitHub login name (preferably one created specifically for testing against).
683
- `OCTOKIT_TEST_GITHUB_PASSWORD`| Password for the test GitHub login.
684
- `OCTOKIT_TEST_GITHUB_TOKEN` | [Personal Access Token](https://github.com/blog/1509-personal-api-tokens) for the test GitHub login.
685
- `OCTOKIT_TEST_GITHUB_CLIENT_ID` | Test OAuth application client id.
686
- `OCTOKIT_TEST_GITHUB_CLIENT_SECRET` | Test OAuth application client secret.
687
- `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`
688
- `OCTOKIT_TEST_GITHUB_ORGANIZATION` | Test organization.
689
- `OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN` | GitHub Enterprise login name.
690
- `OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN` | GitHub Enterprise token.
691
- `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD` | GitHub Enterprise management console password.
692
- `OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT` | GitHub Enterprise hostname.
693
- `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT` | GitHub Enterprise Management Console endpoint.
694
- `OCTOKIT_TEST_GITHUB_INTEGRATION` | [GitHub Integration](https://developer.github.com/early-access/integrations/) owned by your test organization.
695
- `OCTOKIT_TEST_GITHUB_INTEGRATION_INSTALLATION` | Installation of the GitHub Integration specified above.
696
- `OCTOKIT_TEST_INTEGRATION_PEM_KEY` | File path to the private key generated from your integration.
704
+ | ENV Variable | Description |
705
+ | :----------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
706
+ | `OCTOKIT_TEST_GITHUB_LOGIN` | GitHub login name (preferably one created specifically for testing against). |
707
+ | `OCTOKIT_TEST_GITHUB_PASSWORD` | Password for the test GitHub login. |
708
+ | `OCTOKIT_TEST_GITHUB_TOKEN` | [Personal Access Token](https://github.com/blog/1509-personal-api-tokens) for the test GitHub login. |
709
+ | `OCTOKIT_TEST_GITHUB_CLIENT_ID` | Test OAuth application client id. |
710
+ | `OCTOKIT_TEST_GITHUB_CLIENT_SECRET` | Test OAuth application client secret. |
711
+ | `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` |
712
+ | `OCTOKIT_TEST_GITHUB_ORGANIZATION` | Test organization. |
713
+ | `OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN` | GitHub Enterprise login name. |
714
+ | `OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN` | GitHub Enterprise token. |
715
+ | `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD` | GitHub Enterprise management console password. |
716
+ | `OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT` | GitHub Enterprise hostname. |
717
+ | `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT` | GitHub Enterprise Management Console endpoint. |
718
+ | `OCTOKIT_TEST_GITHUB_INTEGRATION` | [GitHub Integration](https://developer.github.com/early-access/integrations/) owned by your test organization. |
719
+ | `OCTOKIT_TEST_GITHUB_INTEGRATION_INSTALLATION` | Installation of the GitHub Integration specified above. |
720
+ | `OCTOKIT_TEST_INTEGRATION_PEM_KEY` | File path to the private key generated from your integration. |
697
721
 
698
722
  Since we periodically refresh our cassettes, please keep some points in mind
699
723
  when writing new specs.
700
724
 
701
- * **Specs should be idempotent**. The HTTP calls made during a spec should be
725
+ - **Specs should be idempotent**. The HTTP calls made during a spec should be
702
726
  able to be run over and over. This means deleting a known resource prior to
703
727
  creating it if the name has to be unique.
704
- * **Specs should be able to be run in random order.** If a spec depends on
728
+ - **Specs should be able to be run in random order.** If a spec depends on
705
729
  another resource as a fixture, make sure that's created in the scope of the
706
730
  spec and not depend on a previous spec to create the data needed.
707
- * **Do not depend on authenticated user info.** Instead of asserting
731
+ - **Do not depend on authenticated user info.** Instead of asserting
708
732
  actual values in resources, try to assert the existence of a key or that a
709
733
  response is an Array. We're testing the client, not the API.
710
734
 
711
735
  [bootstrapping]: http://wynnnetherland.com/linked/2013012801/bootstrapping-consistency
712
- [VCR]: https://github.com/vcr/vcr
736
+ [vcr]: https://github.com/vcr/vcr
713
737
 
714
738
  ## Supported Ruby Versions
715
739
 
@@ -719,6 +743,8 @@ implementations:
719
743
  * Ruby 2.5
720
744
  * Ruby 2.6
721
745
  * Ruby 2.7
746
+ * Ruby 3.0
747
+ * Ruby 3.1
722
748
 
723
749
  If something doesn't work on one of these Ruby versions, it's a bug.
724
750
 
@@ -755,7 +781,8 @@ The changes made between versions can be seen on the [project releases page][rel
755
781
  [releases]: https://github.com/octokit/octokit.rb/releases
756
782
 
757
783
  ## Making Repeating Requests
758
- In most cases it would be best to use a [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.
784
+
785
+ 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.
759
786
 
760
787
  ```ruby
761
788
  Octopoller.poll(timeout: 15.seconds) do
@@ -3,6 +3,14 @@ module Octokit
3
3
  # Authentication methods for {Octokit::Client}
4
4
  module Authentication
5
5
 
6
+ # In Faraday 2.x, the authorization middleware uses new interface
7
+ FARADAY_BASIC_AUTH_KEYS =
8
+ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
9
+ [:authorization, :basic]
10
+ else
11
+ [:basic_auth]
12
+ end
13
+
6
14
  # Indicates if the client was supplied Basic Auth
7
15
  # username and password
8
16
  #
@@ -65,6 +65,17 @@ module Octokit
65
65
  boolean_from_response :post, "#{Repository.path repo}/actions/runs/#{id}/cancel", options
66
66
  end
67
67
 
68
+ # Deletes a workflow run
69
+ #
70
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
71
+ # @param id [Integer] Id of a workflow run
72
+ #
73
+ # @return [Boolean] Returns true if the run is deleted
74
+ # @see https://docs.github.com/en/rest/reference/actions#delete-a-workflow-run
75
+ def delete_workflow_run(repo, id, options = {})
76
+ boolean_from_response :delete, "#{Repository.path repo}/actions/runs/#{id}", options
77
+ end
78
+
68
79
  # Get a download url for archived log files of a workflow run
69
80
  #
70
81
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
@@ -215,8 +215,7 @@ module Octokit
215
215
  #
216
216
  # @return [Boolean] Success
217
217
  def delete_installation(installation, options = {})
218
- opts = ensure_api_media_type(:uninstall_github_app, options)
219
- boolean_from_response :delete, "app/installations/#{installation}", opts
218
+ boolean_from_response :delete, "app/installations/#{installation}", options
220
219
  end
221
220
  end
222
221
  end
@@ -23,7 +23,6 @@ module Octokit
23
23
  # check_run.head_sha # => "7638417db6d59f3c431d3e1f261cc637155684cd"
24
24
  # check_run.status # => "queued"
25
25
  def create_check_run(repo, name, head_sha, options = {})
26
- ensure_api_media_type(:checks, options)
27
26
  options[:name] = name
28
27
  options[:head_sha] = head_sha
29
28
 
@@ -41,8 +40,6 @@ module Octokit
41
40
  # check_run.id # => 51295429
42
41
  # check_run.status # => "in_progress"
43
42
  def update_check_run(repo, id, options = {})
44
- ensure_api_media_type(:checks, options)
45
-
46
43
  patch "#{Repository.path repo}/check-runs/#{id}", options
47
44
  end
48
45
 
@@ -63,9 +60,10 @@ module Octokit
63
60
  # result.check_runs[0].id # => 51295429
64
61
  # result.check_runs[0].status # => "in_progress"
65
62
  def check_runs_for_ref(repo, ref, options = {})
66
- ensure_api_media_type(:checks, options)
67
-
68
- get "#{Repository.path repo}/commits/#{ref}/check-runs", options
63
+ paginate "#{Repository.path repo}/commits/#{ref}/check-runs", options do |data, last_response|
64
+ data.check_runs.concat last_response.data.check_runs
65
+ data.total_count += last_response.data.total_count
66
+ end
69
67
  end
70
68
  alias :list_check_runs_for_ref :check_runs_for_ref
71
69
 
@@ -86,9 +84,10 @@ module Octokit
86
84
  # result.check_runs[0].check_suite.id # => 50440400
87
85
  # result.check_runs[0].status # => "in_progress"
88
86
  def check_runs_for_check_suite(repo, id, options = {})
89
- ensure_api_media_type(:checks, options)
90
-
91
- get "#{Repository.path repo}/check-suites/#{id}/check-runs", options
87
+ paginate "#{Repository.path repo}/check-suites/#{id}/check-runs", options do |data, last_response|
88
+ data.check_runs.concat last_response.data.check_runs
89
+ data.total_count += last_response.data.total_count
90
+ end
92
91
  end
93
92
  alias :list_check_runs_for_check_suite :check_runs_for_check_suite
94
93
 
@@ -99,8 +98,6 @@ module Octokit
99
98
  # @return [Sawyer::Resource] A hash representing the check run
100
99
  # @see https://developer.github.com/v3/checks/runs/#get-a-single-check-run
101
100
  def check_run(repo, id, options = {})
102
- ensure_api_media_type(:checks, options)
103
-
104
101
  get "#{Repository.path repo}/check-runs/#{id}", options
105
102
  end
106
103
 
@@ -116,9 +113,7 @@ module Octokit
116
113
  # annotations[0].path # => "README.md"
117
114
  # annotations[0].message # => "Looks good!"
118
115
  def check_run_annotations(repo, id, options = {})
119
- ensure_api_media_type(:checks, options)
120
-
121
- get "#{Repository.path repo}/check-runs/#{id}/annotations", options
116
+ paginate "#{Repository.path repo}/check-runs/#{id}/annotations", options
122
117
  end
123
118
 
124
119
  # Methods for Check Suites
@@ -132,8 +127,6 @@ module Octokit
132
127
  # @return [Sawyer::Resource] A hash representing the check suite
133
128
  # @see https://developer.github.com/v3/checks/suites/#get-a-single-check-suite
134
129
  def check_suite(repo, id, options = {})
135
- ensure_api_media_type(:checks, options)
136
-
137
130
  get "#{Repository.path repo}/check-suites/#{id}", options
138
131
  end
139
132
 
@@ -153,9 +146,10 @@ module Octokit
153
146
  # result.check_suites[0].id # => 50440400
154
147
  # result.check_suites[0].app.id # => 76765
155
148
  def check_suites_for_ref(repo, ref, options = {})
156
- ensure_api_media_type(:checks, options)
157
-
158
- get "#{Repository.path repo}/commits/#{ref}/check-suites", options
149
+ paginate "#{Repository.path repo}/commits/#{ref}/check-suites", options do |data, last_response|
150
+ data.check_suites.concat last_response.data.check_suites
151
+ data.total_count += last_response.data.total_count
152
+ end
159
153
  end
160
154
  alias :list_check_suites_for_ref :check_suites_for_ref
161
155
 
@@ -172,8 +166,6 @@ module Octokit
172
166
  # result.preferences.auto_trigger_checks[0].setting # => false
173
167
  # result.repository.full_name # => "octocat/Hello-World"
174
168
  def set_check_suite_preferences(repo, options = {})
175
- ensure_api_media_type(:checks, options)
176
-
177
169
  patch "#{Repository.path repo}/check-suites/preferences", options
178
170
  end
179
171
 
@@ -188,7 +180,6 @@ module Octokit
188
180
  # check_suite.head_sha # => "7638417db6d59f3c431d3e1f261cc637155684cd"
189
181
  # check_suite.status # => "queued"
190
182
  def create_check_suite(repo, head_sha, options = {})
191
- ensure_api_media_type(:checks, options)
192
183
  options[:head_sha] = head_sha
193
184
 
194
185
  post "#{Repository.path repo}/check-suites", options
@@ -201,8 +192,6 @@ module Octokit
201
192
  # @return [Boolean] True if successful, raises an error otherwise
202
193
  # @see https://developer.github.com/v3/checks/suites/#rerequest-check-suite
203
194
  def rerequest_check_suite(repo, id, options = {})
204
- ensure_api_media_type(:checks, options)
205
-
206
195
  post "#{Repository.path repo}/check-suites/#{id}/rerequest", options
207
196
  true
208
197
  end
@@ -189,13 +189,18 @@ module Octokit
189
189
 
190
190
  # Compare two commits
191
191
  #
192
+ # When using auto_pagination, commits from all pages will be concatenated
193
+ # into the <tt>commits</tt> attribute of the first page's response.
194
+ #
192
195
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
193
196
  # @param start [String] The sha of the starting commit
194
197
  # @param endd [String] The sha of the ending commit
195
198
  # @return [Sawyer::Resource] A hash representing the comparison
196
199
  # @see https://developer.github.com/v3/repos/commits/#compare-two-commits
197
200
  def compare(repo, start, endd, options = {})
198
- get "#{Repository.path repo}/compare/#{start}...#{endd}", options
201
+ paginate "#{Repository.path repo}/compare/#{start}...#{endd}", options do |data, last_response|
202
+ data.commits.concat last_response.data.commits
203
+ end
199
204
  end
200
205
 
201
206
  # Merge a branch or sha
@@ -156,7 +156,7 @@ module Octokit
156
156
  # @example Get archive link for octokit/octokit.rb
157
157
  # Octokit.archive_link("octokit/octokit.rb")
158
158
  def archive_link(repo, options={})
159
- repo_ref = options.delete :ref
159
+ repo_ref = ERB::Util.url_encode(options.delete :ref)
160
160
  format = (options.delete :format) || 'tarball'
161
161
  url = "#{Repository.path repo}/#{format}/#{repo_ref}"
162
162
 
@@ -1,4 +1,4 @@
1
- require 'cgi'
1
+ require "erb"
2
2
 
3
3
  module Octokit
4
4
  class Client
@@ -28,7 +28,7 @@ module Octokit
28
28
  # @example Get the "V3 Addition" label from octokit/octokit.rb
29
29
  # Octokit.label("octokit/octokit.rb", "V3 Addition")
30
30
  def label(repo, name, options = {})
31
- get "#{Repository.path repo}/labels/#{name}", options
31
+ get "#{Repository.path repo}/labels/#{ERB::Util.url_encode(name)}", options
32
32
  end
33
33
 
34
34
  # Add a label to a repository
@@ -56,7 +56,7 @@ module Octokit
56
56
  # @example Update the label "Version 1.0" with new color "#cceeaa"
57
57
  # Octokit.update_label("octokit/octokit.rb", "Version 1.0", {:color => "cceeaa"})
58
58
  def update_label(repo, label, options = {})
59
- patch "#{Repository.path repo}/labels/#{label}", options
59
+ patch "#{Repository.path repo}/labels/#{ERB::Util.url_encode(label)}", options
60
60
  end
61
61
 
62
62
  # Delete a label from a repository.
@@ -70,7 +70,7 @@ module Octokit
70
70
  # @example Delete the label "Version 1.0" from the repository.
71
71
  # Octokit.delete_label!("octokit/octokit.rb", "Version 1.0")
72
72
  def delete_label!(repo, label, options = {})
73
- boolean_from_response :delete, "#{Repository.path repo}/labels/#{label}", options
73
+ boolean_from_response :delete, "#{Repository.path repo}/labels/#{ERB::Util.url_encode(label)}", options
74
74
  end
75
75
 
76
76
  # Remove a label from an Issue
@@ -85,7 +85,7 @@ module Octokit
85
85
  # @example Remove the label "Version 1.0" from the repository.
86
86
  # Octokit.remove_label("octokit/octokit.rb", 23, "Version 1.0")
87
87
  def remove_label(repo, number, label, options = {})
88
- delete "#{Repository.path repo}/issues/#{number}/labels/#{label}", options
88
+ delete "#{Repository.path repo}/issues/#{number}/labels/#{ERB::Util.url_encode(label)}", options
89
89
  end
90
90
 
91
91
  # Remove all label from an Issue
@@ -731,7 +731,7 @@ module Octokit
731
731
  # @return [Sawyer::Resource] Hash representing the new migration.
732
732
  # @example
733
733
  # @client.start_migration('github', ['github/dotfiles'])
734
- # @see https://developer.github.com/v3/orgs/migrations/#start-a-migration
734
+ # @see https://docs.github.com/en/rest/reference/migrations#start-an-organization-migration
735
735
  def start_migration(org, repositories, options = {})
736
736
  options = ensure_api_media_type(:migrations, options)
737
737
  options[:repositories] = repositories
@@ -744,7 +744,7 @@ module Octokit
744
744
  #
745
745
  # @param org [String, Integer] Organization GitHub login or id.
746
746
  # @return [Array<Sawyer::Resource>] Array of migration resources.
747
- # @see https://developer.github.com/v3/orgs/migrations/#get-a-list-of-migrations
747
+ # @see https://docs.github.com/en/rest/reference/migrations#list-organization-migrations
748
748
  def migrations(org, options = {})
749
749
  options = ensure_api_media_type(:migrations, options)
750
750
  paginate "#{Organization.path(org)}/migrations", options
@@ -756,7 +756,7 @@ module Octokit
756
756
  #
757
757
  # @param org [String, Integer] Organization GitHub login or id.
758
758
  # @param id [Integer] ID number of the migration.
759
- # @see https://developer.github.com/v3/orgs/migrations/#get-the-status-of-a-migration
759
+ # @see https://docs.github.com/en/rest/reference/migrations#get-an-organization-migration-status
760
760
  def migration_status(org, id, options = {})
761
761
  options = ensure_api_media_type(:migrations, options)
762
762
  get "#{Organization.path(org)}/migrations/#{id}", options
@@ -768,7 +768,7 @@ module Octokit
768
768
  #
769
769
  # @param org [String, Integer] Organization GitHub login or id.
770
770
  # @param id [Integer] ID number of the migration.
771
- # @see https://developer.github.com/v3/orgs/migrations/#download-a-migration-archive
771
+ # @see https://docs.github.com/en/rest/reference/migrations#download-an-organization-migration-archive
772
772
  def migration_archive_url(org, id, options = {})
773
773
  options = ensure_api_media_type(:migrations, options)
774
774
  url = "#{Organization.path(org)}/migrations/#{id}/archive"
@@ -783,7 +783,7 @@ module Octokit
783
783
  #
784
784
  # @param org [String, Integer] Organization GitHub login or id.
785
785
  # @param id [Integer] ID number of the migration.
786
- # @see https://developer.github.com/v3/orgs/migrations/#delete-a-migration-archive
786
+ # @see https://docs.github.com/en/rest/reference/migrations#delete-an-organization-migration-archive
787
787
  def delete_migration_archive(org, id, options = {})
788
788
  options = ensure_api_media_type(:migrations, options)
789
789
  delete "#{Organization.path(org)}/migrations/#{id}/archive", options
@@ -796,11 +796,25 @@ module Octokit
796
796
  # @param org [String, Integer] Organization GitHub login or id.
797
797
  # @param id [Integer] ID number of the migration.
798
798
  # @param repo [String] Name of the repository.
799
- # @see https://developer.github.com/v3/orgs/migrations/#unlock-a-repository
799
+ # @see https://docs.github.com/en/rest/reference/migrations#unlock-an-organization-repository
800
800
  def unlock_repository(org, id, repo, options = {})
801
801
  options = ensure_api_media_type(:migrations, options)
802
802
  delete "#{Organization.path(org)}/migrations/#{id}/repos/#{repo}/lock", options
803
803
  end
804
+
805
+ # Get GitHub Actions billing for an organization
806
+ #
807
+ # Requires authenticated organization owner.
808
+ #
809
+ # @param org [String, Integer] Organization GitHub login or id.
810
+ # @return [Sawyer::Resource] Hash representing GitHub Actions billing for an organization.
811
+ # @see https://docs.github.com/en/rest/reference/billing#get-github-actions-billing-for-an-organization
812
+ #
813
+ # @example
814
+ # @client.billing_actions('github')
815
+ def billing_actions(org)
816
+ get "#{Organization.path(org)}/settings/billing/actions"
817
+ end
804
818
  end
805
819
  end
806
820
  end
@@ -91,9 +91,9 @@ module Octokit
91
91
  conn = Faraday.new(:url => @api_endpoint) do |http|
92
92
  http.headers[:user_agent] = user_agent
93
93
  if basic_authenticated?
94
- http.basic_auth(@login, @password)
94
+ http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password
95
95
  elsif token_authenticated?
96
- http.authorization 'token', @access_token
96
+ http.request :authorization, 'token', @access_token
97
97
  end
98
98
  http.request :url_encoded
99
99
  http.use Octokit::Response::RaiseError
@@ -23,6 +23,18 @@ module Octokit
23
23
  alias :references :refs
24
24
  alias :list_references :refs
25
25
 
26
+ # Fetch matching refs
27
+ #
28
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
29
+ # @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt> or <tt>heads/rails-3</tt>
30
+ # @return [Array<Sawyer::Resource>] The reference matching the given repo and the ref id
31
+ # @see https://developer.github.com/v3/git/refs/#list-matching-references
32
+ # @example Fetch refs matching tags/v2 for sferik/rails_admin
33
+ # Octokit.ref("sferik/rails_admin","tags/v2")
34
+ def matching_refs(repo, ref, options = {})
35
+ paginate "#{Repository.path repo}/git/matching-refs/#{ref}", options
36
+ end
37
+
26
38
  # Fetch a given reference
27
39
  #
28
40
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
@@ -46,7 +58,7 @@ module Octokit
46
58
  # @example Create refs/heads/master for octocat/Hello-World with sha 827efc6d56897b048c772eb4087f854f46256132
47
59
  # Octokit.create_ref("octocat/Hello-World", "heads/master", "827efc6d56897b048c772eb4087f854f46256132")
48
60
  def create_ref(repo, ref, sha, options = {})
49
- ref = "refs/#{ref}" unless ref =~ %r{refs/}
61
+ ref = "refs/#{ref}" unless ref =~ %r{\Arefs/}
50
62
  parameters = {
51
63
  :ref => ref,
52
64
  :sha => sha
@@ -640,6 +640,24 @@ module Octokit
640
640
  boolean_from_response :delete, "#{Repository.path repo}/branches/#{branch}/protection", opts
641
641
  end
642
642
 
643
+ # Rename a single branch from a repository
644
+ #
645
+ # Requires authenticated client
646
+ #
647
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
648
+ # @param branch [String] Current branch name
649
+ # @param new_name [String] New branch name
650
+ # @return [Sawyer::Resource] The renamed branch
651
+ # @see https://developer.github.com/v3/repos/#rename-a-branch
652
+ # @example
653
+ # @client.rename_branch('octokit/octokit.rb', 'master', 'main')
654
+ def rename_branch(repo, branch, new_name, options = {})
655
+ params = {
656
+ new_name: new_name,
657
+ }
658
+ post "#{Repository.path repo}/branches/#{branch}/rename", params.merge(options)
659
+ end
660
+
643
661
  # List users available for assigning to issues.
644
662
  #
645
663
  # Requires authenticated client for private repos.
@@ -8,30 +8,40 @@ module Octokit
8
8
 
9
9
  # Root for status API
10
10
  # @private
11
- STATUS_ROOT = 'https://status.github.com/api.json'
11
+ SUMMARY_ROOT = 'https://www.githubstatus.com/api/v2/summary.json'
12
+ STATUS_ROOT = 'https://www.githubstatus.com/api/v2/status.json'
13
+ COMPONENTS_ROOT = 'https://www.githubstatus.com/api/v2/components.json'
14
+
15
+ # Returns a summary with the current status and the last status messages.
16
+ #
17
+ # @return [<Sawyer::Resource>] GitHub status summary
18
+ # @see https://www.githubstatus.com/api#summory
19
+ def github_status_summary
20
+ get(SUMMARY_ROOT)
21
+ end
12
22
 
13
23
  # Returns the current system status
14
24
  #
15
25
  # @return [Sawyer::Resource] GitHub status
16
- # @see https://status.github.com/api#api-current-status
26
+ # @see https://www.githubstatus.com/api#status
17
27
  def github_status
18
- get(STATUS_ROOT).rels[:status].get.data
28
+ get(STATUS_ROOT)
19
29
  end
20
30
 
21
31
  # Returns the last human communication, status, and timestamp.
22
32
  #
23
33
  # @return [Sawyer::Resource] GitHub status last message
24
- # @see https://status.github.com/api#api-last-message
34
+ # @see https://www.githubstatus.com/api/#components
25
35
  def github_status_last_message
26
- get(STATUS_ROOT).rels[:last_message].get.data
36
+ get(COMPONENTS_ROOT).components.first
27
37
  end
28
38
 
29
39
  # Returns the most recent human communications with status and timestamp.
30
40
  #
31
41
  # @return [Array<Sawyer::Resource>] GitHub status messages
32
- # @see https://status.github.com/api#api-recent-messages
42
+ # @see https://www.githubstatus.com/api#components
33
43
  def github_status_messages
34
- get(STATUS_ROOT).rels[:messages].get.data
44
+ get(COMPONENTS_ROOT).components
35
45
  end
36
46
  end
37
47
  end
@@ -2,7 +2,6 @@ require 'octokit/connection'
2
2
  require 'octokit/warnable'
3
3
  require 'octokit/arguments'
4
4
  require 'octokit/repo_arguments'
5
- require 'octokit/configurable'
6
5
  require 'octokit/authentication'
7
6
  require 'octokit/gist'
8
7
  require 'octokit/rate_limit'
@@ -133,7 +132,7 @@ module Octokit
133
132
  def initialize(options = {})
134
133
  # Use options passed in, but fall back to module defaults
135
134
  Octokit::Configurable.keys.each do |key|
136
- value = options.key?(key) ? options[key] : Octokit.instance_variable_get(:"@#{key}")
135
+ value = options[key].nil? ? Octokit.instance_variable_get(:"@#{key}") : options[key]
137
136
  instance_variable_set(:"@#{key}", value)
138
137
  end
139
138
 
@@ -238,11 +237,11 @@ module Octokit
238
237
  conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode
239
238
  conn = Faraday.new(conn_opts) do |http|
240
239
  if basic_authenticated?
241
- http.basic_auth(@login, @password)
240
+ http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password
242
241
  elsif token_authenticated?
243
- http.authorization 'token', @access_token
242
+ http.request :authorization, 'token', @access_token
244
243
  elsif bearer_authenticated?
245
- http.authorization 'Bearer', @bearer_token
244
+ http.request :authorization, 'Bearer', @bearer_token
246
245
  end
247
246
  http.headers['accept'] = options[:accept] if options.key?(:accept)
248
247
  end
@@ -107,13 +107,13 @@ module Octokit
107
107
  http.headers[:content_type] = "application/json"
108
108
  http.headers[:user_agent] = user_agent
109
109
  if basic_authenticated?
110
- http.basic_auth(@login, @password)
110
+ http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password
111
111
  elsif token_authenticated?
112
- http.authorization 'token', @access_token
112
+ http.request :authorization, 'token', @access_token
113
113
  elsif bearer_authenticated?
114
- http.authorization 'Bearer', @bearer_token
114
+ http.request :authorization, 'Bearer', @bearer_token
115
115
  elsif application_authenticated?
116
- http.basic_auth(@client_id, @client_secret)
116
+ http.request *FARADAY_BASIC_AUTH_KEYS, @client_id, @client_secret
117
117
  end
118
118
  end
119
119
  end
@@ -176,7 +176,7 @@ module Octokit
176
176
  :links_parser => Sawyer::LinkParsers::Simple.new
177
177
  }
178
178
  conn_opts = @connection_options
179
- conn_opts[:builder] = @middleware if @middleware
179
+ conn_opts[:builder] = @middleware.dup if @middleware
180
180
  conn_opts[:proxy] = @proxy if @proxy
181
181
  if conn_opts[:ssl].nil?
182
182
  conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode
@@ -2,6 +2,15 @@ require 'octokit/middleware/follow_redirects'
2
2
  require 'octokit/response/raise_error'
3
3
  require 'octokit/response/feed_parser'
4
4
  require 'octokit/version'
5
+ require 'octokit/warnable'
6
+
7
+ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
8
+ begin
9
+ require 'faraday/retry'
10
+ rescue LoadError
11
+ Octokit::Warnable.octokit_warn 'To use retry middleware with Faraday v2.0+, install `faraday-retry` gem'
12
+ end
13
+ end
5
14
 
6
15
  module Octokit
7
16
 
@@ -20,12 +29,13 @@ module Octokit
20
29
  # Default WEB endpoint
21
30
  WEB_ENDPOINT = "https://github.com".freeze
22
31
 
23
- # In Faraday 0.9, Faraday::Builder was renamed to Faraday::RackBuilder
24
- RACK_BUILDER_CLASS = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder
25
-
26
32
  # Default Faraday middleware stack
27
- MIDDLEWARE = RACK_BUILDER_CLASS.new do |builder|
28
- builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError]
33
+ MIDDLEWARE = Faraday::RackBuilder.new do |builder|
34
+ # In Faraday 2.x, Faraday::Request::Retry was moved to a separate gem
35
+ # so we use it only when it's available.
36
+ builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError] if defined?(Faraday::Request::Retry)
37
+ builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError] if defined?(Faraday::Retry::Middleware)
38
+
29
39
  builder.use Octokit::Middleware::FollowRedirects
30
40
  builder.use Octokit::Response::RaiseError
31
41
  builder.use Octokit::Response::FeedParser
@@ -11,7 +11,7 @@ module Octokit
11
11
  # @param license [String] The path to your .ghl license file.
12
12
  # @param settings [Hash] A hash configuration of the initial settings.
13
13
  #
14
- # @see http: //git.io/j5NT
14
+ # @see https://docs.github.com/en/enterprise-server@3.4/rest/enterprise-admin/management-console#create-a-github-license
15
15
  # @return nil
16
16
  def upload_license(license, settings = nil)
17
17
  conn = faraday_configuration
@@ -156,7 +156,7 @@ module Octokit
156
156
  end
157
157
 
158
158
  # We fall back to raw Faraday for handling the licenses because I'm suspicious
159
- # that Sawyer isn't handling binary POSTs correctly: http://git.io/jMir
159
+ # that Sawyer isn't handling binary POSTs correctly: https://github.com/lostisland/sawyer/blob/03fca4c020f465ec42856d0486ec3991859b0aed/lib/sawyer/agent.rb#L85
160
160
  def faraday_configuration
161
161
  @faraday_configuration ||= Faraday.new(:url => @management_console_endpoint) do |http|
162
162
  http.headers[:user_agent] = user_agent
data/lib/octokit/error.rb CHANGED
@@ -68,6 +68,8 @@ module Octokit
68
68
  def self.error_for_403(body)
69
69
  if body =~ /rate limit exceeded/i
70
70
  Octokit::TooManyRequests
71
+ elsif body =~ /exceeded a secondary rate limit/i
72
+ Octokit::TooManyRequests
71
73
  elsif body =~ /login attempts exceeded/i
72
74
  Octokit::TooManyLoginAttempts
73
75
  elsif body =~ /returns blobs up to [0-9]+ MB/i
@@ -106,6 +108,8 @@ module Octokit
106
108
  def self.error_for_422(body)
107
109
  if body =~ /PullRequestReviewComment/i && body =~ /(commit_id|end_commit_oid) is not part of the pull request/i
108
110
  Octokit::CommitIsNotPartOfPullRequest
111
+ elsif body =~ /Path diff too large/i
112
+ Octokit::PathDiffTooLarge
109
113
  else
110
114
  Octokit::UnprocessableEntity
111
115
  end
@@ -314,6 +318,10 @@ module Octokit
314
318
  # and body matches 'PullRequestReviewComment' and 'commit_id (or end_commit_oid) is not part of the pull request'
315
319
  class CommitIsNotPartOfPullRequest < UnprocessableEntity; end
316
320
 
321
+ # Raised when GitHub returns a 422 HTTP status code and body matches 'Path diff too large'.
322
+ # It could occur when attempting to post review comments on a "too large" file.
323
+ class PathDiffTooLarge < UnprocessableEntity; end
324
+
317
325
  # Raised when GitHub returns a 451 HTTP status code
318
326
  class UnavailableForLegalReasons < ClientError; end
319
327
 
@@ -86,7 +86,10 @@ module Octokit
86
86
  original_url = env[:url]
87
87
  env[:url] += safe_escape(response["location"])
88
88
  unless same_host?(original_url, env[:url])
89
- env[:request_headers].delete("Authorization")
89
+ # HACK: Faraday’s Authorization middlewares don’t touch the request if the `Authorization` header is set.
90
+ # This is a workaround to drop authentication info.
91
+ # See https://github.com/octokit/octokit.rb/pull/1359#issuecomment-925609697
92
+ env[:request_headers]["Authorization"] = "dummy"
90
93
  end
91
94
 
92
95
  if convert_to_get?(response)
@@ -6,7 +6,6 @@ module Octokit
6
6
  PREVIEW_TYPES = {
7
7
  :applications_api => 'application/vnd.github.doctor-strange-preview+json'.freeze,
8
8
  :branch_protection => 'application/vnd.github.luke-cage-preview+json'.freeze,
9
- :checks => 'application/vnd.github.antiope-preview+json'.freeze,
10
9
  :commit_search => 'application/vnd.github.cloak-preview+json'.freeze,
11
10
  :commit_pulls => 'application/vnd.github.groot-preview+json'.freeze,
12
11
  :commit_branches => 'application/vnd.github.groot-preview+json'.freeze,
@@ -23,9 +22,7 @@ module Octokit
23
22
  :topics => 'application/vnd.github.mercy-preview+json'.freeze,
24
23
  :community_profile => 'application/vnd.github.black-panther-preview+json'.freeze,
25
24
  :strict_validation => 'application/vnd.github.speedy-preview+json'.freeze,
26
- :drafts => 'application/vnd.github.shadow-cat-preview'.freeze,
27
25
  :template_repositories => 'application/vnd.github.baptiste-preview+json'.freeze,
28
- :uninstall_github_app => 'application/vnd.github.gambit-preview+json'.freeze,
29
26
  :project_card_events => 'application/vnd.github.starfox-preview+json'.freeze,
30
27
  :vulnerability_alerts => 'application/vnd.github.dorian-preview+json'.freeze,
31
28
  }
@@ -0,0 +1,8 @@
1
+ require 'faraday'
2
+
3
+ module Octokit
4
+ module Response
5
+ # In Faraday 2.x, Faraday::Response::Middleware was removed
6
+ BaseMiddleware = defined?(Faraday::Response::Middleware) ? Faraday::Response::Middleware : Faraday::Middleware
7
+ end
8
+ end
@@ -1,11 +1,11 @@
1
- require 'faraday'
1
+ require 'octokit/response/base_middleware'
2
2
 
3
3
  module Octokit
4
4
 
5
5
  module Response
6
6
 
7
7
  # Parses RSS and Atom feed responses.
8
- class FeedParser < Faraday::Response::Middleware
8
+ class FeedParser < BaseMiddleware
9
9
 
10
10
  def on_complete(env)
11
11
  if env[:response_headers]["content-type"] =~ /(\batom|\brss)/
@@ -1,4 +1,4 @@
1
- require 'faraday'
1
+ require 'octokit/response/base_middleware'
2
2
  require 'octokit/error'
3
3
 
4
4
  module Octokit
@@ -7,7 +7,7 @@ module Octokit
7
7
 
8
8
  # This class raises an Octokit-flavored exception based
9
9
  # HTTP status codes returned by the API
10
- class RaiseError < Faraday::Response::Middleware
10
+ class RaiseError < BaseMiddleware
11
11
 
12
12
  def on_complete(response)
13
13
  if error = Octokit::Error.from_response(response)
@@ -5,7 +5,7 @@ module Octokit
5
5
 
6
6
  # Current minor release.
7
7
  # @return [Integer]
8
- MINOR = 20
8
+ MINOR = 23
9
9
 
10
10
  # Current patch level.
11
11
  # @return [Integer]
@@ -3,6 +3,8 @@ module Octokit
3
3
  # Allows warnings to be suppressed via environment variable.
4
4
  module Warnable
5
5
 
6
+ module_function
7
+
6
8
  # Wrapper around Kernel#warn to print warnings unless
7
9
  # OCTOKIT_SILENT is set to true.
8
10
  #
data/lib/octokit.rb CHANGED
@@ -1,10 +1,11 @@
1
- require 'octokit/client'
2
- require 'octokit/enterprise_admin_client'
3
- require 'octokit/enterprise_management_console_client'
4
1
  require 'octokit/default'
2
+ require 'octokit/configurable'
5
3
 
6
4
  # Ruby toolkit for the GitHub API
7
5
  module Octokit
6
+ autoload(:Client, File.join(__dir__, 'octokit/client'))
7
+ autoload(:EnterpriseAdminClient, File.join(__dir__, 'octokit/enterprise_admin_client'))
8
+ autoload(:EnterpriseManagementConsoleClient, File.join(__dir__, 'octokit/enterprise_management_console_client'))
8
9
 
9
10
  class << self
10
11
  include Octokit::Configurable
data/octokit.gemspec CHANGED
@@ -5,8 +5,8 @@ require 'octokit/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.add_development_dependency 'bundler', '>= 1', '< 3'
8
- spec.add_dependency 'sawyer', '>= 0.5.3', '~> 0.8.0'
9
- spec.add_dependency 'faraday', '>= 0.9'
8
+ spec.add_dependency 'sawyer', '~> 0.9'
9
+ spec.add_dependency 'faraday', '>= 1', '< 3'
10
10
  spec.authors = ["Wynn Netherland", "Erik Michaels-Ober", "Clint Shryock"]
11
11
  spec.description = %q{Simple wrapper for the GitHub API}
12
12
  spec.email = ['wynn.netherland@gmail.com', 'sferik@gmail.com', 'clint@ctshryock.com']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.20.0
4
+ version: 4.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wynn Netherland
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-12-28 00:00:00.000000000 Z
13
+ date: 2022-05-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -36,36 +36,36 @@ dependencies:
36
36
  name: sawyer
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: 0.5.3
42
39
  - - "~>"
43
40
  - !ruby/object:Gem::Version
44
- version: 0.8.0
41
+ version: '0.9'
45
42
  type: :runtime
46
43
  prerelease: false
47
44
  version_requirements: !ruby/object:Gem::Requirement
48
45
  requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: 0.5.3
52
46
  - - "~>"
53
47
  - !ruby/object:Gem::Version
54
- version: 0.8.0
48
+ version: '0.9'
55
49
  - !ruby/object:Gem::Dependency
56
50
  name: faraday
57
51
  requirement: !ruby/object:Gem::Requirement
58
52
  requirements:
59
53
  - - ">="
60
54
  - !ruby/object:Gem::Version
61
- version: '0.9'
55
+ version: '1'
56
+ - - "<"
57
+ - !ruby/object:Gem::Version
58
+ version: '3'
62
59
  type: :runtime
63
60
  prerelease: false
64
61
  version_requirements: !ruby/object:Gem::Requirement
65
62
  requirements:
66
63
  - - ">="
67
64
  - !ruby/object:Gem::Version
68
- version: '0.9'
65
+ version: '1'
66
+ - - "<"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
69
  description: Simple wrapper for the GitHub API
70
70
  email:
71
71
  - wynn.netherland@gmail.com
@@ -155,6 +155,7 @@ files:
155
155
  - lib/octokit/rate_limit.rb
156
156
  - lib/octokit/repo_arguments.rb
157
157
  - lib/octokit/repository.rb
158
+ - lib/octokit/response/base_middleware.rb
158
159
  - lib/octokit/response/feed_parser.rb
159
160
  - lib/octokit/response/raise_error.rb
160
161
  - lib/octokit/user.rb
@@ -180,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  - !ruby/object:Gem::Version
181
182
  version: 1.3.5
182
183
  requirements: []
183
- rubygems_version: 3.0.3
184
+ rubygems_version: 3.2.9
184
185
  signing_key:
185
186
  specification_version: 4
186
187
  summary: Ruby toolkit for working with the GitHub API