octokit 5.6.1 → 6.1.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: bbf0b3ef2f8550628d4bde2fa55f7bcb97261364e94aac9f5a149ce6e86fa019
4
- data.tar.gz: d336c02e28efb73618c1c24827b2b7703dc5341ce95087467089cf36f11d96fb
3
+ metadata.gz: afa7dae6ede3d3871a1ba78d8c0de33d3aa4692869eacdbb30e0867f555c21f2
4
+ data.tar.gz: 213439dcb01e0af935df22e902caa69d9c395b1ab9076a83918efebc374140bd
5
5
  SHA512:
6
- metadata.gz: 960aacdc0e1a37794e6bed1a0c5f2686c1dca5160c0802cb449590f92ecab4cf243a0201b65e419fe3ffa38c194f106eceed0d46c90f63ceeb8a4aa14b22d716
7
- data.tar.gz: 22a81c032d49f11c2f3875bfbc1c577449787d0899f20d0108dc7de868a2b5f1c86163ccebf46eb4a4b2567277c46fd83aca619c071a238746229664894008bf
6
+ metadata.gz: 117e024b6078555cdd6809d941a19a0e8b77e629939e112ffe5a5116674c16d6b441358e3ba56bc2d27770fea108fd4adc18d48aa6c186206628abc28dd525d9
7
+ data.tar.gz: 4caea9cb705c43d9c8022f0de6d74cc9ece8d1e1771ae7a43c0e53a748c226a8c231fe25c64b813bf025a80521dd5c201eb7d2693ebbd6074d47a776137dd7fb
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
 
@@ -298,6 +300,15 @@ user = client.user 'defunkt'
298
300
  [access scopes]: http://developer.github.com/v3/oauth/#scopes
299
301
  [app-creds]: http://developer.github.com/v3/#increasing-the-unauthenticated-rate-limit-for-oauth-applications
300
302
 
303
+ ### GitHub App
304
+ 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).
305
+
306
+ ```ruby
307
+ client = Octokit::Client.new(:bearer_token => "<your jwt token>")
308
+ client.app
309
+ # => about GitHub App info
310
+ ```
311
+
301
312
  ## Default results per_page
302
313
 
303
314
  Default results from the GitHub API are 30, if you wish to add more you must do so during Octokit configuration.
@@ -606,7 +617,7 @@ traffic:
606
617
 
607
618
  ```ruby
608
619
  stack = Faraday::RackBuilder.new do |builder|
609
- builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError] # or Faraday::Request::Retry for Faraday < 2.0
620
+ builder.use Faraday::Retry::Middleware, exceptions: Faraday::Request::Retry::DEFAULT_EXCEPTIONS + [Octokit::ServerError] # or Faraday::Request::Retry for Faraday < 2.0
610
621
  builder.use Octokit::Middleware::FollowRedirects
611
622
  builder.use Octokit::Response::RaiseError
612
623
  builder.use Octokit::Response::FeedParser
@@ -746,6 +757,7 @@ implementations:
746
757
  * Ruby 2.7
747
758
  * Ruby 3.0
748
759
  * Ruby 3.1
760
+ * Ruby 3.2
749
761
 
750
762
  If something doesn't work on one of these Ruby versions, it's a bug.
751
763
 
data/Rakefile CHANGED
@@ -10,15 +10,13 @@ task test: :spec
10
10
  task default: :spec
11
11
 
12
12
  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
13
+ require 'yard'
14
+ YARD::Rake::YardocTask.new do |task|
15
+ task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
16
+ task.options = [
17
+ '--output-dir', 'doc/yard',
18
+ '--markup', 'markdown'
19
+ ]
23
20
  end
21
+ rescue LoadError
24
22
  end
@@ -13,7 +13,9 @@ module Octokit
13
13
  # @return [Sawyer::Resource] the total count and an array of artifacts
14
14
  # @see https://developer.github.com/v3/actions/artifacts#list-artifacts-for-a-repository
15
15
  def repository_artifacts(repo, options = {})
16
- paginate "#{Repository.path repo}/actions/artifacts", options
16
+ paginate "#{Repository.path repo}/actions/artifacts", options do |data, last_response|
17
+ data.artifacts.concat last_response.data.artifacts
18
+ end
17
19
  end
18
20
 
19
21
  # List all artifacts for a workflow run
@@ -24,7 +26,9 @@ module Octokit
24
26
  # @return [Sawyer::Resource] the total count and an array of artifacts
25
27
  # @see https://docs.github.com/en/rest/actions/artifacts#list-workflow-run-artifacts
26
28
  def workflow_run_artifacts(repo, workflow_run_id, options = {})
27
- paginate "#{Repository.path repo}/actions/runs/#{workflow_run_id}/artifacts", options
29
+ paginate "#{Repository.path repo}/actions/runs/#{workflow_run_id}/artifacts", options do |data, last_response|
30
+ data.artifacts.concat last_response.data.artifacts
31
+ end
28
32
  end
29
33
 
30
34
  # Get an artifact
@@ -21,7 +21,9 @@ module Octokit
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
23
  def list_secrets(repo)
24
- paginate "#{Repository.path repo}/actions/secrets"
24
+ paginate "#{Repository.path repo}/actions/secrets" do |data, last_response|
25
+ data.secrets.concat last_response.data.secrets
26
+ end
25
27
  end
26
28
 
27
29
  # Get a secret
@@ -40,7 +40,9 @@ module Octokit
40
40
  # @return [Sawyer::Resource] Jobs information
41
41
  # @see https://docs.github.com/rest/actions/workflow-jobs#list-jobs-for-a-workflow-run-attempt
42
42
  def workflow_run_attempt_jobs(repo, run_id, attempt_number, options = {})
43
- paginate "#{Repository.path repo}/actions/runs/#{run_id}/attempts/#{attempt_number}/jobs", options
43
+ paginate "#{Repository.path repo}/actions/runs/#{run_id}/attempts/#{attempt_number}/jobs", options do |data, last_response|
44
+ data.jobs.concat last_response.data.jobs
45
+ end
44
46
  end
45
47
  alias list_workflow_run_attempt_jobs workflow_run_attempt_jobs
46
48
 
@@ -53,7 +55,9 @@ module Octokit
53
55
  # @return [Sawyer::Resource] Jobs information
54
56
  # @see https://docs.github.com/rest/actions/workflow-jobs#list-jobs-for-a-workflow-run
55
57
  def workflow_run_jobs(repo, run_id, options = {})
56
- paginate "#{Repository.path repo}/actions/runs/#{run_id}/jobs", options
58
+ paginate "#{Repository.path repo}/actions/runs/#{run_id}/jobs", options do |data, last_response|
59
+ data.jobs.concat last_response.data.jobs
60
+ end
57
61
  end
58
62
  alias list_workflow_run_jobs workflow_run_jobs
59
63
  end
@@ -18,7 +18,9 @@ module Octokit
18
18
  # @return [Sawyer::Resource] the total count and an array of workflows
19
19
  # @see https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
20
20
  def workflow_runs(repo, workflow, options = {})
21
- paginate "#{Repository.path repo}/actions/workflows/#{workflow}/runs", options
21
+ paginate "#{Repository.path repo}/actions/workflows/#{workflow}/runs", options do |data, last_response|
22
+ data.workflow_runs.concat last_response.data.workflow_runs
23
+ end
22
24
  end
23
25
  alias list_workflow_runs workflow_runs
24
26
 
@@ -33,7 +35,9 @@ module Octokit
33
35
  # @return [Sawyer::Resource] the total count and an array of workflows
34
36
  # @see https://developer.github.com/v3/actions/workflow-runs/#list-repository-workflow-runs
35
37
  def repository_workflow_runs(repo, options = {})
36
- paginate "#{Repository.path repo}/actions/runs", options
38
+ paginate "#{Repository.path repo}/actions/runs", options do |data, last_response|
39
+ data.workflow_runs.concat last_response.data.workflow_runs
40
+ end
37
41
  end
38
42
  alias list_repository_workflow_runs repository_workflow_runs
39
43
 
@@ -13,7 +13,9 @@ module Octokit
13
13
  # @return [Sawyer::Resource] the total count and an array of workflows
14
14
  # @see https://developer.github.com/v3/actions/workflows/#list-repository-workflows
15
15
  def workflows(repo, options = {})
16
- paginate "#{Repository.path repo}/actions/workflows", options
16
+ paginate "#{Repository.path repo}/actions/workflows", options do |data, last_response|
17
+ data.workflows.concat last_response.data.workflows
18
+ end
17
19
  end
18
20
  alias list_workflows workflows
19
21
 
@@ -4,16 +4,6 @@ module Octokit
4
4
  class Client
5
5
  # Methods for the Hooks API
6
6
  module Hooks
7
- # List all Service Hooks supported by GitHub
8
- #
9
- # @return [Sawyer::Resource] A list of all hooks on GitHub
10
- # @see https://developer.github.com/v3/repos/hooks/#services
11
- # @example List all hooks
12
- # Octokit.available_hooks
13
- def available_hooks(options = {})
14
- get 'hooks', options
15
- end
16
-
17
7
  # List repo hooks
18
8
  #
19
9
  # Requires authenticated client.
@@ -77,9 +77,7 @@ module Octokit
77
77
  # @see https://developer.github.com/v3/git/refs/#update-a-reference
78
78
  # @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
79
79
  # Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
80
- # @example Fast-forward update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
81
- # Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", false)
82
- def update_ref(repo, ref, sha, force = true, options = {})
80
+ def update_ref(repo, ref, sha, force = false, options = {})
83
81
  parameters = {
84
82
  sha: sha,
85
83
  force: force
@@ -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
 
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Method to check scopes
6
+ #
7
+ # @see https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api
8
+ module Tokens
9
+ # Check scopes for a token
10
+ #
11
+ # @param token [String] GitHub OAuth token
12
+ # @param options [Hash] Header params for request
13
+ # @return [Array<String>] OAuth scopes
14
+ # @see https://developer.github.com/v3/oauth/#scopes
15
+ def scopes(token = @access_token, options = {})
16
+ options = options.dup
17
+ raise ArgumentError, 'Access token required' if token.nil?
18
+
19
+ auth = { 'Authorization' => "token #{token}" }
20
+ headers = (options.delete(:headers) || {}).merge(auth)
21
+
22
+ agent.call(:get, 'user', headers: headers)
23
+ .headers['X-OAuth-Scopes']
24
+ .to_s
25
+ .split(',')
26
+ .map(&:strip)
27
+ .sort
28
+ end
29
+ end
30
+ end
31
+ end
@@ -17,7 +17,6 @@ require 'octokit/client/actions_workflows'
17
17
  require 'octokit/client/actions_workflow_jobs'
18
18
  require 'octokit/client/actions_workflow_runs'
19
19
  require 'octokit/client/apps'
20
- require 'octokit/client/authorizations'
21
20
  require 'octokit/client/checks'
22
21
  require 'octokit/client/commits'
23
22
  require 'octokit/client/commit_comments'
@@ -62,6 +61,7 @@ require 'octokit/client/service_status'
62
61
  require 'octokit/client/source_import'
63
62
  require 'octokit/client/stats'
64
63
  require 'octokit/client/statuses'
64
+ require 'octokit/client/tokens'
65
65
  require 'octokit/client/traffic'
66
66
  require 'octokit/client/users'
67
67
  require 'ext/sawyer/relation'
@@ -77,7 +77,6 @@ module Octokit
77
77
  include Octokit::Warnable
78
78
  include Octokit::Client::ActionsArtifacts
79
79
  include Octokit::Client::ActionsSecrets
80
- include Octokit::Client::Authorizations
81
80
  include Octokit::Client::Checks
82
81
  include Octokit::Client::Commits
83
82
  include Octokit::Client::CommitComments
@@ -126,6 +125,7 @@ module Octokit
126
125
  include Octokit::Client::SourceImport
127
126
  include Octokit::Client::Stats
128
127
  include Octokit::Client::Statuses
128
+ include Octokit::Client::Tokens
129
129
  include Octokit::Client::Traffic
130
130
  include Octokit::Client::Users
131
131
 
@@ -163,10 +163,10 @@ module Octokit
163
163
  inspected.gsub! @bearer_token, '********' if @bearer_token
164
164
  # Only show last 4 of token, secret
165
165
  if @access_token
166
- inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..-1]}"
166
+ inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..]}"
167
167
  end
168
168
  if @client_secret
169
- inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..-1]}"
169
+ inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..]}"
170
170
  end
171
171
 
172
172
  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
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('/')
@@ -3,15 +3,15 @@
3
3
  module Octokit
4
4
  # Current major release.
5
5
  # @return [Integer]
6
- MAJOR = 5
6
+ MAJOR = 6
7
7
 
8
8
  # Current minor release.
9
9
  # @return [Integer]
10
- MINOR = 6
10
+ MINOR = 1
11
11
 
12
12
  # Current patch level.
13
13
  # @return [Integer]
14
- PATCH = 1
14
+ PATCH = 0
15
15
 
16
16
  # Full release version.
17
17
  # @return [String]
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: 5.6.1
4
+ version: 6.1.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: 2022-09-14 00:00:00.000000000 Z
13
+ date: 2023-03-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -91,7 +91,6 @@ files:
91
91
  - lib/octokit/client/actions_workflow_runs.rb
92
92
  - lib/octokit/client/actions_workflows.rb
93
93
  - lib/octokit/client/apps.rb
94
- - lib/octokit/client/authorizations.rb
95
94
  - lib/octokit/client/checks.rb
96
95
  - lib/octokit/client/commit_branches.rb
97
96
  - lib/octokit/client/commit_comments.rb
@@ -136,6 +135,7 @@ files:
136
135
  - lib/octokit/client/source_import.rb
137
136
  - lib/octokit/client/stats.rb
138
137
  - lib/octokit/client/statuses.rb
138
+ - lib/octokit/client/tokens.rb
139
139
  - lib/octokit/client/traffic.rb
140
140
  - lib/octokit/client/users.rb
141
141
  - lib/octokit/configurable.rb
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  - !ruby/object:Gem::Version
184
184
  version: 1.3.5
185
185
  requirements: []
186
- rubygems_version: 3.3.7
186
+ rubygems_version: 3.1.2
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: Ruby toolkit for working with the GitHub API
@@ -1,185 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Octokit
4
- class Client
5
- # Methods for the Authorizations API
6
- #
7
- # @see https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api
8
- module Authorizations
9
- # List the authenticated user's authorizations
10
- #
11
- # API for users to manage their own tokens.
12
- # You can only access your own tokens, and only through
13
- # Basic Authentication.
14
- #
15
- # @return [Array<Sawyer::Resource>] A list of authorizations for the authenticated user
16
- # @see https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations
17
- # @example List authorizations for user ctshryock
18
- # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
19
- # client.authorizations
20
- def authorizations(options = {})
21
- paginate 'authorizations', options
22
- end
23
-
24
- # Get a single authorization for the authenticated user.
25
- #
26
- # You can only access your own tokens, and only through
27
- # Basic Authentication.
28
- #
29
- # @return [Sawyer::Resource] A single authorization for the authenticated user
30
- # @see https://developer.github.com/v3/oauth_authorizations/#get-a-single-authorization
31
- # @example Show authorization for user ctshryock's Travis auth
32
- # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
33
- # client.authorization(999999)
34
- def authorization(number, options = {})
35
- get "authorizations/#{number}", options
36
- end
37
-
38
- # Create an authorization for the authenticated user.
39
- #
40
- # You can create your own tokens, and only through
41
- # Basic Authentication.
42
- #
43
- # @param options [Hash] A customizable set of options.
44
- # @option options [Array] :scopes A list of scopes that this authorization is in.
45
- # @option options [String] :note A note to remind you what the OAuth token is for.
46
- # @option options [String] :note_url A URL to remind you what app the OAuth token is for.
47
- # @option options [Boolean] :idempotent If true, will return an existing authorization if one has already been created.
48
- # @option options [String] :client_id Client Id we received when our application was registered with GitHub.
49
- # @option options [String] :client_secret Client Secret we received when our application was registered with GitHub.
50
- #
51
- # @return [Sawyer::Resource] A single authorization for the authenticated user
52
- # @see https://developer.github.com/v3/oauth/#scopes Available scopes
53
- # @see https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization
54
- # @see https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app
55
- # @example Create a new authorization for user ctshryock's project Zoidberg
56
- # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
57
- # client.create_authorization({:scopes => ["public_repo", "gist"], :note => "Why not Zoidberg?", :note_url=> "https://en.wikipedia.org/wiki/Zoidberg"})
58
- # @example Create a new OR return an existing authorization to be used by a specific client for user ctshryock's project Zoidberg
59
- # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
60
- # client.create_authorization({:idempotent => true, :client_id => 'xxxx', :client_secret => 'yyyy', :scopes => ["user"]})
61
- def create_authorization(options = {})
62
- # Technically we can omit scopes as GitHub has a default, however the
63
- # API will reject us if we send a POST request with an empty body.
64
- options = options.dup
65
- if options.delete :idempotent
66
- client_id, client_secret = fetch_client_id_and_secret(options)
67
- unless client_id && client_secret
68
- raise ArgumentError, 'Client ID and Secret required for idempotent authorizations'
69
- end
70
-
71
- # Remove the client_id from the body otherwise
72
- # this will result in a 422.
73
- options.delete(:client_id)
74
-
75
- if (fingerprint = options.delete(:fingerprint))
76
- put "authorizations/clients/#{client_id}/#{fingerprint}", options.merge(client_secret: client_secret)
77
- else
78
- put "authorizations/clients/#{client_id}", options.merge(client_secret: client_secret)
79
- end
80
-
81
- else
82
- post 'authorizations', options
83
- end
84
- end
85
-
86
- # Update an authorization for the authenticated user.
87
- #
88
- # You can update your own tokens, but only through
89
- # Basic Authentication.
90
- #
91
- # @param options [Hash] A customizable set of options.
92
- # @option options [Array] :scopes Replace the authorization scopes with these.
93
- # @option options [Array] :add_scopes A list of scopes to add to this authorization.
94
- # @option options [Array] :remove_scopes A list of scopes to remove from this authorization.
95
- # @option options [String] :note A note to remind you what the OAuth token is for.
96
- # @option options [String] :note_url A URL to remind you what app the OAuth token is for.
97
- #
98
- # @return [Sawyer::Resource] A single (updated) authorization for the authenticated user
99
- # @see https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization
100
- # @see https://developer.github.com/v3/oauth/#scopes for available scopes
101
- # @example Update the authorization for user ctshryock's project Zoidberg
102
- # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
103
- # client.update_authorization(999999, {:add_scopes => ["gist", "repo"], :note => "Why not Zoidberg possibly?"})
104
- def update_authorization(number, options = {})
105
- patch "authorizations/#{number}", options
106
- end
107
-
108
- # Delete an authorization for the authenticated user.
109
- #
110
- # You can delete your own tokens, and only through
111
- # Basic Authentication.
112
- #
113
- # @param number [Number] An existing Authorization ID
114
- #
115
- # @return [Boolean] Success
116
- # @see https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization
117
- # @example Delete an authorization
118
- # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
119
- # client.delete_authorization(999999)
120
- def delete_authorization(number, options = {})
121
- boolean_from_response :delete, "authorizations/#{number}", options
122
- end
123
-
124
- # Check scopes for a token
125
- #
126
- # @param token [String] GitHub OAuth token
127
- # @param options [Hash] Header params for request
128
- # @return [Array<String>] OAuth scopes
129
- # @see https://developer.github.com/v3/oauth/#scopes
130
- def scopes(token = @access_token, options = {})
131
- options = options.dup
132
- raise ArgumentError, 'Access token required' if token.nil?
133
-
134
- auth = { 'Authorization' => "token #{token}" }
135
- headers = (options.delete(:headers) || {}).merge(auth)
136
-
137
- agent.call(:get, 'user', headers: headers)
138
- .headers['X-OAuth-Scopes']
139
- .to_s
140
- .split(',')
141
- .map(&:strip)
142
- .sort
143
- end
144
-
145
- # Revoke all tokens for an app
146
- #
147
- # Applications can revoke all of their tokens in a single request
148
- #
149
- # @deprecated As of January 25th, 2016: https://developer.github.com/changes/2014-04-08-reset-api-tokens/
150
- # @return [Boolean] false
151
- def revoke_all_application_authorizations(_options = {})
152
- octokit_warn('Deprecated: If you need to revoke all tokens for your application, you can do so via the settings page for your application.')
153
- false
154
- end
155
-
156
- # Get the URL to authorize a user for an application via the web flow
157
- #
158
- # @param app_id [String] Client Id we received when our application was registered with GitHub.
159
- # @option options [String] :redirect_uri The url to redirect to after authorizing.
160
- # @option options [String] :scope The scopes to request from the user.
161
- # @option options [String] :state A random string to protect against CSRF.
162
- # @return [String] The url to redirect the user to authorize.
163
- # @see Octokit::Client
164
- # @see https://developer.github.com/v3/oauth/#web-application-flow
165
- # @example
166
- # @client.authorize_url('xxxx')
167
- def authorize_url(app_id = client_id, options = {})
168
- opts = options.dup
169
- if app_id.to_s.empty?
170
- raise Octokit::ApplicationCredentialsRequired, 'client_id required'
171
- end
172
-
173
- authorize_url = opts.delete(:endpoint) || Octokit.web_endpoint
174
- authorize_url << "login/oauth/authorize?client_id=#{app_id}"
175
-
176
- require 'cgi'
177
- opts.each do |key, value|
178
- authorize_url << "&#{key}=#{CGI.escape value}"
179
- end
180
-
181
- authorize_url
182
- end
183
- end
184
- end
185
- end