octokit 4.22.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +113 -75
  3. data/Rakefile +20 -14
  4. data/lib/ext/sawyer/relation.rb +4 -2
  5. data/lib/octokit/arguments.rb +2 -2
  6. data/lib/octokit/authentication.rb +10 -3
  7. data/lib/octokit/client/actions_artifacts.rb +71 -0
  8. data/lib/octokit/client/actions_secrets.rb +10 -9
  9. data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
  10. data/lib/octokit/client/actions_workflow_runs.rb +23 -3
  11. data/lib/octokit/client/actions_workflows.rb +27 -2
  12. data/lib/octokit/client/apps.rb +26 -26
  13. data/lib/octokit/client/checks.rb +18 -9
  14. data/lib/octokit/client/code_scanning.rb +53 -0
  15. data/lib/octokit/client/codespaces_secrets.rb +59 -0
  16. data/lib/octokit/client/commit_branches.rb +2 -2
  17. data/lib/octokit/client/commit_comments.rb +8 -8
  18. data/lib/octokit/client/commit_pulls.rb +2 -2
  19. data/lib/octokit/client/commits.rb +25 -33
  20. data/lib/octokit/client/community_profile.rb +2 -3
  21. data/lib/octokit/client/contents.rb +20 -21
  22. data/lib/octokit/client/dependabot_secrets.rb +59 -0
  23. data/lib/octokit/client/deployments.rb +6 -6
  24. data/lib/octokit/client/downloads.rb +5 -6
  25. data/lib/octokit/client/emojis.rb +3 -3
  26. data/lib/octokit/client/environments.rb +55 -0
  27. data/lib/octokit/client/events.rb +4 -5
  28. data/lib/octokit/client/feeds.rb +4 -5
  29. data/lib/octokit/client/gists.rb +6 -6
  30. data/lib/octokit/client/gitignore.rb +3 -3
  31. data/lib/octokit/client/hooks.rb +9 -19
  32. data/lib/octokit/client/issues.rb +14 -15
  33. data/lib/octokit/client/labels.rb +10 -10
  34. data/lib/octokit/client/legacy_search.rb +3 -3
  35. data/lib/octokit/client/licenses.rb +3 -6
  36. data/lib/octokit/client/markdown.rb +3 -3
  37. data/lib/octokit/client/marketplace.rb +4 -4
  38. data/lib/octokit/client/meta.rb +4 -5
  39. data/lib/octokit/client/milestones.rb +5 -5
  40. data/lib/octokit/client/notifications.rb +6 -6
  41. data/lib/octokit/client/oauth_applications.rb +0 -6
  42. data/lib/octokit/client/objects.rb +14 -14
  43. data/lib/octokit/client/organizations.rb +100 -56
  44. data/lib/octokit/client/pages.rb +5 -7
  45. data/lib/octokit/client/projects.rb +44 -64
  46. data/lib/octokit/client/pub_sub_hubbub.rb +15 -15
  47. data/lib/octokit/client/pull_requests.rb +54 -42
  48. data/lib/octokit/client/rate_limit.rb +9 -11
  49. data/lib/octokit/client/reactions.rb +13 -16
  50. data/lib/octokit/client/refs.rb +14 -17
  51. data/lib/octokit/client/releases.rb +13 -13
  52. data/lib/octokit/client/repositories.rb +49 -69
  53. data/lib/octokit/client/repository_invitations.rb +3 -3
  54. data/lib/octokit/client/reviews.rb +8 -8
  55. data/lib/octokit/client/say.rb +4 -5
  56. data/lib/octokit/client/search.rb +24 -10
  57. data/lib/octokit/client/service_status.rb +19 -9
  58. data/lib/octokit/client/source_import.rb +7 -12
  59. data/lib/octokit/client/stats.rb +10 -9
  60. data/lib/octokit/client/statuses.rb +5 -5
  61. data/lib/octokit/client/tokens.rb +31 -0
  62. data/lib/octokit/client/traffic.rb +6 -11
  63. data/lib/octokit/client/users.rb +27 -33
  64. data/lib/octokit/client.rb +40 -16
  65. data/lib/octokit/configurable.rb +34 -30
  66. data/lib/octokit/connection.rb +28 -21
  67. data/lib/octokit/default.rb +48 -35
  68. data/lib/octokit/enterprise_admin_client/admin_stats.rb +13 -14
  69. data/lib/octokit/enterprise_admin_client/license.rb +3 -4
  70. data/lib/octokit/enterprise_admin_client/orgs.rb +3 -4
  71. data/lib/octokit/enterprise_admin_client/search_indexing.rb +7 -8
  72. data/lib/octokit/enterprise_admin_client/users.rb +5 -4
  73. data/lib/octokit/enterprise_admin_client.rb +9 -3
  74. data/lib/octokit/enterprise_management_console_client/management_console.rb +32 -32
  75. data/lib/octokit/enterprise_management_console_client.rb +8 -2
  76. data/lib/octokit/error.rb +45 -34
  77. data/lib/octokit/gist.rb +3 -4
  78. data/lib/octokit/middleware/follow_redirects.rb +12 -11
  79. data/lib/octokit/organization.rb +3 -1
  80. data/lib/octokit/rate_limit.rb +8 -6
  81. data/lib/octokit/repo_arguments.rb +2 -3
  82. data/lib/octokit/repository.rb +24 -24
  83. data/lib/octokit/response/base_middleware.rb +10 -0
  84. data/lib/octokit/response/feed_parser.rb +5 -7
  85. data/lib/octokit/response/raise_error.rb +4 -4
  86. data/lib/octokit/user.rb +4 -2
  87. data/lib/octokit/version.rb +4 -2
  88. data/lib/octokit/warnable.rb +4 -5
  89. data/lib/octokit.rb +15 -8
  90. data/octokit.gemspec +12 -11
  91. metadata +20 -33
  92. data/lib/octokit/client/authorizations.rb +0 -182
  93. data/lib/octokit/preview.rb +0 -46
@@ -1,19 +1,21 @@
1
- module Octokit
1
+ # frozen_string_literal: true
2
2
 
3
+ module Octokit
3
4
  # Class to parse GitHub repository owner and name from
4
5
  # URLs and to generate URLs
5
6
  class Repository
6
7
  attr_accessor :owner, :name, :id
7
- NAME_WITH_OWNER_PATTERN = /\A[\w.-]+\/[\w.-]+\z/i
8
+
9
+ NAME_WITH_OWNER_PATTERN = %r{\A[\w.-]+/[\w.-]+\z}i.freeze
8
10
 
9
11
  # Instantiate from a GitHub repository URL
10
12
  #
11
13
  # @return [Repository]
12
14
  def self.from_url(url)
13
- new URI.parse(url).path[1..-1].
14
- gsub(/^repos\//,'').
15
- split('/', 3)[0..1].
16
- join('/')
15
+ new URI.parse(url).path[1..]
16
+ .gsub(%r{^repos/}, '')
17
+ .split('/', 3)[0..1]
18
+ .join('/')
17
19
  end
18
20
 
19
21
  # @raise [Octokit::InvalidRepository] if the repository
@@ -23,7 +25,7 @@ module Octokit
23
25
  when Integer
24
26
  @id = repo
25
27
  when NAME_WITH_OWNER_PATTERN
26
- @owner, @name = repo.split("/")
28
+ @owner, @name = repo.split('/')
27
29
  when Repository
28
30
  @owner = repo.owner
29
31
  @name = repo.name
@@ -33,9 +35,7 @@ module Octokit
33
35
  else
34
36
  raise_invalid_repository!(repo)
35
37
  end
36
- if @owner && @name
37
- validate_owner_and_name!(repo)
38
- end
38
+ validate_owner_and_name!(repo) if @owner && @name
39
39
  end
40
40
 
41
41
  # Repository owner/name
@@ -43,7 +43,7 @@ module Octokit
43
43
  def slug
44
44
  "#{@owner}/#{@name}"
45
45
  end
46
- alias :to_s :slug
46
+ alias to_s slug
47
47
 
48
48
  # @return [String] Repository API path
49
49
  def path
@@ -54,7 +54,7 @@ module Octokit
54
54
  # Get the api path for a repo
55
55
  # @param repo [Integer, String, Hash, Repository] A GitHub repository.
56
56
  # @return [String] Api path.
57
- def self.path repo
57
+ def self.path(repo)
58
58
  new(repo).path
59
59
  end
60
60
 
@@ -74,22 +74,22 @@ module Octokit
74
74
  "#{Octokit.web_endpoint}#{slug}"
75
75
  end
76
76
 
77
- alias :user :owner
78
- alias :username :owner
79
- alias :repo :name
77
+ alias user owner
78
+ alias username owner
79
+ alias repo name
80
80
 
81
81
  private
82
82
 
83
- def validate_owner_and_name!(repo)
84
- if @owner.include?('/') || @name.include?('/') || !url.match(URI::ABS_URI)
85
- raise_invalid_repository!(repo)
86
- end
83
+ def validate_owner_and_name!(repo)
84
+ if @owner.include?('/') || @name.include?('/') || !url.match(URI::ABS_URI)
85
+ raise_invalid_repository!(repo)
87
86
  end
87
+ end
88
88
 
89
- def raise_invalid_repository!(repo)
90
- msg = "#{repo.inspect} is invalid as a repository identifier. " +
91
- "Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys."
92
- raise Octokit::InvalidRepository, msg
93
- end
89
+ def raise_invalid_repository!(repo)
90
+ msg = "#{repo.inspect} is invalid as a repository identifier. " \
91
+ 'Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.'
92
+ raise Octokit::InvalidRepository, msg
93
+ end
94
94
  end
95
95
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Octokit
6
+ module Response
7
+ # In Faraday 2.x, Faraday::Response::Middleware was removed
8
+ BaseMiddleware = defined?(Faraday::Response::Middleware) ? Faraday::Response::Middleware : Faraday::Middleware
9
+ end
10
+ end
@@ -1,19 +1,17 @@
1
- require 'faraday'
1
+ # frozen_string_literal: true
2
2
 
3
- module Octokit
3
+ require 'octokit/response/base_middleware'
4
4
 
5
+ module Octokit
5
6
  module Response
6
-
7
7
  # Parses RSS and Atom feed responses.
8
- class FeedParser < Faraday::Response::Middleware
9
-
8
+ class FeedParser < BaseMiddleware
10
9
  def on_complete(env)
11
- if env[:response_headers]["content-type"] =~ /(\batom|\brss)/
10
+ if env[:response_headers]['content-type'] =~ /(\batom|\brss)/
12
11
  require 'rss'
13
12
  env[:body] = RSS::Parser.parse env[:body]
14
13
  end
15
14
  end
16
-
17
15
  end
18
16
  end
19
17
  end
@@ -1,14 +1,14 @@
1
- require 'faraday'
1
+ # frozen_string_literal: true
2
+
3
+ require 'octokit/response/base_middleware'
2
4
  require 'octokit/error'
3
5
 
4
6
  module Octokit
5
7
  # Faraday response middleware
6
8
  module Response
7
-
8
9
  # This class raises an Octokit-flavored exception based
9
10
  # HTTP status codes returned by the API
10
- class RaiseError < Faraday::Response::Middleware
11
-
11
+ class RaiseError < BaseMiddleware
12
12
  def on_complete(response)
13
13
  if error = Octokit::Error.from_response(response)
14
14
  raise error
data/lib/octokit/user.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  # GitHub user class to generate API path urls
3
5
  class User
@@ -5,14 +7,14 @@ module Octokit
5
7
  #
6
8
  # @param user [String, Integer] GitHub user login or id
7
9
  # @return [String] User Api path
8
- def self.path user
10
+ def self.path(user)
9
11
  case user
10
12
  when String
11
13
  "users/#{user}"
12
14
  when Integer
13
15
  "user/#{user}"
14
16
  else
15
- "user"
17
+ 'user'
16
18
  end
17
19
  end
18
20
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  # Current major release.
3
5
  # @return [Integer]
4
- MAJOR = 4
6
+ MAJOR = 7
5
7
 
6
8
  # Current minor release.
7
9
  # @return [Integer]
8
- MINOR = 22
10
+ MINOR = 0
9
11
 
10
12
  # Current patch level.
11
13
  # @return [Integer]
@@ -1,17 +1,16 @@
1
- module Octokit
1
+ # frozen_string_literal: true
2
2
 
3
+ module Octokit
3
4
  # Allows warnings to be suppressed via environment variable.
4
5
  module Warnable
6
+ module_function
5
7
 
6
8
  # Wrapper around Kernel#warn to print warnings unless
7
9
  # OCTOKIT_SILENT is set to true.
8
10
  #
9
11
  # @return [nil]
10
12
  def octokit_warn(*message)
11
- unless ENV['OCTOKIT_SILENT']
12
- warn message
13
- end
13
+ warn message unless ENV['OCTOKIT_SILENT']
14
14
  end
15
15
  end
16
16
  end
17
-
data/lib/octokit.rb CHANGED
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'octokit/default'
1
4
  require 'octokit/client'
2
5
  require 'octokit/enterprise_admin_client'
3
6
  require 'octokit/enterprise_management_console_client'
4
- require 'octokit/default'
5
7
 
6
8
  # Ruby toolkit for the GitHub API
7
9
  module Octokit
8
-
9
10
  class << self
10
11
  include Octokit::Configurable
11
12
 
@@ -14,6 +15,7 @@ module Octokit
14
15
  # @return [Octokit::Client] API wrapper
15
16
  def client
16
17
  return @client if defined?(@client) && @client.same_options?(options)
18
+
17
19
  @client = Octokit::Client.new(options)
18
20
  end
19
21
 
@@ -21,7 +23,10 @@ module Octokit
21
23
  #
22
24
  # @return [Octokit::EnterpriseAdminClient] API wrapper
23
25
  def enterprise_admin_client
24
- return @enterprise_admin_client if defined?(@enterprise_admin_client) && @enterprise_admin_client.same_options?(options)
26
+ if defined?(@enterprise_admin_client) && @enterprise_admin_client.same_options?(options)
27
+ return @enterprise_admin_client
28
+ end
29
+
25
30
  @enterprise_admin_client = Octokit::EnterpriseAdminClient.new(options)
26
31
  end
27
32
 
@@ -29,16 +34,19 @@ module Octokit
29
34
  #
30
35
  # @return [Octokit::EnterpriseManagementConsoleClient] API wrapper
31
36
  def enterprise_management_console_client
32
- return @enterprise_management_console_client if defined?(@enterprise_management_console_client) && @enterprise_management_console_client.same_options?(options)
37
+ if defined?(@enterprise_management_console_client) && @enterprise_management_console_client.same_options?(options)
38
+ return @enterprise_management_console_client
39
+ end
40
+
33
41
  @enterprise_management_console_client = Octokit::EnterpriseManagementConsoleClient.new(options)
34
42
  end
35
43
 
36
44
  private
37
45
 
38
- def respond_to_missing?(method_name, include_private=false)
46
+ def respond_to_missing?(method_name, include_private = false)
39
47
  client.respond_to?(method_name, include_private) ||
40
- enterprise_admin_client.respond_to?(method_name, include_private) ||
41
- enterprise_management_console_client.respond_to?(method_name, include_private)
48
+ enterprise_admin_client.respond_to?(method_name, include_private) ||
49
+ enterprise_management_console_client.respond_to?(method_name, include_private)
42
50
  end
43
51
 
44
52
  def method_missing(method_name, *args, &block)
@@ -52,7 +60,6 @@ module Octokit
52
60
 
53
61
  super
54
62
  end
55
-
56
63
  end
57
64
  end
58
65
 
data/octokit.gemspec CHANGED
@@ -1,23 +1,24 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'octokit/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
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'
10
- spec.authors = ["Wynn Netherland", "Erik Michaels-Ober", "Clint Shryock"]
11
- spec.description = %q{Simple wrapper for the GitHub API}
8
+ spec.add_dependency 'faraday', '>= 1', '< 3'
9
+ spec.add_dependency 'sawyer', '~> 0.9'
10
+ spec.authors = ['Wynn Netherland', 'Erik Michaels-Ober', 'Clint Shryock']
11
+ spec.description = 'Simple wrapper for the GitHub API'
12
12
  spec.email = ['wynn.netherland@gmail.com', 'sferik@gmail.com', 'clint@ctshryock.com']
13
- spec.files = %w(.document CONTRIBUTING.md LICENSE.md README.md Rakefile octokit.gemspec)
14
- spec.files += Dir.glob("lib/**/*.rb")
13
+ spec.files = %w[.document CONTRIBUTING.md LICENSE.md README.md Rakefile octokit.gemspec]
14
+ spec.files += Dir.glob('lib/**/*.rb')
15
15
  spec.homepage = 'https://github.com/octokit/octokit.rb'
16
16
  spec.licenses = ['MIT']
17
17
  spec.name = 'octokit'
18
18
  spec.require_paths = ['lib']
19
- spec.required_ruby_version = '>= 2.0.0'
19
+ spec.required_ruby_version = '>= 2.7.0'
20
20
  spec.required_rubygems_version = '>= 1.3.5'
21
- spec.summary = "Ruby toolkit for working with the GitHub API"
21
+ spec.summary = 'Ruby toolkit for working with the GitHub API'
22
22
  spec.version = Octokit::VERSION.dup
23
+ spec.metadata = { 'rubygems_mfa_required' => 'true' }
23
24
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.22.0
4
+ version: 7.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-01-12 00:00:00.000000000 Z
13
+ date: 2023-07-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: bundler
16
+ name: faraday
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ">="
@@ -22,7 +22,7 @@ dependencies:
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
24
  version: '3'
25
- type: :development
25
+ type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
@@ -36,34 +36,14 @@ 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
- - - "~>"
43
- - !ruby/object:Gem::Version
44
- version: 0.8.0
45
- type: :runtime
46
- prerelease: false
47
- version_requirements: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: 0.5.3
52
39
  - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.8.0
55
- - !ruby/object:Gem::Dependency
56
- name: faraday
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
40
  - !ruby/object:Gem::Version
61
41
  version: '0.9'
62
42
  type: :runtime
63
43
  prerelease: false
64
44
  version_requirements: !ruby/object:Gem::Requirement
65
45
  requirements:
66
- - - ">="
46
+ - - "~>"
67
47
  - !ruby/object:Gem::Version
68
48
  version: '0.9'
69
49
  description: Simple wrapper for the GitHub API
@@ -85,21 +65,26 @@ files:
85
65
  - lib/octokit/arguments.rb
86
66
  - lib/octokit/authentication.rb
87
67
  - lib/octokit/client.rb
68
+ - lib/octokit/client/actions_artifacts.rb
88
69
  - lib/octokit/client/actions_secrets.rb
70
+ - lib/octokit/client/actions_workflow_jobs.rb
89
71
  - lib/octokit/client/actions_workflow_runs.rb
90
72
  - lib/octokit/client/actions_workflows.rb
91
73
  - lib/octokit/client/apps.rb
92
- - lib/octokit/client/authorizations.rb
93
74
  - lib/octokit/client/checks.rb
75
+ - lib/octokit/client/code_scanning.rb
76
+ - lib/octokit/client/codespaces_secrets.rb
94
77
  - lib/octokit/client/commit_branches.rb
95
78
  - lib/octokit/client/commit_comments.rb
96
79
  - lib/octokit/client/commit_pulls.rb
97
80
  - lib/octokit/client/commits.rb
98
81
  - lib/octokit/client/community_profile.rb
99
82
  - lib/octokit/client/contents.rb
83
+ - lib/octokit/client/dependabot_secrets.rb
100
84
  - lib/octokit/client/deployments.rb
101
85
  - lib/octokit/client/downloads.rb
102
86
  - lib/octokit/client/emojis.rb
87
+ - lib/octokit/client/environments.rb
103
88
  - lib/octokit/client/events.rb
104
89
  - lib/octokit/client/feeds.rb
105
90
  - lib/octokit/client/gists.rb
@@ -134,6 +119,7 @@ files:
134
119
  - lib/octokit/client/source_import.rb
135
120
  - lib/octokit/client/stats.rb
136
121
  - lib/octokit/client/statuses.rb
122
+ - lib/octokit/client/tokens.rb
137
123
  - lib/octokit/client/traffic.rb
138
124
  - lib/octokit/client/users.rb
139
125
  - lib/octokit/configurable.rb
@@ -151,10 +137,10 @@ files:
151
137
  - lib/octokit/gist.rb
152
138
  - lib/octokit/middleware/follow_redirects.rb
153
139
  - lib/octokit/organization.rb
154
- - lib/octokit/preview.rb
155
140
  - lib/octokit/rate_limit.rb
156
141
  - lib/octokit/repo_arguments.rb
157
142
  - lib/octokit/repository.rb
143
+ - lib/octokit/response/base_middleware.rb
158
144
  - lib/octokit/response/feed_parser.rb
159
145
  - lib/octokit/response/raise_error.rb
160
146
  - lib/octokit/user.rb
@@ -164,8 +150,9 @@ files:
164
150
  homepage: https://github.com/octokit/octokit.rb
165
151
  licenses:
166
152
  - MIT
167
- metadata: {}
168
- post_install_message:
153
+ metadata:
154
+ rubygems_mfa_required: 'true'
155
+ post_install_message:
169
156
  rdoc_options: []
170
157
  require_paths:
171
158
  - lib
@@ -173,15 +160,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
160
  requirements:
174
161
  - - ">="
175
162
  - !ruby/object:Gem::Version
176
- version: 2.0.0
163
+ version: 2.7.0
177
164
  required_rubygems_version: !ruby/object:Gem::Requirement
178
165
  requirements:
179
166
  - - ">="
180
167
  - !ruby/object:Gem::Version
181
168
  version: 1.3.5
182
169
  requirements: []
183
- rubygems_version: 3.1.2
184
- signing_key:
170
+ rubygems_version: 3.4.0.dev
171
+ signing_key:
185
172
  specification_version: 4
186
173
  summary: Ruby toolkit for working with the GitHub API
187
174
  test_files: []
@@ -1,182 +0,0 @@
1
- module Octokit
2
- class Client
3
-
4
- # Methods for the Authorizations API
5
- #
6
- # @see https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api
7
- module Authorizations
8
-
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
- raise ArgumentError.new("Client ID and Secret required for idempotent authorizations") unless client_id && client_secret
68
-
69
- # Remove the client_id from the body otherwise
70
- # this will result in a 422.
71
- options.delete(:client_id)
72
-
73
- if (fingerprint = options.delete(:fingerprint))
74
- put "authorizations/clients/#{client_id}/#{fingerprint}", options.merge(:client_secret => client_secret)
75
- else
76
- put "authorizations/clients/#{client_id}", options.merge(:client_secret => client_secret)
77
- end
78
-
79
- else
80
- post 'authorizations', options
81
- end
82
- end
83
-
84
- # Update an authorization for the authenticated user.
85
- #
86
- # You can update your own tokens, but only through
87
- # Basic Authentication.
88
- #
89
- # @param options [Hash] A customizable set of options.
90
- # @option options [Array] :scopes Replace the authorization scopes with these.
91
- # @option options [Array] :add_scopes A list of scopes to add to this authorization.
92
- # @option options [Array] :remove_scopes A list of scopes to remove from this authorization.
93
- # @option options [String] :note A note to remind you what the OAuth token is for.
94
- # @option options [String] :note_url A URL to remind you what app the OAuth token is for.
95
- #
96
- # @return [Sawyer::Resource] A single (updated) authorization for the authenticated user
97
- # @see https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization
98
- # @see https://developer.github.com/v3/oauth/#scopes for available scopes
99
- # @example Update the authorization for user ctshryock's project Zoidberg
100
- # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
101
- # client.update_authorization(999999, {:add_scopes => ["gist", "repo"], :note => "Why not Zoidberg possibly?"})
102
- def update_authorization(number, options = {})
103
- patch "authorizations/#{number}", options
104
- end
105
-
106
- # Delete an authorization for the authenticated user.
107
- #
108
- # You can delete your own tokens, and only through
109
- # Basic Authentication.
110
- #
111
- # @param number [Number] An existing Authorization ID
112
- #
113
- # @return [Boolean] Success
114
- # @see https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization
115
- # @example Delete an authorization
116
- # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
117
- # client.delete_authorization(999999)
118
- def delete_authorization(number, options = {})
119
- boolean_from_response :delete, "authorizations/#{number}", options
120
- end
121
-
122
- # Check scopes for a token
123
- #
124
- # @param token [String] GitHub OAuth token
125
- # @param options [Hash] Header params for request
126
- # @return [Array<String>] OAuth scopes
127
- # @see https://developer.github.com/v3/oauth/#scopes
128
- def scopes(token = @access_token, options = {})
129
- options= options.dup
130
- raise ArgumentError.new("Access token required") if token.nil?
131
-
132
- auth = { "Authorization" => "token #{token}" }
133
- headers = (options.delete(:headers) || {}).merge(auth)
134
-
135
- agent.call(:get, "user", :headers => headers).
136
- headers['X-OAuth-Scopes'].
137
- to_s.
138
- split(',').
139
- map(&:strip).
140
- sort
141
- end
142
-
143
- # Revoke all tokens for an app
144
- #
145
- # Applications can revoke all of their tokens in a single request
146
- #
147
- # @deprecated As of January 25th, 2016: https://developer.github.com/changes/2014-04-08-reset-api-tokens/
148
- # @return [Boolean] false
149
- def revoke_all_application_authorizations(options = {})
150
- octokit_warn("Deprecated: If you need to revoke all tokens for your application, you can do so via the settings page for your application.")
151
- false
152
- end
153
-
154
- # Get the URL to authorize a user for an application via the web flow
155
- #
156
- # @param app_id [String] Client Id we received when our application was registered with GitHub.
157
- # @option options [String] :redirect_uri The url to redirect to after authorizing.
158
- # @option options [String] :scope The scopes to request from the user.
159
- # @option options [String] :state A random string to protect against CSRF.
160
- # @return [String] The url to redirect the user to authorize.
161
- # @see Octokit::Client
162
- # @see https://developer.github.com/v3/oauth/#web-application-flow
163
- # @example
164
- # @client.authorize_url('xxxx')
165
- def authorize_url(app_id = client_id, options = {})
166
- opts = options.dup
167
- if app_id.to_s.empty?
168
- raise Octokit::ApplicationCredentialsRequired, "client_id required"
169
- end
170
- authorize_url = opts.delete(:endpoint) || Octokit.web_endpoint
171
- authorize_url << "login/oauth/authorize?client_id=#{app_id}"
172
-
173
- require 'cgi'
174
- opts.each do |key, value|
175
- authorize_url << "&#{key}=#{CGI.escape value}"
176
- end
177
-
178
- authorize_url
179
- end
180
- end
181
- end
182
- end