octokit 4.2.0 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +14 -13
  3. data/LICENSE.md +1 -1
  4. data/README.md +275 -127
  5. data/Rakefile +20 -14
  6. data/lib/ext/sawyer/relation.rb +12 -0
  7. data/lib/octokit/arguments.rb +3 -3
  8. data/lib/octokit/authentication.rb +20 -14
  9. data/lib/octokit/client/actions_artifacts.rb +71 -0
  10. data/lib/octokit/client/actions_secrets.rb +161 -0
  11. data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
  12. data/lib/octokit/client/actions_workflow_runs.rb +125 -0
  13. data/lib/octokit/client/actions_workflows.rb +68 -0
  14. data/lib/octokit/client/apps.rb +259 -0
  15. data/lib/octokit/client/checks.rb +200 -0
  16. data/lib/octokit/client/code_scanning.rb +190 -0
  17. data/lib/octokit/client/codespaces_secrets.rb +108 -0
  18. data/lib/octokit/client/commit_branches.rb +20 -0
  19. data/lib/octokit/client/commit_comments.rb +8 -8
  20. data/lib/octokit/client/commit_pulls.rb +20 -0
  21. data/lib/octokit/client/commits.rb +32 -35
  22. data/lib/octokit/client/community_profile.rb +21 -0
  23. data/lib/octokit/client/contents.rb +24 -21
  24. data/lib/octokit/client/dependabot_secrets.rb +108 -0
  25. data/lib/octokit/client/deployments.rb +29 -7
  26. data/lib/octokit/client/downloads.rb +5 -6
  27. data/lib/octokit/client/emojis.rb +3 -3
  28. data/lib/octokit/client/environments.rb +58 -0
  29. data/lib/octokit/client/events.rb +4 -4
  30. data/lib/octokit/client/feeds.rb +4 -5
  31. data/lib/octokit/client/gists.rb +36 -8
  32. data/lib/octokit/client/gitignore.rb +3 -3
  33. data/lib/octokit/client/hooks.rb +34 -30
  34. data/lib/octokit/client/issues.rb +97 -14
  35. data/lib/octokit/client/labels.rb +17 -17
  36. data/lib/octokit/client/legacy_search.rb +3 -3
  37. data/lib/octokit/client/licenses.rb +5 -8
  38. data/lib/octokit/client/markdown.rb +3 -3
  39. data/lib/octokit/client/marketplace.rb +56 -0
  40. data/lib/octokit/client/meta.rb +4 -5
  41. data/lib/octokit/client/milestones.rb +14 -14
  42. data/lib/octokit/client/notifications.rb +7 -11
  43. data/lib/octokit/client/oauth_applications.rb +116 -0
  44. data/lib/octokit/client/objects.rb +14 -14
  45. data/lib/octokit/client/organizations.rb +256 -73
  46. data/lib/octokit/client/pages.rb +26 -3
  47. data/lib/octokit/client/projects.rb +294 -0
  48. data/lib/octokit/client/pull_requests.rb +74 -51
  49. data/lib/octokit/client/rate_limit.rb +11 -13
  50. data/lib/octokit/client/reactions.rb +204 -0
  51. data/lib/octokit/client/refs.rb +34 -20
  52. data/lib/octokit/client/releases.rb +16 -13
  53. data/lib/octokit/client/repositories.rb +276 -60
  54. data/lib/octokit/client/repository_invitations.rb +96 -0
  55. data/lib/octokit/client/reviews.rb +227 -0
  56. data/lib/octokit/client/say.rb +4 -5
  57. data/lib/octokit/client/search.rb +46 -17
  58. data/lib/octokit/client/service_status.rb +19 -9
  59. data/lib/octokit/client/source_import.rb +156 -0
  60. data/lib/octokit/client/stats.rb +39 -17
  61. data/lib/octokit/client/statuses.rb +6 -6
  62. data/lib/octokit/client/tokens.rb +31 -0
  63. data/lib/octokit/client/traffic.rb +64 -0
  64. data/lib/octokit/client/users.rb +133 -25
  65. data/lib/octokit/client.rb +85 -19
  66. data/lib/octokit/configurable.rb +60 -32
  67. data/lib/octokit/connection.rb +45 -21
  68. data/lib/octokit/default.rb +82 -35
  69. data/lib/octokit/enterprise_admin_client/admin_stats.rb +14 -15
  70. data/lib/octokit/enterprise_admin_client/license.rb +4 -5
  71. data/lib/octokit/enterprise_admin_client/orgs.rb +7 -6
  72. data/lib/octokit/enterprise_admin_client/search_indexing.rb +8 -9
  73. data/lib/octokit/enterprise_admin_client/users.rb +19 -18
  74. data/lib/octokit/enterprise_admin_client.rb +11 -3
  75. data/lib/octokit/enterprise_management_console_client/management_console.rb +52 -34
  76. data/lib/octokit/enterprise_management_console_client.rb +9 -3
  77. data/lib/octokit/error.rb +144 -26
  78. data/lib/octokit/gist.rb +4 -5
  79. data/lib/octokit/manage_ghes_client/manage_ghes.rb +178 -0
  80. data/lib/octokit/manage_ghes_client.rb +64 -0
  81. data/lib/octokit/middleware/follow_redirects.rb +18 -14
  82. data/lib/octokit/organization.rb +3 -1
  83. data/lib/octokit/rate_limit.rb +11 -9
  84. data/lib/octokit/repo_arguments.rb +3 -4
  85. data/lib/octokit/repository.rb +35 -23
  86. data/lib/octokit/response/base_middleware.rb +10 -0
  87. data/lib/octokit/response/feed_parser.rb +5 -9
  88. data/lib/octokit/response/raise_error.rb +4 -6
  89. data/lib/octokit/user.rb +4 -2
  90. data/lib/octokit/version.rb +3 -1
  91. data/lib/octokit/warnable.rb +4 -5
  92. data/lib/octokit.rb +30 -8
  93. data/octokit.gemspec +12 -10
  94. metadata +47 -24
  95. data/lib/octokit/client/authorizations.rb +0 -256
  96. data/lib/octokit/client/pub_sub_hubbub.rb +0 -111
  97. data/lib/octokit/preview.rb +0 -28
@@ -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,43 @@ 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
+
57
+ post "#{web_endpoint}login/oauth/access_token", options
58
+ end
59
+
60
+ # Refresh a user's access token with a refresh token.
61
+ #
62
+ # Applications can refresh an access token without requiring a user to re-authorize using refresh access token.
63
+ #
64
+ # @param code [String] 40 character GitHub OAuth refresh access token
65
+ #
66
+ # @return [Sawyer::Resource]
67
+ # @see https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens#refreshing-a-user-access-token-with-a-refresh-token
68
+ #
69
+ # @example
70
+ # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
71
+ # client.refresh_access_token('40-character-refresh-token')
72
+ def refresh_access_token(code, app_id = client_id, app_secret = client_secret, options = {})
73
+ options = options.merge({
74
+ refresh_token: code,
75
+ client_id: app_id,
76
+ client_secret: app_secret,
77
+ grant_type: 'refresh_token',
78
+ headers: {
79
+ content_type: 'application/json',
80
+ accept: 'application/json'
81
+ }
82
+ })
83
+
56
84
  post "#{web_endpoint}login/oauth/access_token", options
57
85
  end
58
86
 
@@ -83,7 +111,7 @@ module Octokit
83
111
  # @example
84
112
  # Octokit.update_user(:name => "Erik Michaels-Ober", :email => "sferik@gmail.com", :company => "Code for America", :location => "San Francisco", :hireable => false)
85
113
  def update_user(options)
86
- patch "user", options
114
+ patch 'user', options
87
115
  end
88
116
 
89
117
  # Get a user's followers.
@@ -95,7 +123,7 @@ module Octokit
95
123
  # @see https://developer.github.com/v3/users/followers/#list-followers-of-a-user
96
124
  # @example
97
125
  # Octokit.followers('pengwynn')
98
- def followers(user=login, options = {})
126
+ def followers(user = login, options = {})
99
127
  paginate "#{User.path user}/followers", options
100
128
  end
101
129
 
@@ -108,7 +136,7 @@ module Octokit
108
136
  # @see https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
109
137
  # @example
110
138
  # Octokit.following('pengwynn')
111
- def following(user=login, options = {})
139
+ def following(user = login, options = {})
112
140
  paginate "#{User.path user}/following", options
113
141
  end
114
142
 
@@ -173,7 +201,7 @@ module Octokit
173
201
  # @see https://developer.github.com/v3/activity/starring/#list-repositories-being-starred
174
202
  # @example
175
203
  # Octokit.starred('pengwynn')
176
- def starred(user=login, options = {})
204
+ def starred(user = login, options = {})
177
205
  paginate user_path(user, 'starred'), options
178
206
  end
179
207
 
@@ -226,7 +254,7 @@ module Octokit
226
254
  # @example
227
255
  # @client.keys
228
256
  def keys(options = {})
229
- paginate "user/keys", options
257
+ paginate 'user/keys', options
230
258
  end
231
259
 
232
260
  # Get list of public keys for user.
@@ -252,7 +280,7 @@ module Octokit
252
280
  # @example
253
281
  # @client.add_key('Personal projects key', 'ssh-rsa AAA...')
254
282
  def add_key(title, key, options = {})
255
- post "user/keys", options.merge({:title => title, :key => key})
283
+ post 'user/keys', options.merge({ title: title, key: key })
256
284
  end
257
285
 
258
286
  # Update a public key
@@ -296,7 +324,7 @@ module Octokit
296
324
  # @example
297
325
  # @client.emails
298
326
  def emails(options = {})
299
- paginate "user/emails", options
327
+ paginate 'user/emails', options
300
328
  end
301
329
 
302
330
  # Add email address to user.
@@ -308,9 +336,9 @@ module Octokit
308
336
  # @see https://developer.github.com/v3/users/emails/#add-email-addresses
309
337
  # @example
310
338
  # @client.add_email('new_email@user.com')
311
- def add_email(email, options = {})
339
+ def add_email(email, _options = {})
312
340
  email = Array(email)
313
- post "user/emails", email
341
+ post 'user/emails', email
314
342
  end
315
343
 
316
344
  # Remove email from user.
@@ -324,7 +352,7 @@ module Octokit
324
352
  # @client.remove_email('old_email@user.com')
325
353
  def remove_email(email)
326
354
  email = Array(email)
327
- boolean_from_response :delete, "user/emails", email
355
+ boolean_from_response :delete, 'user/emails', email
328
356
  end
329
357
 
330
358
  # List repositories being watched by a user.
@@ -334,14 +362,94 @@ module Octokit
334
362
  # @see https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
335
363
  # @example
336
364
  # @client.subscriptions("pengwynn")
337
- def subscriptions(user=login, options = {})
365
+ def subscriptions(user = login, options = {})
338
366
  paginate user_path(user, 'subscriptions'), options
339
367
  end
340
- alias :watched :subscriptions
368
+ alias watched subscriptions
369
+
370
+ # Initiates the generation of a migration archive.
371
+ #
372
+ # Requires authenticated user.
373
+ #
374
+ # @param repositories [Array<String>] :repositories Repositories for the organization.
375
+ # @option options [Boolean, optional] :lock_repositories Indicates whether repositories should be locked during migration
376
+ # @option options [Boolean, optional] :exclude_attachments Exclude attachments fro the migration data
377
+ # @return [Sawyer::Resource] Hash representing the new migration.
378
+ # @example
379
+ # @client.start_migration(['octocat/hello-world'])
380
+ # @see https://docs.github.com/en/rest/reference/migrations#start-a-user-migration
381
+ def start_user_migration(repositories, options = {})
382
+ options[:repositories] = repositories
383
+ post 'user/migrations', options
384
+ end
385
+
386
+ # Lists the most recent migrations.
387
+ #
388
+ # Requires authenticated user.
389
+ #
390
+ # @return [Array<Sawyer::Resource>] Array of migration resources.
391
+ # @see https://docs.github.com/en/rest/reference/migrations#list-user-migrations
392
+ def user_migrations(options = {})
393
+ paginate 'user/migrations', options
394
+ end
395
+
396
+ # Fetches the status of a migration.
397
+ #
398
+ # Requires authenticated user.
399
+ #
400
+ # @param id [Integer] ID number of the migration.
401
+ # @see https://docs.github.com/en/rest/reference/migrations#get-a-user-migration-status
402
+ def user_migration_status(id, options = {})
403
+ get "user/migrations/#{id}", options
404
+ end
405
+
406
+ # Fetches the URL to a migration archive.
407
+ #
408
+ # Requires authenticated user.
409
+ #
410
+ # @param id [Integer] ID number of the migration.
411
+ # @see https://docs.github.com/en/rest/reference/migrations#download-a-user-migration-archive
412
+ def user_migration_archive_url(id, options = {})
413
+ url = "user/migrations/#{id}/archive"
414
+
415
+ response = client_without_redirects(options).get(url)
416
+ response.headers['location']
417
+ end
418
+
419
+ # Deletes a previous migration archive.
420
+ #
421
+ # Requires authenticated user.
422
+ #
423
+ # @param id [Integer] ID number of the migration.
424
+ # @see https://docs.github.com/en/rest/reference/migrations#delete-a-user-migration-archive
425
+ def delete_user_migration_archive(id, options = {})
426
+ delete "user/migrations/#{id}/archive", options
427
+ end
341
428
 
429
+ # List repositories for a user migration.
430
+ #
431
+ # Requires authenticated user.
432
+ #
433
+ # @param id [Integer] ID number of the migration.
434
+ # @see https://docs.github.com/en/rest/reference/migrations#list-repositories-for-a-user-migration
435
+ def user_migration_repositories(id, options = {})
436
+ get "user/migrations/#{id}/repositories", options
437
+ end
438
+
439
+ # Unlock a user repository which has been locked by a migration.
440
+ #
441
+ # Requires authenticated user.
442
+ #
443
+ # @param id [Integer] ID number of the migration.
444
+ # @param repo [String] Name of the repository.
445
+ # @see https://docs.github.com/en/rest/reference/migrations#unlock-a-user-repository
446
+ def unlock_user_repository(id, repo, options = {})
447
+ delete "user/migrations/#{id}/repos/#{repo}/lock", options
448
+ end
342
449
  end
343
450
 
344
451
  private
452
+
345
453
  # convenience method for constructing a user specific path, if the user is logged in
346
454
  def user_path(user, path)
347
455
  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,13 +11,25 @@ require 'octokit/rate_limit'
9
11
  require 'octokit/repository'
10
12
  require 'octokit/user'
11
13
  require 'octokit/organization'
12
- require 'octokit/preview'
13
- require 'octokit/client/authorizations'
14
+ require 'octokit/client/actions_artifacts'
15
+ require 'octokit/client/actions_secrets'
16
+ require 'octokit/client/actions_workflows'
17
+ require 'octokit/client/actions_workflow_jobs'
18
+ require 'octokit/client/actions_workflow_runs'
19
+ require 'octokit/client/apps'
20
+ require 'octokit/client/checks'
21
+ require 'octokit/client/code_scanning'
22
+ require 'octokit/client/codespaces_secrets'
14
23
  require 'octokit/client/commits'
15
24
  require 'octokit/client/commit_comments'
25
+ require 'octokit/client/commit_pulls'
26
+ require 'octokit/client/commit_branches'
27
+ require 'octokit/client/community_profile'
16
28
  require 'octokit/client/contents'
17
29
  require 'octokit/client/downloads'
30
+ require 'octokit/client/dependabot_secrets'
18
31
  require 'octokit/client/deployments'
32
+ require 'octokit/client/environments'
19
33
  require 'octokit/client/emojis'
20
34
  require 'octokit/client/events'
21
35
  require 'octokit/client/feeds'
@@ -28,79 +42,114 @@ require 'octokit/client/legacy_search'
28
42
  require 'octokit/client/licenses'
29
43
  require 'octokit/client/meta'
30
44
  require 'octokit/client/markdown'
45
+ require 'octokit/client/marketplace'
31
46
  require 'octokit/client/milestones'
32
47
  require 'octokit/client/notifications'
48
+ require 'octokit/client/oauth_applications'
33
49
  require 'octokit/client/objects'
34
50
  require 'octokit/client/organizations'
35
51
  require 'octokit/client/pages'
36
- require 'octokit/client/pub_sub_hubbub'
52
+ require 'octokit/client/projects'
37
53
  require 'octokit/client/pull_requests'
38
54
  require 'octokit/client/rate_limit'
55
+ require 'octokit/client/reactions'
39
56
  require 'octokit/client/refs'
40
57
  require 'octokit/client/releases'
41
58
  require 'octokit/client/repositories'
59
+ require 'octokit/client/repository_invitations'
60
+ require 'octokit/client/reviews'
42
61
  require 'octokit/client/say'
43
62
  require 'octokit/client/search'
44
63
  require 'octokit/client/service_status'
64
+ require 'octokit/client/source_import'
45
65
  require 'octokit/client/stats'
46
66
  require 'octokit/client/statuses'
67
+ require 'octokit/client/tokens'
68
+ require 'octokit/client/traffic'
47
69
  require 'octokit/client/users'
70
+ require 'ext/sawyer/relation'
48
71
 
49
72
  module Octokit
50
-
51
73
  # Client for the GitHub API
52
74
  #
53
75
  # @see https://developer.github.com
54
76
  class Client
55
-
56
77
  include Octokit::Authentication
57
78
  include Octokit::Configurable
58
79
  include Octokit::Connection
59
- include Octokit::Preview
60
80
  include Octokit::Warnable
61
- include Octokit::Client::Authorizations
81
+ include Octokit::Client::ActionsArtifacts
82
+ include Octokit::Client::ActionsSecrets
83
+ include Octokit::Client::Checks
84
+ include Octokit::Client::CodeScanning
85
+ include Octokit::Client::CodespacesSecrets
62
86
  include Octokit::Client::Commits
63
87
  include Octokit::Client::CommitComments
88
+ include Octokit::Client::CommitPulls
89
+ include Octokit::Client::CommitBranches
90
+ include Octokit::Client::CommunityProfile
64
91
  include Octokit::Client::Contents
92
+ include Octokit::Client::DependabotSecrets
65
93
  include Octokit::Client::Deployments
66
94
  include Octokit::Client::Downloads
95
+ include Octokit::Client::Environments
67
96
  include Octokit::Client::Emojis
68
97
  include Octokit::Client::Events
69
98
  include Octokit::Client::Feeds
70
99
  include Octokit::Client::Gists
71
100
  include Octokit::Client::Gitignore
72
101
  include Octokit::Client::Hooks
102
+ include Octokit::Client::ActionsWorkflows
103
+ include Octokit::Client::ActionsWorkflowJobs
104
+ include Octokit::Client::ActionsWorkflowRuns
105
+ include Octokit::Client::Apps
73
106
  include Octokit::Client::Issues
74
107
  include Octokit::Client::Labels
75
108
  include Octokit::Client::LegacySearch
76
109
  include Octokit::Client::Licenses
77
110
  include Octokit::Client::Meta
78
111
  include Octokit::Client::Markdown
112
+ include Octokit::Client::Marketplace
79
113
  include Octokit::Client::Milestones
80
114
  include Octokit::Client::Notifications
115
+ include Octokit::Client::OauthApplications
81
116
  include Octokit::Client::Objects
82
117
  include Octokit::Client::Organizations
83
118
  include Octokit::Client::Pages
84
- include Octokit::Client::PubSubHubbub
119
+ include Octokit::Client::Projects
85
120
  include Octokit::Client::PullRequests
86
121
  include Octokit::Client::RateLimit
122
+ include Octokit::Client::Reactions
87
123
  include Octokit::Client::Refs
88
124
  include Octokit::Client::Releases
89
125
  include Octokit::Client::Repositories
126
+ include Octokit::Client::RepositoryInvitations
127
+ include Octokit::Client::Reviews
90
128
  include Octokit::Client::Say
91
129
  include Octokit::Client::Search
92
130
  include Octokit::Client::ServiceStatus
131
+ include Octokit::Client::SourceImport
93
132
  include Octokit::Client::Stats
94
133
  include Octokit::Client::Statuses
134
+ include Octokit::Client::Tokens
135
+ include Octokit::Client::Traffic
95
136
  include Octokit::Client::Users
96
137
 
97
138
  # Header keys that can be passed in options hash to {#get},{#head}
98
- CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
139
+ CONVENIENCE_HEADERS = Set.new(%i[accept content_type])
99
140
 
100
141
  def initialize(options = {})
101
142
  # Use options passed in, but fall back to module defaults
143
+ #
144
+ # rubocop:disable Style/HashEachMethods
145
+ #
146
+ # This may look like a `.keys.each` which should be replaced with `#each_key`, but
147
+ # this doesn't actually work, since `#keys` is just a method we've defined ourselves.
148
+ # The class doesn't fulfill the whole `Enumerable` contract.
102
149
  Octokit::Configurable.keys.each do |key|
103
- instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}"))
150
+ # rubocop:enable Style/HashEachMethods
151
+ value = options[key].nil? ? Octokit.instance_variable_get(:"@#{key}") : options[key]
152
+ instance_variable_set(:"@#{key}", value)
104
153
  end
105
154
 
106
155
  login_from_netrc unless user_authenticated? || application_authenticated?
@@ -113,14 +162,17 @@ module Octokit
113
162
  inspected = super
114
163
 
115
164
  # mask password
116
- inspected = inspected.gsub! @password, "*******" if @password
117
- inspected = inspected.gsub! @management_console_password, "*******" if @management_console_password
165
+ inspected.gsub! @password, '*******' if @password
166
+ if @management_console_password
167
+ inspected.gsub! @management_console_password, '*******'
168
+ end
169
+ inspected.gsub! @bearer_token, '********' if @bearer_token
118
170
  # Only show last 4 of token, secret
119
171
  if @access_token
120
- inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}"
172
+ inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..]}"
121
173
  end
122
174
  if @client_secret
123
- inspected = inspected.gsub! @client_secret, "#{'*'*36}#{@client_secret[36..-1]}"
175
+ inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..]}"
124
176
  end
125
177
 
126
178
  inspected
@@ -139,11 +191,12 @@ module Octokit
139
191
  # # GET https://foo:bar@api.github.com/
140
192
  # client.get "/"
141
193
  # end
142
- def as_app(key = client_id, secret = client_secret, &block)
194
+ def as_app(key = client_id, secret = client_secret)
143
195
  if key.to_s.empty? || secret.to_s.empty?
144
- raise ApplicationCredentialsRequired, "client_id and client_secret required"
196
+ raise ApplicationCredentialsRequired, 'client_id and client_secret required'
145
197
  end
146
- app_client = self.dup
198
+
199
+ app_client = dup
147
200
  app_client.client_id = app_client.client_secret = nil
148
201
  app_client.login = key
149
202
  app_client.password = secret
@@ -175,6 +228,14 @@ module Octokit
175
228
  @access_token = value
176
229
  end
177
230
 
231
+ # Set Bearer Token for authentication
232
+ #
233
+ # @param value [String] JWT
234
+ def bearer_token=(value)
235
+ reset_agent
236
+ @bearer_token = value
237
+ end
238
+
178
239
  # Set OAuth app client_id
179
240
  #
180
241
  # @param value [String] 20 character GitHub OAuth app client_id
@@ -196,12 +257,17 @@ module Octokit
196
257
  conn_opts[:url] = @api_endpoint
197
258
  conn_opts[:builder] = @middleware.dup if @middleware
198
259
  conn_opts[:proxy] = @proxy if @proxy
260
+ conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode
199
261
  conn = Faraday.new(conn_opts) do |http|
262
+ http_cache_middleware = http.builder.handlers.delete(Faraday::HttpCache) if Faraday.const_defined?(:HttpCache)
200
263
  if basic_authenticated?
201
- http.basic_auth(@login, @password)
264
+ http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
202
265
  elsif token_authenticated?
203
- http.authorization 'token', @access_token
266
+ http.request :authorization, 'token', @access_token
267
+ elsif bearer_authenticated?
268
+ http.request :authorization, 'Bearer', @bearer_token
204
269
  end
270
+ http.builder.handlers.push(http_cache_middleware) unless http_cache_middleware.nil?
205
271
  http.headers['accept'] = options[:accept] if options.key?(:accept)
206
272
  end
207
273
  conn.builder.delete(Octokit::Middleware::FollowRedirects)
@@ -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
@@ -28,6 +32,12 @@ module Octokit
28
32
  # @return [String] An admin password set up for your GitHub Enterprise management console
29
33
  # @!attribute management_console_endpoint
30
34
  # @return [String] Base URL for API requests to the GitHub Enterprise management console
35
+ # @!attribute manage_ghes_endpoint
36
+ # @return [String] Base URL for API requests to the GitHub Enterprise Server Manage API
37
+ # @!attribute manage_ghes_username
38
+ # @return [String] API username for requests to the GitHub Enterprise Server Manage API
39
+ # @!attribute manage_ghes_password
40
+ # @return [String] API user password for requests to the GitHub Enterprise Server Manage API
31
41
  # @!attribute middleware
32
42
  # @see https://github.com/lostisland/faraday
33
43
  # @return [Faraday::Builder or Faraday::RackBuilder] Configure middleware for Faraday
@@ -42,42 +52,52 @@ module Octokit
42
52
  # @!attribute proxy
43
53
  # @see https://github.com/lostisland/faraday
44
54
  # @return [String] URI for proxy server
55
+ # @!attribute ssl_verify_mode
56
+ # @see https://github.com/lostisland/faraday
57
+ # @return [String] SSL verify mode for ssl connections
45
58
  # @!attribute user_agent
46
59
  # @return [String] Configure User-Agent header for requests.
47
60
  # @!attribute web_endpoint
48
61
  # @return [String] Base URL for web URLs. default: https://github.com/
49
62
 
50
- attr_accessor :access_token, :auto_paginate, :client_id,
63
+ attr_accessor :access_token, :auto_paginate, :bearer_token, :client_id,
51
64
  :client_secret, :default_media_type, :connection_options,
52
- :management_console_endpoint, :management_console_password,
53
65
  :middleware, :netrc, :netrc_file,
54
- :per_page, :proxy, :user_agent
55
- attr_writer :password, :web_endpoint, :api_endpoint, :login
66
+ :per_page, :proxy, :ssl_verify_mode, :user_agent
67
+ attr_writer :password, :web_endpoint, :api_endpoint, :login,
68
+ :management_console_endpoint, :management_console_password,
69
+ :manage_ghes_endpoint,
70
+ :manage_ghes_username,
71
+ :manage_ghes_password
56
72
 
57
73
  class << self
58
-
59
74
  # List of configurable keys for {Octokit::Client}
60
75
  # @return [Array] of option keys
61
76
  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
77
+ @keys ||= %i[
78
+ access_token
79
+ api_endpoint
80
+ auto_paginate
81
+ bearer_token
82
+ client_id
83
+ client_secret
84
+ connection_options
85
+ default_media_type
86
+ login
87
+ management_console_endpoint
88
+ management_console_password
89
+ manage_ghes_endpoint
90
+ manage_ghes_username
91
+ manage_ghes_password
92
+ middleware
93
+ netrc
94
+ netrc_file
95
+ per_page
96
+ password
97
+ proxy
98
+ ssl_verify_mode
99
+ user_agent
100
+ web_endpoint
81
101
  ]
82
102
  end
83
103
  end
@@ -89,7 +109,13 @@ module Octokit
89
109
 
90
110
  # Reset configuration options to default values
91
111
  def reset!
112
+ # rubocop:disable Style/HashEachMethods
113
+ #
114
+ # This may look like a `.keys.each` which should be replaced with `#each_key`, but
115
+ # this doesn't actually work, since `#keys` is just a method we've defined ourselves.
116
+ # The class doesn't fulfill the whole `Enumerable` contract.
92
117
  Octokit::Configurable.keys.each do |key|
118
+ # rubocop:enable Style/HashEachMethods
93
119
  instance_variable_set(:"@#{key}", Octokit::Default.options[key])
94
120
  end
95
121
  self
@@ -105,24 +131,26 @@ module Octokit
105
131
  end
106
132
 
107
133
  def api_endpoint
108
- File.join(@api_endpoint, "")
134
+ File.join(@api_endpoint, '')
109
135
  end
110
136
 
111
137
  def management_console_endpoint
112
- File.join(@management_console_endpoint, "")
138
+ File.join(@management_console_endpoint, '')
139
+ end
140
+
141
+ def manage_ghes_endpoint
142
+ File.join(@manage_ghes_endpoint, '')
113
143
  end
114
144
 
115
145
  # Base URL for generated web URLs
116
146
  #
117
147
  # @return [String] Default: https://github.com/
118
148
  def web_endpoint
119
- File.join(@web_endpoint, "")
149
+ File.join(@web_endpoint, '')
120
150
  end
121
151
 
122
152
  def login
123
- @login ||= begin
124
- user.login if token_authenticated?
125
- end
153
+ @login ||= (user.login if token_authenticated?)
126
154
  end
127
155
 
128
156
  def netrc?
@@ -132,7 +160,7 @@ module Octokit
132
160
  private
133
161
 
134
162
  def options
135
- Hash[Octokit::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
163
+ Octokit::Configurable.keys.to_h { |key| [key, instance_variable_get(:"@#{key}")] }
136
164
  end
137
165
 
138
166
  def fetch_client_id_and_secret(overrides = {})