octokit 6.0.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3018cabf6ab75fe3a4340d20a4844ab92fa7059a4bbbdd96b9b671537aef5b5
4
- data.tar.gz: 6308252f312bb301eadfe573daf9d5e17ce0698480dbdc938f72b62831e73632
3
+ metadata.gz: a9f2dca26c45a1b912572448c2fe16e78f37b7bb5fc7dc885488847c6eb19315
4
+ data.tar.gz: 11a332c8d3ad5f92ac0ed01ccd03e6a699f852d31946e6e4acc43e75ea3b2d00
5
5
  SHA512:
6
- metadata.gz: 7477cd6b438fedbec3fe952a8aebeefa224b991a65c8950c26c938db69962614d1ae066c3afd4b40a37ab935637af2dbc08ae126f8e5d199c16df1e646b2878b
7
- data.tar.gz: 6d891d836aa8118c9cce64d265ee26d8e97f7dc05425d491d0d7123f1b9fab12eb3aa62ccc85a1b69640ed29819dba7b19d34161f2fa5b159a0b36701c0c758a
6
+ metadata.gz: 4790f888c01d7094b822ba72fc1ac576efa0803c6433982b53373787649b9b398842ee2986e43af6000677cda62a81e9072936b1d46c516a441a8256de10a1ae
7
+ data.tar.gz: 135c6ab374669d1db0fd18172670f79856adb627ef3e8cf015e0af93dacedf110f6f022df2be04907fdf11d4db68d7c382569e56f792d4c5eac2db7f65f8bbec
data/README.md CHANGED
@@ -13,7 +13,7 @@ Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
13
13
  ## Table of Contents
14
14
 
15
15
  1. [Philosophy](#philosophy)
16
- 2. [Installation](#quick-start)
16
+ 2. [Installation](#installation)
17
17
  3. [Making requests](#making-requests)
18
18
  1. [Additional Query Parameters](#additional-query-parameters)
19
19
  4. [Consuming resources](#consuming-resources)
@@ -25,33 +25,35 @@ Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
25
25
  3. [Two-Factor Authentication](#two-factor-authentication)
26
26
  4. [Using a .netrc file](#using-a-netrc-file)
27
27
  5. [Application authentication](#application-authentication)
28
- 8. [Pagination](#pagination)
28
+ 6. [GitHub App](#github-app)
29
+ 8. [Default results per_page](#default-results-per_page)
30
+ 9. [Pagination](#pagination)
29
31
  1. [Auto pagination](#auto-pagination)
30
- 9. [Working with GitHub Enterprise](#working-with-github-enterprise)
32
+ 10. [Working with GitHub Enterprise](#working-with-github-enterprise)
31
33
  1. [Interacting with the GitHub.com APIs in GitHub Enterprise](#interacting-with-the-githubcom-apis-in-github-enterprise)
32
34
  2. [Interacting with the GitHub Enterprise Admin APIs](#interacting-with-the-github-enterprise-admin-apis)
33
35
  3. [Interacting with the GitHub Enterprise Management Console APIs](#interacting-with-the-github-enterprise-management-console-apis)
34
36
  4. [SSL Connection Errors](#ssl-connection-errors)
35
- 10. [Configuration and defaults](#configuration-and-defaults)
37
+ 11. [Configuration and defaults](#configuration-and-defaults)
36
38
  1. [Configuring module defaults](#configuring-module-defaults)
37
39
  2. [Using ENV variables](#using-env-variables)
38
40
  3. [Timeouts](#timeouts)
39
- 11. [Hypermedia agent](#hypermedia-agent)
41
+ 12. [Hypermedia agent](#hypermedia-agent)
40
42
  1. [Hypermedia in Octokit](#hypermedia-in-octokit)
41
43
  2. [URI templates](#uri-templates)
42
44
  3. [The Full Hypermedia Experience™](#the-full-hypermedia-experience)
43
- 12. [Upgrading guide](#upgrading-guide)
45
+ 13. [Upgrading guide](#upgrading-guide)
44
46
  1. [Upgrading from 1.x.x](#upgrading-from-1xx)
45
- 13. [Advanced usage](#advanced-usage)
47
+ 14. [Advanced usage](#advanced-usage)
46
48
  1. [Debugging](#debugging)
47
49
  2. [Caching](#caching)
48
- 14. [Hacking on Octokit.rb](#hacking-on-octokitrb)
50
+ 15. [Hacking on Octokit.rb](#hacking-on-octokitrb)
49
51
  1. [Code of Conduct](#code-of-conduct)
50
52
  2. [Running and writing new tests](#running-and-writing-new-tests)
51
- 15. [Supported Ruby Versions](#supported-ruby-versions)
52
- 16. [Versioning](#versioning)
53
- 17. [Making Repeating Requests](#making-repeating-requests)
54
- 18. [License](#license)
53
+ 16. [Supported Ruby Versions](#supported-ruby-versions)
54
+ 17. [Versioning](#versioning)
55
+ 18. [Making Repeating Requests](#making-repeating-requests)
56
+ 19. [License](#license)
55
57
 
56
58
  ## Philosophy
57
59
 
@@ -211,15 +213,7 @@ user.login
211
213
  # => "defunkt"
212
214
  ```
213
215
 
214
- You can [create access tokens through your GitHub Account Settings](https://help.github.com/articles/creating-an-access-token-for-command-line-use)
215
- or with a basic authenticated Octokit client:
216
-
217
- ```ruby
218
- client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!')
219
-
220
- client.create_authorization(:scopes => ["user"], :note => "Name of token")
221
- # => <your new oauth token>
222
- ```
216
+ You can [create access tokens through your GitHub Account Settings](https://help.github.com/articles/creating-an-access-token-for-command-line-use).
223
217
 
224
218
  ### Two-Factor Authentication
225
219
 
@@ -235,18 +229,6 @@ client = Octokit::Client.new \
235
229
  user = client.user("defunkt", :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
236
230
  ```
237
231
 
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:
239
-
240
- ```ruby
241
- client = Octokit::Client.new \
242
- :login => 'defunkt',
243
- :password => 'c0d3b4ssssss!'
244
-
245
- client.create_authorization(:scopes => ["user"], :note => "Name of token",
246
- :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
247
- # => <your new oauth token>
248
- ```
249
-
250
232
  ### Using a .netrc file
251
233
 
252
234
  Octokit supports reading credentials from a netrc file (defaulting to
@@ -298,6 +280,15 @@ user = client.user 'defunkt'
298
280
  [access scopes]: http://developer.github.com/v3/oauth/#scopes
299
281
  [app-creds]: http://developer.github.com/v3/#increasing-the-unauthenticated-rate-limit-for-oauth-applications
300
282
 
283
+ ### GitHub App
284
+ Octokit.rb also supports authentication [using a GitHub App](https://docs.github.com/en/developers/apps/managing-github-apps/installing-github-apps), which [requires a generated JWT token](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app).
285
+
286
+ ```ruby
287
+ client = Octokit::Client.new(:bearer_token => "<your jwt token>")
288
+ client.app
289
+ # => about GitHub App info
290
+ ```
291
+
301
292
  ## Default results per_page
302
293
 
303
294
  Default results from the GitHub API are 30, if you wish to add more you must do so during Octokit configuration.
@@ -606,7 +597,7 @@ traffic:
606
597
 
607
598
  ```ruby
608
599
  stack = Faraday::RackBuilder.new do |builder|
609
- builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError] # or Faraday::Request::Retry for Faraday < 2.0
600
+ builder.use Faraday::Retry::Middleware, exceptions: Faraday::Request::Retry::DEFAULT_EXCEPTIONS + [Octokit::ServerError] # or Faraday::Request::Retry for Faraday < 2.0
610
601
  builder.use Octokit::Middleware::FollowRedirects
611
602
  builder.use Octokit::Response::RaiseError
612
603
  builder.use Octokit::Response::FeedParser
@@ -746,6 +737,7 @@ implementations:
746
737
  * Ruby 2.7
747
738
  * Ruby 3.0
748
739
  * Ruby 3.1
740
+ * Ruby 3.2
749
741
 
750
742
  If something doesn't work on one of these Ruby versions, it's a bug.
751
743
 
data/Rakefile CHANGED
@@ -3,22 +3,26 @@
3
3
  require 'bundler'
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
- require 'rspec/core/rake_task'
7
- RSpec::Core::RakeTask.new(:spec)
8
-
9
6
  task test: :spec
10
7
  task default: :spec
11
8
 
9
+ desc 'Run RSpec'
10
+ task :spec do
11
+ if Process.respond_to?(:fork)
12
+ sh('rspec-queue')
13
+ else
14
+ sh('rspec')
15
+ end
16
+ end
17
+
12
18
  namespace :doc do
13
- begin
14
- require 'yard'
15
- YARD::Rake::YardocTask.new do |task|
16
- task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
17
- task.options = [
18
- '--output-dir', 'doc/yard',
19
- '--markup', 'markdown'
20
- ]
21
- end
22
- rescue LoadError
19
+ require 'yard'
20
+ YARD::Rake::YardocTask.new do |task|
21
+ task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
22
+ task.options = [
23
+ '--output-dir', 'doc/yard',
24
+ '--markup', 'markdown'
25
+ ]
23
26
  end
27
+ rescue LoadError
24
28
  end
@@ -11,7 +11,7 @@ module Octokit
11
11
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
12
12
  # @return [Hash] key_id and key
13
13
  # @see https://developer.github.com/v3/actions/secrets/#get-your-public-key
14
- def get_public_key(repo)
14
+ def get_actions_public_key(repo)
15
15
  get "#{Repository.path repo}/actions/secrets/public-key"
16
16
  end
17
17
 
@@ -20,7 +20,7 @@ module Octokit
20
20
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
21
21
  # @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
22
22
  # @see https://developer.github.com/v3/actions/secrets/#list-secrets-for-a-repository
23
- def list_secrets(repo)
23
+ def list_actions_secrets(repo)
24
24
  paginate "#{Repository.path repo}/actions/secrets" do |data, last_response|
25
25
  data.secrets.concat last_response.data.secrets
26
26
  end
@@ -32,7 +32,7 @@ module Octokit
32
32
  # @param name [String] Name of secret
33
33
  # @return [Hash] name, created_at and updated_at
34
34
  # @see https://developer.github.com/v3/actions/secrets/#get-a-secret
35
- def get_secret(repo, name)
35
+ def get_actions_secret(repo, name)
36
36
  get "#{Repository.path repo}/actions/secrets/#{name}"
37
37
  end
38
38
 
@@ -42,7 +42,7 @@ module Octokit
42
42
  # @param name [String] Name of secret
43
43
  # @param options [Hash] encrypted_value and key_id
44
44
  # @see https://developer.github.com/v3/actions/secrets/#create-or-update-a-secret-for-a-repository
45
- def create_or_update_secret(repo, name, options)
45
+ def create_or_update_actions_secret(repo, name, options)
46
46
  put "#{Repository.path repo}/actions/secrets/#{name}", options
47
47
  end
48
48
 
@@ -51,9 +51,62 @@ module Octokit
51
51
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
52
52
  # @param name [String] Name of secret
53
53
  # @see https://developer.github.com/v3/actions/secrets/#delete-a-secret-from-a-repository
54
- def delete_secret(repo, name)
54
+ def delete_actions_secret(repo, name)
55
55
  boolean_from_response :delete, "#{Repository.path repo}/actions/secrets/#{name}"
56
56
  end
57
+
58
+ # Get environment public key for secrets encryption
59
+ #
60
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
61
+ # @param environment [String] Name of environment
62
+ # @return [Hash] key_id and key
63
+ # @see https://docs.github.com/en/rest/actions/secrets#get-an-environment-public-key
64
+ def get_actions_environment_public_key(repo, environment)
65
+ get "#{Repository.path repo}/environments/#{environment}/secrets/public-key"
66
+ end
67
+
68
+ # List environment secrets
69
+ #
70
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
71
+ # @param environment [String] Name of environment
72
+ # @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
73
+ # @see https://developer.github.com/v3/actions/secrets/#list-environment-secrets
74
+ def list_actions_environment_secrets(repo, environment)
75
+ paginate "#{Repository.path repo}/environments/#{environment}/secrets" do |data, last_response|
76
+ data.secrets.concat last_response.data.secrets
77
+ end
78
+ end
79
+
80
+ # Get an environment secret
81
+ #
82
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
83
+ # @param environment [String] Name of environment
84
+ # @param name [String] Name of secret
85
+ # @return [Hash] name, created_at and updated_at
86
+ # @see https://docs.github.com/en/rest/actions/secrets#get-an-environment-secret
87
+ def get_actions_environment_secret(repo, environment, name)
88
+ get "#{Repository.path repo}/environments/#{environment}/secrets/#{name}"
89
+ end
90
+
91
+ # Create or update an environment secret
92
+ #
93
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
94
+ # @param environment [String] Name of environment
95
+ # @param name [String] Name of secret
96
+ # @param options [Hash] encrypted_value and key_id
97
+ # @see https://docs.github.com/en/rest/actions/secrets#create-or-update-an-environment-secret
98
+ def create_or_update_actions_environment_secret(repo, environment, name, options)
99
+ put "#{Repository.path repo}/environments/#{environment}/secrets/#{name}", options
100
+ end
101
+
102
+ # Delete environment secret
103
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
104
+ # @param environment [String] Name of environment
105
+ # @param name [String] Name of secret
106
+ # @see https://docs.github.com/en/rest/actions/secrets#delete-an-environment-secret
107
+ def delete_actions_environment_secret(repo, environment, name)
108
+ boolean_from_response :delete, "#{Repository.path repo}/environments/#{environment}/secrets/#{name}"
109
+ end
57
110
  end
58
111
  end
59
112
  end
@@ -217,6 +217,31 @@ module Octokit
217
217
  def delete_installation(installation, options = {})
218
218
  boolean_from_response :delete, "app/installations/#{installation}", options
219
219
  end
220
+
221
+ # Returns a list of webhook deliveries for the webhook configured for a GitHub App.
222
+ #
223
+ # @param options [Hash] A customizable set of options
224
+ #
225
+ # @see https://docs.github.com/en/rest/apps/webhooks#list-deliveries-for-an-app-webhook
226
+ #
227
+ # @return [Array<Hash>] an array of hook deliveries
228
+ def list_app_hook_deliveries(options = {})
229
+ paginate('app/hook/deliveries', options) do |data, last_response|
230
+ data.concat last_response.data
231
+ end
232
+ end
233
+
234
+ # Redeliver a delivery for the webhook configured for a GitHub App.
235
+ #
236
+ # @param delivery_id [Integer] The id of a GitHub App Hook Delivery
237
+ # @param options [Hash] A customizable set of options
238
+ #
239
+ # @see https://developer.github.com/v3/apps/#redeliver-a-delivery-for-an-app-webhook
240
+ #
241
+ # @return [Boolean] Success
242
+ def deliver_app_hook(delivery_id, options = {})
243
+ boolean_from_response :post, "app/hook/deliveries/#{delivery_id}/attempts", options
244
+ end
220
245
  end
221
246
  end
222
247
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
4
+ require 'tempfile'
5
+ require 'zlib'
6
+
7
+ module Octokit
8
+ class Client
9
+ # Methods for the code scanning alerts API
10
+ #
11
+ # @see https://docs.github.com/rest/code-scanning
12
+ module CodeScanning
13
+ # Uploads SARIF data containing the results of a code scanning analysis
14
+ #
15
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
16
+ # @param file [String] Path to the SARIF file to upload
17
+ # @param sha [String] The SHA of the commit to which the analysis you are uploading relates
18
+ # @param ref [String] The full Git reference, formatted as `refs/heads/<branch name>`, `refs/pull/<number>/merge`, or `refs/pull/<number>/head`
19
+ #
20
+ # @return [Sawyer::Resource] SARIF upload information
21
+ # @see https://docs.github.com/rest/code-scanning#upload-an-analysis-as-sarif-data
22
+ def upload_sarif_data(repo, file, sha, ref, options = {})
23
+ options[:sarif] = compress_sarif_data(file)
24
+ options[:commit_sha] = sha
25
+ options[:ref] = ref
26
+
27
+ post "#{Repository.path repo}/code-scanning/sarifs", options
28
+ end
29
+
30
+ # Gets information about a SARIF upload
31
+ #
32
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
33
+ # @param sarif_id [String] The SARIF ID obtained after uploading
34
+ #
35
+ # @return [Sawyer::Resource] SARIF upload information
36
+ # @see https://docs.github.com/rest/code-scanning#get-information-about-a-sarif-upload
37
+ def get_sarif_upload_information(repo, sarif_id, options = {})
38
+ get "#{Repository.path repo}/code-scanning/sarifs/#{sarif_id}", options
39
+ end
40
+
41
+ private
42
+
43
+ def compress_sarif_data(file)
44
+ Tempfile.create('sarif.gz') do |tempfile|
45
+ Zlib::GzipWriter.open(tempfile) do |gz_file|
46
+ gz_file.write File.binread(file)
47
+ end
48
+ Base64.strict_encode64(tempfile.read)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the Codespaces Secrets API
6
+ #
7
+ # @see https://docs.github.com/en/rest/codespaces/
8
+ module CodespacesSecrets
9
+ # Get public key for secrets encryption
10
+ #
11
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
12
+ # @return [Hash] key_id and key
13
+ # @see https://docs.github.com/en/rest/codespaces/repository-secrets#get-a-repository-public-key
14
+ def get_codespaces_public_key(repo)
15
+ get "#{Repository.path repo}/codespaces/secrets/public-key"
16
+ end
17
+
18
+ # List secrets
19
+ #
20
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
21
+ # @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
22
+ # @see https://docs.github.com/en/rest/codespaces/repository-secrets?apiVersion=2022-11-28#list-repository-secrets
23
+ def list_codespaces_secrets(repo)
24
+ paginate "#{Repository.path repo}/codespaces/secrets" do |data, last_response|
25
+ data.secrets.concat last_response.data.secrets
26
+ end
27
+ end
28
+
29
+ # Get a secret
30
+ #
31
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
32
+ # @param name [String] Name of secret
33
+ # @return [Hash] name, created_at, updated_at, and visibility
34
+ # @see https://docs.github.com/en/rest/codespaces/repository-secrets?apiVersion=2022-11-28#get-a-repository-secret
35
+ def get_codespaces_secret(repo, name)
36
+ get "#{Repository.path repo}/codespaces/secrets/#{name}"
37
+ end
38
+
39
+ # Create or update secrets
40
+ #
41
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
42
+ # @param name [String] Name of secret
43
+ # @param options [Hash] encrypted_value and key_id
44
+ # @see https://docs.github.com/en/rest/codespaces/repository-secrets?apiVersion=2022-11-28#create-or-update-a-repository-secret
45
+ def create_or_update_codespaces_secret(repo, name, options)
46
+ put "#{Repository.path repo}/codespaces/secrets/#{name}", options
47
+ end
48
+
49
+ # Delete a secret
50
+ #
51
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
52
+ # @param name [String] Name of secret
53
+ # @see https://docs.github.com/en/rest/codespaces/repository-secrets?apiVersion=2022-11-28#delete-a-repository-secret
54
+ def delete_codespaces_secret(repo, name)
55
+ boolean_from_response :delete, "#{Repository.path repo}/codespaces/secrets/#{name}"
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the dependabot Secrets API
6
+ #
7
+ # @see https://docs.github.com/en/rest/dependabot/
8
+ module DependabotSecrets
9
+ # Get public key for secrets encryption
10
+ #
11
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
12
+ # @return [Hash] key_id and key
13
+ # @see https://docs.github.com/en/rest/dependabot/repository-secrets#get-a-repository-public-key
14
+ def get_dependabot_public_key(repo)
15
+ get "#{Repository.path repo}/dependabot/secrets/public-key"
16
+ end
17
+
18
+ # List secrets
19
+ #
20
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
21
+ # @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
22
+ # @see https://docs.github.com/en/rest/dependabot/repository-secrets?apiVersion=2022-11-28#list-repository-secrets
23
+ def list_dependabot_secrets(repo)
24
+ paginate "#{Repository.path repo}/dependabot/secrets" do |data, last_response|
25
+ data.secrets.concat last_response.data.secrets
26
+ end
27
+ end
28
+
29
+ # Get a secret
30
+ #
31
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
32
+ # @param name [String] Name of secret
33
+ # @return [Hash] name, created_at, updated_at, and visibility
34
+ # @see https://docs.github.com/en/rest/dependabot/repository-secrets?apiVersion=2022-11-28#get-a-repository-secret
35
+ def get_dependabot_secret(repo, name)
36
+ get "#{Repository.path repo}/dependabot/secrets/#{name}"
37
+ end
38
+
39
+ # Create or update secrets
40
+ #
41
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
42
+ # @param name [String] Name of secret
43
+ # @param options [Hash] encrypted_value and key_id
44
+ # @see https://docs.github.com/en/rest/dependabot/repository-secrets?apiVersion=2022-11-28#create-or-update-a-repository-secret
45
+ def create_or_update_dependabot_secret(repo, name, options)
46
+ put "#{Repository.path repo}/dependabot/secrets/#{name}", options
47
+ end
48
+
49
+ # Delete a secret
50
+ #
51
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
52
+ # @param name [String] Name of secret
53
+ # @see https://docs.github.com/en/rest/dependabot/repository-secrets?apiVersion=2022-11-28#delete-a-repository-secret
54
+ def delete_dependabot_secret(repo, name)
55
+ boolean_from_response :delete, "#{Repository.path repo}/dependabot/secrets/#{name}"
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the Environments API
6
+ #
7
+ # @see https://docs.github.com/en/rest/deployments/environments
8
+ module Environments
9
+ # Fetch a single environment for a repository
10
+ #
11
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
12
+ # @param environment_name [String] The name of the environment
13
+ # @return <Sawyer::Resource> A single environment
14
+ # @see https://docs.github.com/en/rest/deployments/environments#get-an-environment
15
+ def environment(repo, environment_name, options = {})
16
+ get("#{Repository.path repo}/environments/#{environment_name}", options)
17
+ end
18
+
19
+ # Lists the environments for a repository
20
+ #
21
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
22
+ # @option options [Integer] :per_page The number of results per page (max 100). Default: 30
23
+ # @option options [Integer] :page Page number of the results to fetch. Default: 1
24
+ # @return [Sawyer::Resource] Total count of environments and list of environments
25
+ # @see https://docs.github.com/en/rest/deployments/environments#list-environments
26
+ def environments(repo, options = {})
27
+ get("#{Repository.path repo}/environments", options)
28
+ end
29
+ alias list_environments environments
30
+
31
+ # Create or update an environment with protection rules, such as required reviewers
32
+ #
33
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
34
+ # @param environment_name [String] The name of the environment
35
+ # @option options [Integer] :wait_timer The amount of time to delay a job after the job is initially triggered. The time (in minutes) must be an integer between 0 and 43,200 (30 days).
36
+ # @option options [Array] :reviewers The people or teams that may review jobs that reference the environment. You can list up to six users or teams as reviewers.
37
+ # @option options [Object] :deployment_branch_policy The type of deployment branch policy for this environment. To allow all branches to deploy, set to null.
38
+ # @return [Sawyer::Resource] An environment
39
+ # @see https://docs.github.com/en/rest/deployments/environments#create-or-update-an-environment
40
+ def create_or_update_environment(repo, environment_name, options = {})
41
+ put("#{Repository.path repo}/environments/#{environment_name}", options)
42
+ end
43
+
44
+ # Delete an Environment
45
+ #
46
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
47
+ # @param environment_name [String] The name of the environment
48
+ # @return [No Content]
49
+ # @see https://docs.github.com/en/rest/deployments/environments#delete-an-environment
50
+ def delete_environment(repo, environment_name, options = {})
51
+ delete("#{Repository.path repo}/environments/#{environment_name}", options)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -50,12 +50,28 @@ module Octokit
50
50
  end
51
51
  alias update_org update_organization
52
52
 
53
+ # Delete an organization.
54
+ #
55
+ # Requires authenticated organization owner.
56
+ #
57
+ # @param org [String, Integer] Organization login or ID.
58
+ # @return [Boolean] True if deletion successful, otherwise false.
59
+ # @see https://docs.github.com/rest/orgs/orgs#delete-an-organization
60
+ # @example
61
+ # @client.delete_organization("my-org")
62
+ # @example
63
+ # @client.delete_org("my-org")
64
+ def delete_organization(org)
65
+ boolean_from_response :delete, Organization.path(org)
66
+ end
67
+ alias delete_org delete_organization
68
+
53
69
  # Get organizations for a user.
54
70
  #
55
71
  # Nonauthenticated calls to this method will return organizations that
56
72
  # the user is a public member.
57
73
  #
58
- # Use an authenicated client to get both public and private organizations
74
+ # Use an authenticated client to get both public and private organizations
59
75
  # for a user.
60
76
  #
61
77
  # Calling this method on a `@client` will return that users organizations.
@@ -197,18 +197,21 @@ module Octokit
197
197
  # @param body [String] Comment content
198
198
  # @param commit_id [String] Sha of the commit to comment on.
199
199
  # @param path [String] Relative path of the file to comment on.
200
- # @param position [Integer] Line index in the diff to comment on.
200
+ # @param line [Integer] Line index in the diff to comment on.
201
+ # For a multi-line comment, the last line of the range
202
+ # and specify 'start_line' in the 'options'.
201
203
  # @return [Sawyer::Resource] Hash representing the new comment
204
+ # @deprecated The position will be deprecated in the next major version. Please refer to the details below.
202
205
  # @see https://developer.github.com/v3/pulls/comments/#create-a-comment
203
206
  # @example
204
207
  # @client.create_pull_request_comment("octokit/octokit.rb", 163, ":shipit:",
205
208
  # "2d3201e4440903d8b04a5487842053ca4883e5f0", "lib/octokit/request.rb", 47)
206
- def create_pull_request_comment(repo, pull_id, body, commit_id, path, position, options = {})
209
+ def create_pull_request_comment(repo, pull_id, body, commit_id, path, line, options = {})
207
210
  options.merge!({
208
211
  body: body,
209
212
  commit_id: commit_id,
210
213
  path: path,
211
- position: position
214
+ line: line
212
215
  })
213
216
  post "#{Repository.path repo}/pulls/#{pull_id}/comments", options
214
217
  end
@@ -137,16 +137,67 @@ module Octokit
137
137
 
138
138
  # Delete a reaction
139
139
  #
140
- # @param id [Integer] Reaction id
140
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
141
+ # @param issue_id [Integer] The Issue comment id
142
+ # @param reaction_id [Integer] The Reaction id
143
+ #
144
+ # @see https://docs.github.com/en/rest/reactions/reactions#delete-an-issue-reaction
145
+ #
146
+ # @example
147
+ # @client.delete_issue_reaction("octokit/octokit.rb", 1, 2)
148
+ #
149
+ # @return [Boolean] Return true if reaction was deleted, false otherwise.
150
+ def delete_issue_reaction(repo, issue_id, reaction_id, options = {})
151
+ boolean_from_response :delete, "#{Repository.path repo}/issues/#{issue_id}/reactions/#{reaction_id}", options
152
+ end
153
+
154
+ # List reactions for a release
155
+ #
156
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
157
+ # @param id [Integer] The Release id
158
+ #
159
+ # @see https://docs.github.com/en/free-pro-team@latest/rest/reactions/reactions?apiVersion=2022-11-28#list-reactions-for-a-release
160
+ #
161
+ # @example
162
+ # @client.release_reactions("octokit/octokit.rb", 1)
163
+ #
164
+ # @return [Array<Sawyer::Resource>] Array of Hashes representing the reactions.
165
+ def release_reactions(repo, release_id, options = {})
166
+ get "#{Repository.path repo}/releases/#{release_id}/reactions", options
167
+ end
168
+
169
+ # Create reaction for a release
170
+ #
171
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
172
+ # @param id [Integer] The Release id
173
+ # @param reaction [String] The Reaction
174
+ #
175
+ # @see https://docs.github.com/en/free-pro-team@latest/rest/reactions/reactions?apiVersion=2022-11-28#create-reaction-for-a-release
176
+ # @see https://developer.github.com/v3/reactions/#reaction-types
177
+ #
178
+ # @example
179
+ # @client.create_release_reaction("octokit/octokit.rb", 1)
180
+ #
181
+ # @return [<Sawyer::Resource>] Hash representing the reaction.
182
+ def create_release_reaction(repo, release_id, reaction, options = {})
183
+ options = options.merge(content: reaction)
184
+ post "#{Repository.path repo}/releases/#{release_id}/reactions", options
185
+ end
186
+
187
+ # Delete a reaction for a release
188
+ #
189
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
190
+ # @param issue_id [Integer] The Release id
191
+ # @param reaction_id [Integer] The Reaction id
141
192
  #
142
- # @see https://developer.github.com/v3/reactions/#delete-a-reaction
193
+ # @see https://docs.github.com/en/free-pro-team@latest/rest/reactions/reactions?apiVersion=2022-11-28#delete-a-release-reaction
143
194
  #
144
195
  # @example
145
- # @client.delete_reaction(1)
196
+ # @client.delete_release_reaction("octokit/octokit.rb", 1, 2)
146
197
  #
147
198
  # @return [Boolean] Return true if reaction was deleted, false otherwise.
148
- def delete_reaction(id, options = {})
149
- boolean_from_response :delete, "reactions/#{id}", options
199
+ def delete_release_reaction(repo, release_id, reaction_id, options = {})
200
+ boolean_from_response :delete, "#{Repository.path repo}/releases/#{release_id}/reactions/#{reaction_id}", options
150
201
  end
151
202
  end
152
203
  end
@@ -564,7 +564,7 @@ module Octokit
564
564
  # @example Get branch 'master` from octokit/octokit.rb
565
565
  # Octokit.branch("octokit/octokit.rb", "master")
566
566
  def branch(repo, branch, options = {})
567
- get "#{Repository.path repo}/branches/#{branch}", options
567
+ get "#{Repository.path repo}/branches/#{CGI.escape(branch)}", options
568
568
  end
569
569
  alias get_branch branch
570
570
 
@@ -151,7 +151,7 @@ module Octokit
151
151
  # @param number [Integer] Number ID of the pull request
152
152
  # @param reviewers [Hash] :reviewers [Array<String>] An array of user logins
153
153
  # @param options [Hash] :team_reviewers [Array<String>] An array of team slugs
154
- # @see https://developer.github.com/v3/pulls/review_requests/#create-a-review-request
154
+ # @see https://developer.github.com/v3/pulls/review_requests/#request-reviewers-for-a-pull-request
155
155
  #
156
156
  # @example
157
157
  # @client.request_pull_request_review('octokit/octokit.rb', 2, reviewers: ['soudy'])
@@ -44,6 +44,7 @@ module Octokit
44
44
  # @option options [Integer] :per_page Number of items per page
45
45
  # @return [Sawyer::Resource] Search results object
46
46
  # @see https://developer.github.com/v3/search/#search-issues-and-pull-requests
47
+ # @see https://docs.github.com/en/rest/search#limitations-on-query-length
47
48
  def search_issues(query, options = {})
48
49
  search 'search/issues', query, options
49
50
  end
@@ -18,6 +18,8 @@ require 'octokit/client/actions_workflow_jobs'
18
18
  require 'octokit/client/actions_workflow_runs'
19
19
  require 'octokit/client/apps'
20
20
  require 'octokit/client/checks'
21
+ require 'octokit/client/code_scanning'
22
+ require 'octokit/client/codespaces_secrets'
21
23
  require 'octokit/client/commits'
22
24
  require 'octokit/client/commit_comments'
23
25
  require 'octokit/client/commit_pulls'
@@ -25,7 +27,9 @@ require 'octokit/client/commit_branches'
25
27
  require 'octokit/client/community_profile'
26
28
  require 'octokit/client/contents'
27
29
  require 'octokit/client/downloads'
30
+ require 'octokit/client/dependabot_secrets'
28
31
  require 'octokit/client/deployments'
32
+ require 'octokit/client/environments'
29
33
  require 'octokit/client/emojis'
30
34
  require 'octokit/client/events'
31
35
  require 'octokit/client/feeds'
@@ -78,14 +82,18 @@ module Octokit
78
82
  include Octokit::Client::ActionsArtifacts
79
83
  include Octokit::Client::ActionsSecrets
80
84
  include Octokit::Client::Checks
85
+ include Octokit::Client::CodeScanning
86
+ include Octokit::Client::CodespacesSecrets
81
87
  include Octokit::Client::Commits
82
88
  include Octokit::Client::CommitComments
83
89
  include Octokit::Client::CommitPulls
84
90
  include Octokit::Client::CommitBranches
85
91
  include Octokit::Client::CommunityProfile
86
92
  include Octokit::Client::Contents
93
+ include Octokit::Client::DependabotSecrets
87
94
  include Octokit::Client::Deployments
88
95
  include Octokit::Client::Downloads
96
+ include Octokit::Client::Environments
89
97
  include Octokit::Client::Emojis
90
98
  include Octokit::Client::Events
91
99
  include Octokit::Client::Feeds
@@ -163,10 +171,10 @@ module Octokit
163
171
  inspected.gsub! @bearer_token, '********' if @bearer_token
164
172
  # Only show last 4 of token, secret
165
173
  if @access_token
166
- inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..-1]}"
174
+ inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..]}"
167
175
  end
168
176
  if @client_secret
169
- inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..-1]}"
177
+ inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..]}"
170
178
  end
171
179
 
172
180
  inspected
@@ -144,7 +144,7 @@ module Octokit
144
144
  private
145
145
 
146
146
  def options
147
- Octokit::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }.to_h
147
+ Octokit::Configurable.keys.to_h { |key| [key, instance_variable_get(:"@#{key}")] }
148
148
  end
149
149
 
150
150
  def fetch_client_id_and_secret(overrides = {})
@@ -154,7 +154,7 @@ module Octokit
154
154
  end
155
155
 
156
156
  @last_response = response = agent.call(method, Addressable::URI.parse(path.to_s).normalize.to_s, data, options)
157
- response.data
157
+ response_data_correctly_encoded(response)
158
158
  rescue Octokit::Error => e
159
159
  @last_response = nil
160
160
  raise e
@@ -206,5 +206,13 @@ module Octokit
206
206
 
207
207
  opts
208
208
  end
209
+
210
+ def response_data_correctly_encoded(response)
211
+ content_type = response.headers.fetch('content-type', '')
212
+ return response.data unless content_type.include?('charset') && response.data.is_a?(String)
213
+
214
+ reported_encoding = content_type.match(/charset=([^ ]+)/)[1]
215
+ response.data.force_encoding(reported_encoding)
216
+ end
209
217
  end
210
218
  end
@@ -34,9 +34,11 @@ module Octokit
34
34
  # In Faraday 2.x, Faraday::Request::Retry was moved to a separate gem
35
35
  # so we use it only when it's available.
36
36
  if defined?(Faraday::Request::Retry)
37
- builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError]
37
+ retry_exceptions = Faraday::Request::Retry::DEFAULT_EXCEPTIONS + [Octokit::ServerError]
38
+ builder.use Faraday::Request::Retry, exceptions: retry_exceptions
38
39
  elsif defined?(Faraday::Retry::Middleware)
39
- builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError]
40
+ retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Octokit::ServerError]
41
+ builder.use Faraday::Retry::Middleware, exceptions: retry_exceptions
40
42
  end
41
43
 
42
44
  builder.use Octokit::Middleware::FollowRedirects
@@ -49,7 +51,7 @@ module Octokit
49
51
  # Configuration options
50
52
  # @return [Hash]
51
53
  def options
52
- Octokit::Configurable.keys.map { |key| [key, send(key)] }.to_h
54
+ Octokit::Configurable.keys.to_h { |key| [key, send(key)] }
53
55
  end
54
56
 
55
57
  # Default access token from ENV
data/lib/octokit/error.rb CHANGED
@@ -77,7 +77,7 @@ module Octokit
77
77
  Octokit::TooManyRequests
78
78
  when /login attempts exceeded/i
79
79
  Octokit::TooManyLoginAttempts
80
- when /(returns|for) blobs (up to|between) [0-9\-]+ MB/i
80
+ when /(returns|for) blobs (up to|between) [0-9-]+ MB/i
81
81
  Octokit::TooLargeContent
82
82
  when /abuse/i
83
83
  Octokit::AbuseDetected
@@ -213,7 +213,7 @@ module Octokit
213
213
  end
214
214
 
215
215
  def redact_url(url_string)
216
- %w[client_secret access_token].each do |token|
216
+ %w[client_secret access_token api_key].each do |token|
217
217
  if url_string.include? token
218
218
  url_string.gsub!(/#{token}=\S+/, "#{token}=(redacted)")
219
219
  end
data/lib/octokit/gist.rb CHANGED
@@ -10,7 +10,7 @@ module Octokit
10
10
  # Instantiate {Gist} object from Gist URL
11
11
  # @ return [Gist]
12
12
  def self.from_url(url)
13
- Gist.new(URI.parse(url).path[1..-1])
13
+ Gist.new(URI.parse(url).path[1..])
14
14
  end
15
15
 
16
16
  def initialize(gist)
@@ -20,10 +20,12 @@ module Octokit
20
20
  # @return [RateLimit]
21
21
  def self.from_response(response)
22
22
  info = new
23
- if response.respond_to?(:headers) && !response.headers.nil?
24
- info.limit = (response.headers['X-RateLimit-Limit'] || 1).to_i
25
- info.remaining = (response.headers['X-RateLimit-Remaining'] || 1).to_i
26
- info.resets_at = Time.at((response.headers['X-RateLimit-Reset'] || Time.now).to_i)
23
+ headers = response.headers if response.respond_to?(:headers) && !response.headers.nil?
24
+ headers ||= response.response_headers if response.respond_to?(:response_headers) && !response.response_headers.nil?
25
+ if headers
26
+ info.limit = (headers['X-RateLimit-Limit'] || 1).to_i
27
+ info.remaining = (headers['X-RateLimit-Remaining'] || 1).to_i
28
+ info.resets_at = Time.at((headers['X-RateLimit-Reset'] || Time.now).to_i)
27
29
  info.resets_in = [(info.resets_at - Time.now).to_i, 0].max
28
30
  end
29
31
 
@@ -12,7 +12,7 @@ module Octokit
12
12
  #
13
13
  # @return [Repository]
14
14
  def self.from_url(url)
15
- new URI.parse(url).path[1..-1]
15
+ new URI.parse(url).path[1..]
16
16
  .gsub(%r{^repos/}, '')
17
17
  .split('/', 3)[0..1]
18
18
  .join('/')
@@ -48,7 +48,8 @@ module Octokit
48
48
  # @return [String] Repository API path
49
49
  def path
50
50
  return named_api_path if @owner && @name
51
- return id_api_path if @id
51
+
52
+ id_api_path if @id
52
53
  end
53
54
 
54
55
  # Get the api path for a repo
@@ -3,7 +3,7 @@
3
3
  module Octokit
4
4
  # Current major release.
5
5
  # @return [Integer]
6
- MAJOR = 6
6
+ MAJOR = 8
7
7
 
8
8
  # Current minor release.
9
9
  # @return [Integer]
data/octokit.gemspec CHANGED
@@ -5,7 +5,6 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'octokit/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.add_development_dependency 'bundler', '>= 1', '< 3'
9
8
  spec.add_dependency 'faraday', '>= 1', '< 3'
10
9
  spec.add_dependency 'sawyer', '~> 0.9'
11
10
  spec.authors = ['Wynn Netherland', 'Erik Michaels-Ober', 'Clint Shryock']
metadata CHANGED
@@ -1,37 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wynn Netherland
8
8
  - Erik Michaels-Ober
9
9
  - Clint Shryock
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-10-20 00:00:00.000000000 Z
13
+ date: 2023-10-30 00:00:00.000000000 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: bundler
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
21
- version: '1'
22
- - - "<"
23
- - !ruby/object:Gem::Version
24
- version: '3'
25
- type: :development
26
- prerelease: false
27
- version_requirements: !ruby/object:Gem::Requirement
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- version: '1'
32
- - - "<"
33
- - !ruby/object:Gem::Version
34
- version: '3'
35
15
  - !ruby/object:Gem::Dependency
36
16
  name: faraday
37
17
  requirement: !ruby/object:Gem::Requirement
@@ -92,15 +72,19 @@ files:
92
72
  - lib/octokit/client/actions_workflows.rb
93
73
  - lib/octokit/client/apps.rb
94
74
  - lib/octokit/client/checks.rb
75
+ - lib/octokit/client/code_scanning.rb
76
+ - lib/octokit/client/codespaces_secrets.rb
95
77
  - lib/octokit/client/commit_branches.rb
96
78
  - lib/octokit/client/commit_comments.rb
97
79
  - lib/octokit/client/commit_pulls.rb
98
80
  - lib/octokit/client/commits.rb
99
81
  - lib/octokit/client/community_profile.rb
100
82
  - lib/octokit/client/contents.rb
83
+ - lib/octokit/client/dependabot_secrets.rb
101
84
  - lib/octokit/client/deployments.rb
102
85
  - lib/octokit/client/downloads.rb
103
86
  - lib/octokit/client/emojis.rb
87
+ - lib/octokit/client/environments.rb
104
88
  - lib/octokit/client/events.rb
105
89
  - lib/octokit/client/feeds.rb
106
90
  - lib/octokit/client/gists.rb
@@ -168,7 +152,7 @@ licenses:
168
152
  - MIT
169
153
  metadata:
170
154
  rubygems_mfa_required: 'true'
171
- post_install_message:
155
+ post_install_message:
172
156
  rdoc_options: []
173
157
  require_paths:
174
158
  - lib
@@ -183,8 +167,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
167
  - !ruby/object:Gem::Version
184
168
  version: 1.3.5
185
169
  requirements: []
186
- rubygems_version: 3.1.6
187
- signing_key:
170
+ rubygems_version: 3.4.0.dev
171
+ signing_key:
188
172
  specification_version: 4
189
173
  summary: Ruby toolkit for working with the GitHub API
190
174
  test_files: []