octokit 4.6.2 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +14 -13
  3. data/LICENSE.md +1 -1
  4. data/README.md +218 -109
  5. data/Rakefile +5 -3
  6. data/lib/ext/sawyer/relation.rb +4 -2
  7. data/lib/octokit/arguments.rb +2 -2
  8. data/lib/octokit/authentication.rb +20 -14
  9. data/lib/octokit/client/actions_secrets.rb +57 -0
  10. data/lib/octokit/client/actions_workflow_jobs.rb +61 -0
  11. data/lib/octokit/client/actions_workflow_runs.rb +121 -0
  12. data/lib/octokit/client/actions_workflows.rb +66 -0
  13. data/lib/octokit/client/apps.rb +222 -0
  14. data/lib/octokit/client/authorizations.rb +30 -89
  15. data/lib/octokit/client/checks.rb +200 -0
  16. data/lib/octokit/client/commit_branches.rb +20 -0
  17. data/lib/octokit/client/commit_comments.rb +8 -8
  18. data/lib/octokit/client/commit_pulls.rb +20 -0
  19. data/lib/octokit/client/commits.rb +31 -34
  20. data/lib/octokit/client/community_profile.rb +21 -0
  21. data/lib/octokit/client/contents.rb +25 -20
  22. data/lib/octokit/client/deployments.rb +25 -5
  23. data/lib/octokit/client/downloads.rb +5 -6
  24. data/lib/octokit/client/emojis.rb +3 -3
  25. data/lib/octokit/client/events.rb +4 -4
  26. data/lib/octokit/client/feeds.rb +4 -5
  27. data/lib/octokit/client/gists.rb +7 -6
  28. data/lib/octokit/client/gitignore.rb +3 -3
  29. data/lib/octokit/client/hooks.rb +10 -10
  30. data/lib/octokit/client/issues.rb +60 -14
  31. data/lib/octokit/client/labels.rb +17 -17
  32. data/lib/octokit/client/legacy_search.rb +3 -3
  33. data/lib/octokit/client/licenses.rb +4 -7
  34. data/lib/octokit/client/markdown.rb +3 -3
  35. data/lib/octokit/client/marketplace.rb +56 -0
  36. data/lib/octokit/client/meta.rb +4 -5
  37. data/lib/octokit/client/milestones.rb +5 -5
  38. data/lib/octokit/client/notifications.rb +6 -10
  39. data/lib/octokit/client/oauth_applications.rb +116 -0
  40. data/lib/octokit/client/objects.rb +14 -14
  41. data/lib/octokit/client/organizations.rb +181 -61
  42. data/lib/octokit/client/pages.rb +5 -7
  43. data/lib/octokit/client/projects.rb +49 -69
  44. data/lib/octokit/client/pub_sub_hubbub.rb +16 -16
  45. data/lib/octokit/client/pull_requests.rb +47 -46
  46. data/lib/octokit/client/rate_limit.rb +11 -13
  47. data/lib/octokit/client/reactions.rb +6 -11
  48. data/lib/octokit/client/refs.rb +33 -18
  49. data/lib/octokit/client/releases.rb +14 -13
  50. data/lib/octokit/client/repositories.rb +194 -53
  51. data/lib/octokit/client/repository_invitations.rb +4 -11
  52. data/lib/octokit/client/reviews.rb +227 -0
  53. data/lib/octokit/client/say.rb +4 -5
  54. data/lib/octokit/client/search.rb +45 -17
  55. data/lib/octokit/client/service_status.rb +19 -9
  56. data/lib/octokit/client/source_import.rb +8 -13
  57. data/lib/octokit/client/stats.rb +12 -9
  58. data/lib/octokit/client/statuses.rb +6 -6
  59. data/lib/octokit/client/traffic.rb +6 -11
  60. data/lib/octokit/client/users.rb +106 -25
  61. data/lib/octokit/client.rb +60 -15
  62. data/lib/octokit/configurable.rb +42 -30
  63. data/lib/octokit/connection.rb +34 -20
  64. data/lib/octokit/default.rb +61 -34
  65. data/lib/octokit/enterprise_admin_client/admin_stats.rb +14 -15
  66. data/lib/octokit/enterprise_admin_client/license.rb +4 -5
  67. data/lib/octokit/enterprise_admin_client/orgs.rb +5 -6
  68. data/lib/octokit/enterprise_admin_client/search_indexing.rb +8 -9
  69. data/lib/octokit/enterprise_admin_client/users.rb +17 -16
  70. data/lib/octokit/enterprise_admin_client.rb +9 -3
  71. data/lib/octokit/enterprise_management_console_client/management_console.rb +33 -33
  72. data/lib/octokit/enterprise_management_console_client.rb +9 -3
  73. data/lib/octokit/error.rb +106 -25
  74. data/lib/octokit/gist.rb +3 -4
  75. data/lib/octokit/middleware/follow_redirects.rb +17 -13
  76. data/lib/octokit/organization.rb +3 -1
  77. data/lib/octokit/rate_limit.rb +6 -6
  78. data/lib/octokit/repo_arguments.rb +2 -3
  79. data/lib/octokit/repository.rb +27 -25
  80. data/lib/octokit/response/base_middleware.rb +10 -0
  81. data/lib/octokit/response/feed_parser.rb +5 -9
  82. data/lib/octokit/response/raise_error.rb +4 -6
  83. data/lib/octokit/user.rb +4 -2
  84. data/lib/octokit/version.rb +5 -3
  85. data/lib/octokit/warnable.rb +4 -5
  86. data/lib/octokit.rb +15 -8
  87. data/octokit.gemspec +13 -10
  88. metadata +52 -21
  89. data/lib/octokit/preview.rb +0 -35
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the Traffic API
5
6
  #
6
7
  # @see https://developer.github.com/v3/repos/traffic/
7
8
  module Traffic
8
-
9
9
  # Get the top 10 referrers over the last 14 days
10
10
  #
11
11
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
@@ -14,8 +14,7 @@ module Octokit
14
14
  # @example
15
15
  # @client.top_referrers('octokit/octokit.rb')
16
16
  def top_referrers(repo, options = {})
17
- opts = ensure_api_media_type(:traffic, options)
18
- get "#{Repository.path repo}/traffic/popular/referrers", opts
17
+ get "#{Repository.path repo}/traffic/popular/referrers", options
19
18
  end
20
19
 
21
20
  # Get the top 10 popular contents over the last 14 days
@@ -26,8 +25,7 @@ module Octokit
26
25
  # @example
27
26
  # @client.top_paths('octokit/octokit.rb')
28
27
  def top_paths(repo, options = {})
29
- opts = ensure_api_media_type(:traffic, options)
30
- get "#{Repository.path repo}/traffic/popular/paths", opts
28
+ get "#{Repository.path repo}/traffic/popular/paths", options
31
29
  end
32
30
 
33
31
  # Get the total number of views and breakdown per day or week for the
@@ -43,8 +41,7 @@ module Octokit
43
41
  # @example Views per week
44
42
  # @client.views('octokit/octokit.rb', per: 'week')
45
43
  def views(repo, options = {})
46
- opts = ensure_api_media_type(:traffic, options)
47
- get "#{Repository.path repo}/traffic/views", opts
44
+ get "#{Repository.path repo}/traffic/views", options
48
45
  end
49
46
 
50
47
  # Get the total number of clones and breakdown per day or week for the
@@ -60,10 +57,8 @@ module Octokit
60
57
  # @example Clones per week
61
58
  # @client.clones('octokit/octokit.rb', per: 'week')
62
59
  def clones(repo, options = {})
63
- opts = ensure_api_media_type(:traffic, options)
64
- get "#{Repository.path repo}/traffic/clones", opts
60
+ get "#{Repository.path repo}/traffic/clones", options
65
61
  end
66
-
67
62
  end
68
63
  end
69
64
  end
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the Users API
5
6
  #
6
7
  # @see https://developer.github.com/v3/users/
7
8
  module Users
8
-
9
9
  # List all GitHub users
10
10
  #
11
11
  # This provides a list of every user, in the order that they signed up
@@ -19,7 +19,7 @@ module Octokit
19
19
  #
20
20
  # @return [Array<Sawyer::Resource>] List of GitHub users.
21
21
  def all_users(options = {})
22
- paginate "users", options
22
+ paginate 'users', options
23
23
  end
24
24
 
25
25
  # Get a single user
@@ -30,7 +30,7 @@ module Octokit
30
30
  # @see https://developer.github.com/v3/users/#get-the-authenticated-user
31
31
  # @example
32
32
  # Octokit.user("sferik")
33
- def user(user=nil, options = {})
33
+ def user(user = nil, options = {})
34
34
  get User.path(user), options
35
35
  end
36
36
 
@@ -44,15 +44,16 @@ module Octokit
44
44
  # @example
45
45
  # Octokit.exchange_code_for_token('aaaa', 'xxxx', 'yyyy', {:accept => 'application/json'})
46
46
  def exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {})
47
- options.merge!({
48
- :code => code,
49
- :client_id => app_id,
50
- :client_secret => app_secret,
51
- :headers => {
52
- :content_type => 'application/json',
53
- :accept => 'application/json'
54
- }
55
- })
47
+ options = options.merge({
48
+ code: code,
49
+ client_id: app_id,
50
+ client_secret: app_secret,
51
+ headers: {
52
+ content_type: 'application/json',
53
+ accept: 'application/json'
54
+ }
55
+ })
56
+
56
57
  post "#{web_endpoint}login/oauth/access_token", options
57
58
  end
58
59
 
@@ -83,7 +84,7 @@ module Octokit
83
84
  # @example
84
85
  # Octokit.update_user(:name => "Erik Michaels-Ober", :email => "sferik@gmail.com", :company => "Code for America", :location => "San Francisco", :hireable => false)
85
86
  def update_user(options)
86
- patch "user", options
87
+ patch 'user', options
87
88
  end
88
89
 
89
90
  # Get a user's followers.
@@ -95,7 +96,7 @@ module Octokit
95
96
  # @see https://developer.github.com/v3/users/followers/#list-followers-of-a-user
96
97
  # @example
97
98
  # Octokit.followers('pengwynn')
98
- def followers(user=login, options = {})
99
+ def followers(user = login, options = {})
99
100
  paginate "#{User.path user}/followers", options
100
101
  end
101
102
 
@@ -108,7 +109,7 @@ module Octokit
108
109
  # @see https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
109
110
  # @example
110
111
  # Octokit.following('pengwynn')
111
- def following(user=login, options = {})
112
+ def following(user = login, options = {})
112
113
  paginate "#{User.path user}/following", options
113
114
  end
114
115
 
@@ -173,7 +174,7 @@ module Octokit
173
174
  # @see https://developer.github.com/v3/activity/starring/#list-repositories-being-starred
174
175
  # @example
175
176
  # Octokit.starred('pengwynn')
176
- def starred(user=login, options = {})
177
+ def starred(user = login, options = {})
177
178
  paginate user_path(user, 'starred'), options
178
179
  end
179
180
 
@@ -226,7 +227,7 @@ module Octokit
226
227
  # @example
227
228
  # @client.keys
228
229
  def keys(options = {})
229
- paginate "user/keys", options
230
+ paginate 'user/keys', options
230
231
  end
231
232
 
232
233
  # Get list of public keys for user.
@@ -252,7 +253,7 @@ module Octokit
252
253
  # @example
253
254
  # @client.add_key('Personal projects key', 'ssh-rsa AAA...')
254
255
  def add_key(title, key, options = {})
255
- post "user/keys", options.merge({:title => title, :key => key})
256
+ post 'user/keys', options.merge({ title: title, key: key })
256
257
  end
257
258
 
258
259
  # Update a public key
@@ -296,7 +297,7 @@ module Octokit
296
297
  # @example
297
298
  # @client.emails
298
299
  def emails(options = {})
299
- paginate "user/emails", options
300
+ paginate 'user/emails', options
300
301
  end
301
302
 
302
303
  # Add email address to user.
@@ -308,9 +309,9 @@ module Octokit
308
309
  # @see https://developer.github.com/v3/users/emails/#add-email-addresses
309
310
  # @example
310
311
  # @client.add_email('new_email@user.com')
311
- def add_email(email, options = {})
312
+ def add_email(email, _options = {})
312
313
  email = Array(email)
313
- post "user/emails", email
314
+ post 'user/emails', email
314
315
  end
315
316
 
316
317
  # Remove email from user.
@@ -324,7 +325,7 @@ module Octokit
324
325
  # @client.remove_email('old_email@user.com')
325
326
  def remove_email(email)
326
327
  email = Array(email)
327
- boolean_from_response :delete, "user/emails", email
328
+ boolean_from_response :delete, 'user/emails', email
328
329
  end
329
330
 
330
331
  # List repositories being watched by a user.
@@ -334,14 +335,94 @@ module Octokit
334
335
  # @see https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
335
336
  # @example
336
337
  # @client.subscriptions("pengwynn")
337
- def subscriptions(user=login, options = {})
338
+ def subscriptions(user = login, options = {})
338
339
  paginate user_path(user, 'subscriptions'), options
339
340
  end
340
- alias :watched :subscriptions
341
+ alias watched subscriptions
342
+
343
+ # Initiates the generation of a migration archive.
344
+ #
345
+ # Requires authenticated user.
346
+ #
347
+ # @param repositories [Array<String>] :repositories Repositories for the organization.
348
+ # @option options [Boolean, optional] :lock_repositories Indicates whether repositories should be locked during migration
349
+ # @option options [Boolean, optional] :exclude_attachments Exclude attachments fro the migration data
350
+ # @return [Sawyer::Resource] Hash representing the new migration.
351
+ # @example
352
+ # @client.start_migration(['octocat/hello-world'])
353
+ # @see https://docs.github.com/en/rest/reference/migrations#start-a-user-migration
354
+ def start_user_migration(repositories, options = {})
355
+ options[:repositories] = repositories
356
+ post 'user/migrations', options
357
+ end
358
+
359
+ # Lists the most recent migrations.
360
+ #
361
+ # Requires authenticated user.
362
+ #
363
+ # @return [Array<Sawyer::Resource>] Array of migration resources.
364
+ # @see https://docs.github.com/en/rest/reference/migrations#list-user-migrations
365
+ def user_migrations(options = {})
366
+ paginate 'user/migrations', options
367
+ end
368
+
369
+ # Fetches the status of a migration.
370
+ #
371
+ # Requires authenticated user.
372
+ #
373
+ # @param id [Integer] ID number of the migration.
374
+ # @see https://docs.github.com/en/rest/reference/migrations#get-a-user-migration-status
375
+ def user_migration_status(id, options = {})
376
+ get "user/migrations/#{id}", options
377
+ end
341
378
 
379
+ # Fetches the URL to a migration archive.
380
+ #
381
+ # Requires authenticated user.
382
+ #
383
+ # @param id [Integer] ID number of the migration.
384
+ # @see https://docs.github.com/en/rest/reference/migrations#download-a-user-migration-archive
385
+ def user_migration_archive_url(id, options = {})
386
+ url = "user/migrations/#{id}/archive"
387
+
388
+ response = client_without_redirects(options).get(url)
389
+ response.headers['location']
390
+ end
391
+
392
+ # Deletes a previous migration archive.
393
+ #
394
+ # Requires authenticated user.
395
+ #
396
+ # @param id [Integer] ID number of the migration.
397
+ # @see https://docs.github.com/en/rest/reference/migrations#delete-a-user-migration-archive
398
+ def delete_user_migration_archive(id, options = {})
399
+ delete "user/migrations/#{id}/archive", options
400
+ end
401
+
402
+ # List repositories for a user migration.
403
+ #
404
+ # Requires authenticated user.
405
+ #
406
+ # @param id [Integer] ID number of the migration.
407
+ # @see https://docs.github.com/en/rest/reference/migrations#list-repositories-for-a-user-migration
408
+ def user_migration_repositories(id, options = {})
409
+ get "user/migrations/#{id}/repositories", options
410
+ end
411
+
412
+ # Unlock a user repository which has been locked by a migration.
413
+ #
414
+ # Requires authenticated user.
415
+ #
416
+ # @param id [Integer] ID number of the migration.
417
+ # @param repo [String] Name of the repository.
418
+ # @see https://docs.github.com/en/rest/reference/migrations#unlock-a-user-repository
419
+ def unlock_user_repository(id, repo, options = {})
420
+ delete "user/migrations/#{id}/repos/#{repo}/lock", options
421
+ end
342
422
  end
343
423
 
344
424
  private
425
+
345
426
  # convenience method for constructing a user specific path, if the user is logged in
346
427
  def user_path(user, path)
347
428
  if user == login && user_authenticated?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'octokit/connection'
2
4
  require 'octokit/warnable'
3
5
  require 'octokit/arguments'
@@ -9,10 +11,18 @@ require 'octokit/rate_limit'
9
11
  require 'octokit/repository'
10
12
  require 'octokit/user'
11
13
  require 'octokit/organization'
12
- require 'octokit/preview'
14
+ require 'octokit/client/actions_secrets'
15
+ require 'octokit/client/actions_workflows'
16
+ require 'octokit/client/actions_workflow_jobs'
17
+ require 'octokit/client/actions_workflow_runs'
18
+ require 'octokit/client/apps'
13
19
  require 'octokit/client/authorizations'
20
+ require 'octokit/client/checks'
14
21
  require 'octokit/client/commits'
15
22
  require 'octokit/client/commit_comments'
23
+ require 'octokit/client/commit_pulls'
24
+ require 'octokit/client/commit_branches'
25
+ require 'octokit/client/community_profile'
16
26
  require 'octokit/client/contents'
17
27
  require 'octokit/client/downloads'
18
28
  require 'octokit/client/deployments'
@@ -28,8 +38,10 @@ require 'octokit/client/legacy_search'
28
38
  require 'octokit/client/licenses'
29
39
  require 'octokit/client/meta'
30
40
  require 'octokit/client/markdown'
41
+ require 'octokit/client/marketplace'
31
42
  require 'octokit/client/milestones'
32
43
  require 'octokit/client/notifications'
44
+ require 'octokit/client/oauth_applications'
33
45
  require 'octokit/client/objects'
34
46
  require 'octokit/client/organizations'
35
47
  require 'octokit/client/pages'
@@ -42,6 +54,7 @@ require 'octokit/client/refs'
42
54
  require 'octokit/client/releases'
43
55
  require 'octokit/client/repositories'
44
56
  require 'octokit/client/repository_invitations'
57
+ require 'octokit/client/reviews'
45
58
  require 'octokit/client/say'
46
59
  require 'octokit/client/search'
47
60
  require 'octokit/client/service_status'
@@ -53,20 +66,22 @@ require 'octokit/client/users'
53
66
  require 'ext/sawyer/relation'
54
67
 
55
68
  module Octokit
56
-
57
69
  # Client for the GitHub API
58
70
  #
59
71
  # @see https://developer.github.com
60
72
  class Client
61
-
62
73
  include Octokit::Authentication
63
74
  include Octokit::Configurable
64
75
  include Octokit::Connection
65
- include Octokit::Preview
66
76
  include Octokit::Warnable
77
+ include Octokit::Client::ActionsSecrets
67
78
  include Octokit::Client::Authorizations
79
+ include Octokit::Client::Checks
68
80
  include Octokit::Client::Commits
69
81
  include Octokit::Client::CommitComments
82
+ include Octokit::Client::CommitPulls
83
+ include Octokit::Client::CommitBranches
84
+ include Octokit::Client::CommunityProfile
70
85
  include Octokit::Client::Contents
71
86
  include Octokit::Client::Deployments
72
87
  include Octokit::Client::Downloads
@@ -76,14 +91,20 @@ module Octokit
76
91
  include Octokit::Client::Gists
77
92
  include Octokit::Client::Gitignore
78
93
  include Octokit::Client::Hooks
94
+ include Octokit::Client::ActionsWorkflows
95
+ include Octokit::Client::ActionsWorkflowJobs
96
+ include Octokit::Client::ActionsWorkflowRuns
97
+ include Octokit::Client::Apps
79
98
  include Octokit::Client::Issues
80
99
  include Octokit::Client::Labels
81
100
  include Octokit::Client::LegacySearch
82
101
  include Octokit::Client::Licenses
83
102
  include Octokit::Client::Meta
84
103
  include Octokit::Client::Markdown
104
+ include Octokit::Client::Marketplace
85
105
  include Octokit::Client::Milestones
86
106
  include Octokit::Client::Notifications
107
+ include Octokit::Client::OauthApplications
87
108
  include Octokit::Client::Objects
88
109
  include Octokit::Client::Organizations
89
110
  include Octokit::Client::Pages
@@ -96,6 +117,7 @@ module Octokit
96
117
  include Octokit::Client::Releases
97
118
  include Octokit::Client::Repositories
98
119
  include Octokit::Client::RepositoryInvitations
120
+ include Octokit::Client::Reviews
99
121
  include Octokit::Client::Say
100
122
  include Octokit::Client::Search
101
123
  include Octokit::Client::ServiceStatus
@@ -106,12 +128,20 @@ module Octokit
106
128
  include Octokit::Client::Users
107
129
 
108
130
  # Header keys that can be passed in options hash to {#get},{#head}
109
- CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
131
+ CONVENIENCE_HEADERS = Set.new(%i[accept content_type])
110
132
 
111
133
  def initialize(options = {})
112
134
  # Use options passed in, but fall back to module defaults
135
+ #
136
+ # rubocop:disable Style/HashEachMethods
137
+ #
138
+ # This may look like a `.keys.each` which should be replaced with `#each_key`, but
139
+ # this doesn't actually work, since `#keys` is just a method we've defined ourselves.
140
+ # The class doesn't fulfill the whole `Enumerable` contract.
113
141
  Octokit::Configurable.keys.each do |key|
114
- instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}"))
142
+ # rubocop:enable Style/HashEachMethods
143
+ value = options[key].nil? ? Octokit.instance_variable_get(:"@#{key}") : options[key]
144
+ instance_variable_set(:"@#{key}", value)
115
145
  end
116
146
 
117
147
  login_from_netrc unless user_authenticated? || application_authenticated?
@@ -124,14 +154,17 @@ module Octokit
124
154
  inspected = super
125
155
 
126
156
  # mask password
127
- inspected = inspected.gsub! @password, "*******" if @password
128
- inspected = inspected.gsub! @management_console_password, "*******" if @management_console_password
157
+ inspected.gsub! @password, '*******' if @password
158
+ if @management_console_password
159
+ inspected.gsub! @management_console_password, '*******'
160
+ end
161
+ inspected.gsub! @bearer_token, '********' if @bearer_token
129
162
  # Only show last 4 of token, secret
130
163
  if @access_token
131
- inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}"
164
+ inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..-1]}"
132
165
  end
133
166
  if @client_secret
134
- inspected = inspected.gsub! @client_secret, "#{'*'*36}#{@client_secret[36..-1]}"
167
+ inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..-1]}"
135
168
  end
136
169
 
137
170
  inspected
@@ -150,11 +183,12 @@ module Octokit
150
183
  # # GET https://foo:bar@api.github.com/
151
184
  # client.get "/"
152
185
  # end
153
- def as_app(key = client_id, secret = client_secret, &block)
186
+ def as_app(key = client_id, secret = client_secret)
154
187
  if key.to_s.empty? || secret.to_s.empty?
155
- raise ApplicationCredentialsRequired, "client_id and client_secret required"
188
+ raise ApplicationCredentialsRequired, 'client_id and client_secret required'
156
189
  end
157
- app_client = self.dup
190
+
191
+ app_client = dup
158
192
  app_client.client_id = app_client.client_secret = nil
159
193
  app_client.login = key
160
194
  app_client.password = secret
@@ -186,6 +220,14 @@ module Octokit
186
220
  @access_token = value
187
221
  end
188
222
 
223
+ # Set Bearer Token for authentication
224
+ #
225
+ # @param value [String] JWT
226
+ def bearer_token=(value)
227
+ reset_agent
228
+ @bearer_token = value
229
+ end
230
+
189
231
  # Set OAuth app client_id
190
232
  #
191
233
  # @param value [String] 20 character GitHub OAuth app client_id
@@ -207,11 +249,14 @@ module Octokit
207
249
  conn_opts[:url] = @api_endpoint
208
250
  conn_opts[:builder] = @middleware.dup if @middleware
209
251
  conn_opts[:proxy] = @proxy if @proxy
252
+ conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode
210
253
  conn = Faraday.new(conn_opts) do |http|
211
254
  if basic_authenticated?
212
- http.basic_auth(@login, @password)
255
+ http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
213
256
  elsif token_authenticated?
214
- http.authorization 'token', @access_token
257
+ http.request :authorization, 'token', @access_token
258
+ elsif bearer_authenticated?
259
+ http.request :authorization, 'Bearer', @bearer_token
215
260
  end
216
261
  http.headers['accept'] = options[:accept] if options.key?(:accept)
217
262
  end
@@ -1,5 +1,6 @@
1
- module Octokit
1
+ # frozen_string_literal: true
2
2
 
3
+ module Octokit
3
4
  # Configuration options for {Client}, defaulting to values
4
5
  # in {Default}
5
6
  module Configurable
@@ -10,6 +11,9 @@ module Octokit
10
11
  # @return [String] Base URL for API requests. default: https://api.github.com/
11
12
  # @!attribute auto_paginate
12
13
  # @return [Boolean] Auto fetch next page of results until rate limit reached
14
+ # @!attribute [w] bearer_token
15
+ # @see https://developer.github.com/early-access/integrations/authentication/#as-an-integration
16
+ # @return [String] JWT bearer token for authentication
13
17
  # @!attribute client_id
14
18
  # @see https://developer.github.com/v3/oauth/
15
19
  # @return [String] Configure OAuth app key
@@ -42,42 +46,46 @@ module Octokit
42
46
  # @!attribute proxy
43
47
  # @see https://github.com/lostisland/faraday
44
48
  # @return [String] URI for proxy server
49
+ # @!attribute ssl_verify_mode
50
+ # @see https://github.com/lostisland/faraday
51
+ # @return [String] SSL verify mode for ssl connections
45
52
  # @!attribute user_agent
46
53
  # @return [String] Configure User-Agent header for requests.
47
54
  # @!attribute web_endpoint
48
55
  # @return [String] Base URL for web URLs. default: https://github.com/
49
56
 
50
- attr_accessor :access_token, :auto_paginate, :client_id,
57
+ attr_accessor :access_token, :auto_paginate, :bearer_token, :client_id,
51
58
  :client_secret, :default_media_type, :connection_options,
52
59
  :middleware, :netrc, :netrc_file,
53
- :per_page, :proxy, :user_agent
60
+ :per_page, :proxy, :ssl_verify_mode, :user_agent
54
61
  attr_writer :password, :web_endpoint, :api_endpoint, :login,
55
62
  :management_console_endpoint, :management_console_password
56
63
 
57
64
  class << self
58
-
59
65
  # List of configurable keys for {Octokit::Client}
60
66
  # @return [Array] of option keys
61
67
  def keys
62
- @keys ||= [
63
- :access_token,
64
- :api_endpoint,
65
- :auto_paginate,
66
- :client_id,
67
- :client_secret,
68
- :connection_options,
69
- :default_media_type,
70
- :login,
71
- :management_console_endpoint,
72
- :management_console_password,
73
- :middleware,
74
- :netrc,
75
- :netrc_file,
76
- :per_page,
77
- :password,
78
- :proxy,
79
- :user_agent,
80
- :web_endpoint
68
+ @keys ||= %i[
69
+ access_token
70
+ api_endpoint
71
+ auto_paginate
72
+ bearer_token
73
+ client_id
74
+ client_secret
75
+ connection_options
76
+ default_media_type
77
+ login
78
+ management_console_endpoint
79
+ management_console_password
80
+ middleware
81
+ netrc
82
+ netrc_file
83
+ per_page
84
+ password
85
+ proxy
86
+ ssl_verify_mode
87
+ user_agent
88
+ web_endpoint
81
89
  ]
82
90
  end
83
91
  end
@@ -89,7 +97,13 @@ module Octokit
89
97
 
90
98
  # Reset configuration options to default values
91
99
  def reset!
100
+ # rubocop:disable Style/HashEachMethods
101
+ #
102
+ # This may look like a `.keys.each` which should be replaced with `#each_key`, but
103
+ # this doesn't actually work, since `#keys` is just a method we've defined ourselves.
104
+ # The class doesn't fulfill the whole `Enumerable` contract.
92
105
  Octokit::Configurable.keys.each do |key|
106
+ # rubocop:enable Style/HashEachMethods
93
107
  instance_variable_set(:"@#{key}", Octokit::Default.options[key])
94
108
  end
95
109
  self
@@ -105,24 +119,22 @@ module Octokit
105
119
  end
106
120
 
107
121
  def api_endpoint
108
- File.join(@api_endpoint, "")
122
+ File.join(@api_endpoint, '')
109
123
  end
110
124
 
111
125
  def management_console_endpoint
112
- File.join(@management_console_endpoint, "")
126
+ File.join(@management_console_endpoint, '')
113
127
  end
114
128
 
115
129
  # Base URL for generated web URLs
116
130
  #
117
131
  # @return [String] Default: https://github.com/
118
132
  def web_endpoint
119
- File.join(@web_endpoint, "")
133
+ File.join(@web_endpoint, '')
120
134
  end
121
135
 
122
136
  def login
123
- @login ||= begin
124
- user.login if token_authenticated?
125
- end
137
+ @login ||= (user.login if token_authenticated?)
126
138
  end
127
139
 
128
140
  def netrc?
@@ -132,7 +144,7 @@ module Octokit
132
144
  private
133
145
 
134
146
  def options
135
- Hash[Octokit::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
147
+ Octokit::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }.to_h
136
148
  end
137
149
 
138
150
  def fetch_client_id_and_secret(overrides = {})