octokit 4.6.2 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +14 -13
- data/LICENSE.md +1 -1
- data/README.md +239 -118
- data/Rakefile +12 -12
- data/lib/ext/sawyer/relation.rb +4 -2
- data/lib/octokit/arguments.rb +2 -2
- data/lib/octokit/authentication.rb +20 -14
- data/lib/octokit/client/actions_artifacts.rb +71 -0
- data/lib/octokit/client/actions_secrets.rb +59 -0
- data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
- data/lib/octokit/client/actions_workflow_runs.rb +125 -0
- data/lib/octokit/client/actions_workflows.rb +68 -0
- data/lib/octokit/client/apps.rb +222 -0
- data/lib/octokit/client/checks.rb +200 -0
- data/lib/octokit/client/commit_branches.rb +20 -0
- data/lib/octokit/client/commit_comments.rb +8 -8
- data/lib/octokit/client/commit_pulls.rb +20 -0
- data/lib/octokit/client/commits.rb +31 -34
- data/lib/octokit/client/community_profile.rb +21 -0
- data/lib/octokit/client/contents.rb +25 -20
- data/lib/octokit/client/deployments.rb +25 -5
- data/lib/octokit/client/downloads.rb +5 -6
- data/lib/octokit/client/emojis.rb +3 -3
- data/lib/octokit/client/environments.rb +55 -0
- data/lib/octokit/client/events.rb +4 -4
- data/lib/octokit/client/feeds.rb +4 -5
- data/lib/octokit/client/gists.rb +7 -6
- data/lib/octokit/client/gitignore.rb +3 -3
- data/lib/octokit/client/hooks.rb +9 -19
- data/lib/octokit/client/issues.rb +60 -14
- data/lib/octokit/client/labels.rb +17 -17
- data/lib/octokit/client/legacy_search.rb +3 -3
- data/lib/octokit/client/licenses.rb +4 -7
- data/lib/octokit/client/markdown.rb +3 -3
- data/lib/octokit/client/marketplace.rb +56 -0
- data/lib/octokit/client/meta.rb +4 -5
- data/lib/octokit/client/milestones.rb +5 -5
- data/lib/octokit/client/notifications.rb +6 -10
- data/lib/octokit/client/oauth_applications.rb +116 -0
- data/lib/octokit/client/objects.rb +14 -14
- data/lib/octokit/client/organizations.rb +238 -61
- data/lib/octokit/client/pages.rb +5 -7
- data/lib/octokit/client/projects.rb +50 -70
- data/lib/octokit/client/pub_sub_hubbub.rb +16 -16
- data/lib/octokit/client/pull_requests.rb +58 -46
- data/lib/octokit/client/rate_limit.rb +11 -13
- data/lib/octokit/client/reactions.rb +6 -11
- data/lib/octokit/client/refs.rb +32 -19
- data/lib/octokit/client/releases.rb +14 -13
- data/lib/octokit/client/repositories.rb +195 -54
- data/lib/octokit/client/repository_invitations.rb +4 -11
- data/lib/octokit/client/reviews.rb +227 -0
- data/lib/octokit/client/say.rb +4 -5
- data/lib/octokit/client/search.rb +46 -17
- data/lib/octokit/client/service_status.rb +19 -9
- data/lib/octokit/client/source_import.rb +8 -13
- data/lib/octokit/client/stats.rb +12 -9
- data/lib/octokit/client/statuses.rb +6 -6
- data/lib/octokit/client/tokens.rb +31 -0
- data/lib/octokit/client/traffic.rb +6 -11
- data/lib/octokit/client/users.rb +106 -25
- data/lib/octokit/client.rb +66 -17
- data/lib/octokit/configurable.rb +42 -30
- data/lib/octokit/connection.rb +43 -21
- data/lib/octokit/default.rb +63 -34
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +14 -15
- data/lib/octokit/enterprise_admin_client/license.rb +4 -5
- data/lib/octokit/enterprise_admin_client/orgs.rb +5 -6
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +8 -9
- data/lib/octokit/enterprise_admin_client/users.rb +17 -16
- data/lib/octokit/enterprise_admin_client.rb +9 -3
- data/lib/octokit/enterprise_management_console_client/management_console.rb +33 -33
- data/lib/octokit/enterprise_management_console_client.rb +9 -3
- data/lib/octokit/error.rb +107 -26
- data/lib/octokit/gist.rb +4 -5
- data/lib/octokit/middleware/follow_redirects.rb +17 -13
- data/lib/octokit/organization.rb +3 -1
- data/lib/octokit/rate_limit.rb +11 -9
- data/lib/octokit/repo_arguments.rb +2 -3
- data/lib/octokit/repository.rb +27 -25
- data/lib/octokit/response/base_middleware.rb +10 -0
- data/lib/octokit/response/feed_parser.rb +5 -9
- data/lib/octokit/response/raise_error.rb +4 -6
- data/lib/octokit/user.rb +4 -2
- data/lib/octokit/version.rb +5 -3
- data/lib/octokit/warnable.rb +4 -5
- data/lib/octokit.rb +15 -8
- data/octokit.gemspec +13 -10
- metadata +55 -22
- data/lib/octokit/client/authorizations.rb +0 -244
- 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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/octokit/client/users.rb
CHANGED
@@ -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
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
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
|
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
|
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
|
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,
|
312
|
+
def add_email(email, _options = {})
|
312
313
|
email = Array(email)
|
313
|
-
post
|
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,
|
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
|
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?
|
data/lib/octokit/client.rb
CHANGED
@@ -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,22 @@ require 'octokit/rate_limit'
|
|
9
11
|
require 'octokit/repository'
|
10
12
|
require 'octokit/user'
|
11
13
|
require 'octokit/organization'
|
12
|
-
require 'octokit/
|
13
|
-
require 'octokit/client/
|
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'
|
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'
|
29
|
+
require 'octokit/client/environments'
|
19
30
|
require 'octokit/client/emojis'
|
20
31
|
require 'octokit/client/events'
|
21
32
|
require 'octokit/client/feeds'
|
@@ -28,8 +39,10 @@ require 'octokit/client/legacy_search'
|
|
28
39
|
require 'octokit/client/licenses'
|
29
40
|
require 'octokit/client/meta'
|
30
41
|
require 'octokit/client/markdown'
|
42
|
+
require 'octokit/client/marketplace'
|
31
43
|
require 'octokit/client/milestones'
|
32
44
|
require 'octokit/client/notifications'
|
45
|
+
require 'octokit/client/oauth_applications'
|
33
46
|
require 'octokit/client/objects'
|
34
47
|
require 'octokit/client/organizations'
|
35
48
|
require 'octokit/client/pages'
|
@@ -42,48 +55,59 @@ require 'octokit/client/refs'
|
|
42
55
|
require 'octokit/client/releases'
|
43
56
|
require 'octokit/client/repositories'
|
44
57
|
require 'octokit/client/repository_invitations'
|
58
|
+
require 'octokit/client/reviews'
|
45
59
|
require 'octokit/client/say'
|
46
60
|
require 'octokit/client/search'
|
47
61
|
require 'octokit/client/service_status'
|
48
62
|
require 'octokit/client/source_import'
|
49
63
|
require 'octokit/client/stats'
|
50
64
|
require 'octokit/client/statuses'
|
65
|
+
require 'octokit/client/tokens'
|
51
66
|
require 'octokit/client/traffic'
|
52
67
|
require 'octokit/client/users'
|
53
68
|
require 'ext/sawyer/relation'
|
54
69
|
|
55
70
|
module Octokit
|
56
|
-
|
57
71
|
# Client for the GitHub API
|
58
72
|
#
|
59
73
|
# @see https://developer.github.com
|
60
74
|
class Client
|
61
|
-
|
62
75
|
include Octokit::Authentication
|
63
76
|
include Octokit::Configurable
|
64
77
|
include Octokit::Connection
|
65
|
-
include Octokit::Preview
|
66
78
|
include Octokit::Warnable
|
67
|
-
include Octokit::Client::
|
79
|
+
include Octokit::Client::ActionsArtifacts
|
80
|
+
include Octokit::Client::ActionsSecrets
|
81
|
+
include Octokit::Client::Checks
|
68
82
|
include Octokit::Client::Commits
|
69
83
|
include Octokit::Client::CommitComments
|
84
|
+
include Octokit::Client::CommitPulls
|
85
|
+
include Octokit::Client::CommitBranches
|
86
|
+
include Octokit::Client::CommunityProfile
|
70
87
|
include Octokit::Client::Contents
|
71
88
|
include Octokit::Client::Deployments
|
72
89
|
include Octokit::Client::Downloads
|
90
|
+
include Octokit::Client::Environments
|
73
91
|
include Octokit::Client::Emojis
|
74
92
|
include Octokit::Client::Events
|
75
93
|
include Octokit::Client::Feeds
|
76
94
|
include Octokit::Client::Gists
|
77
95
|
include Octokit::Client::Gitignore
|
78
96
|
include Octokit::Client::Hooks
|
97
|
+
include Octokit::Client::ActionsWorkflows
|
98
|
+
include Octokit::Client::ActionsWorkflowJobs
|
99
|
+
include Octokit::Client::ActionsWorkflowRuns
|
100
|
+
include Octokit::Client::Apps
|
79
101
|
include Octokit::Client::Issues
|
80
102
|
include Octokit::Client::Labels
|
81
103
|
include Octokit::Client::LegacySearch
|
82
104
|
include Octokit::Client::Licenses
|
83
105
|
include Octokit::Client::Meta
|
84
106
|
include Octokit::Client::Markdown
|
107
|
+
include Octokit::Client::Marketplace
|
85
108
|
include Octokit::Client::Milestones
|
86
109
|
include Octokit::Client::Notifications
|
110
|
+
include Octokit::Client::OauthApplications
|
87
111
|
include Octokit::Client::Objects
|
88
112
|
include Octokit::Client::Organizations
|
89
113
|
include Octokit::Client::Pages
|
@@ -96,22 +120,32 @@ module Octokit
|
|
96
120
|
include Octokit::Client::Releases
|
97
121
|
include Octokit::Client::Repositories
|
98
122
|
include Octokit::Client::RepositoryInvitations
|
123
|
+
include Octokit::Client::Reviews
|
99
124
|
include Octokit::Client::Say
|
100
125
|
include Octokit::Client::Search
|
101
126
|
include Octokit::Client::ServiceStatus
|
102
127
|
include Octokit::Client::SourceImport
|
103
128
|
include Octokit::Client::Stats
|
104
129
|
include Octokit::Client::Statuses
|
130
|
+
include Octokit::Client::Tokens
|
105
131
|
include Octokit::Client::Traffic
|
106
132
|
include Octokit::Client::Users
|
107
133
|
|
108
134
|
# Header keys that can be passed in options hash to {#get},{#head}
|
109
|
-
CONVENIENCE_HEADERS = Set.new([
|
135
|
+
CONVENIENCE_HEADERS = Set.new(%i[accept content_type])
|
110
136
|
|
111
137
|
def initialize(options = {})
|
112
138
|
# Use options passed in, but fall back to module defaults
|
139
|
+
#
|
140
|
+
# rubocop:disable Style/HashEachMethods
|
141
|
+
#
|
142
|
+
# This may look like a `.keys.each` which should be replaced with `#each_key`, but
|
143
|
+
# this doesn't actually work, since `#keys` is just a method we've defined ourselves.
|
144
|
+
# The class doesn't fulfill the whole `Enumerable` contract.
|
113
145
|
Octokit::Configurable.keys.each do |key|
|
114
|
-
|
146
|
+
# rubocop:enable Style/HashEachMethods
|
147
|
+
value = options[key].nil? ? Octokit.instance_variable_get(:"@#{key}") : options[key]
|
148
|
+
instance_variable_set(:"@#{key}", value)
|
115
149
|
end
|
116
150
|
|
117
151
|
login_from_netrc unless user_authenticated? || application_authenticated?
|
@@ -124,14 +158,17 @@ module Octokit
|
|
124
158
|
inspected = super
|
125
159
|
|
126
160
|
# mask password
|
127
|
-
inspected
|
128
|
-
|
161
|
+
inspected.gsub! @password, '*******' if @password
|
162
|
+
if @management_console_password
|
163
|
+
inspected.gsub! @management_console_password, '*******'
|
164
|
+
end
|
165
|
+
inspected.gsub! @bearer_token, '********' if @bearer_token
|
129
166
|
# Only show last 4 of token, secret
|
130
167
|
if @access_token
|
131
|
-
inspected
|
168
|
+
inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..]}"
|
132
169
|
end
|
133
170
|
if @client_secret
|
134
|
-
inspected
|
171
|
+
inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..]}"
|
135
172
|
end
|
136
173
|
|
137
174
|
inspected
|
@@ -150,11 +187,12 @@ module Octokit
|
|
150
187
|
# # GET https://foo:bar@api.github.com/
|
151
188
|
# client.get "/"
|
152
189
|
# end
|
153
|
-
def as_app(key = client_id, secret = client_secret
|
190
|
+
def as_app(key = client_id, secret = client_secret)
|
154
191
|
if key.to_s.empty? || secret.to_s.empty?
|
155
|
-
raise ApplicationCredentialsRequired,
|
192
|
+
raise ApplicationCredentialsRequired, 'client_id and client_secret required'
|
156
193
|
end
|
157
|
-
|
194
|
+
|
195
|
+
app_client = dup
|
158
196
|
app_client.client_id = app_client.client_secret = nil
|
159
197
|
app_client.login = key
|
160
198
|
app_client.password = secret
|
@@ -186,6 +224,14 @@ module Octokit
|
|
186
224
|
@access_token = value
|
187
225
|
end
|
188
226
|
|
227
|
+
# Set Bearer Token for authentication
|
228
|
+
#
|
229
|
+
# @param value [String] JWT
|
230
|
+
def bearer_token=(value)
|
231
|
+
reset_agent
|
232
|
+
@bearer_token = value
|
233
|
+
end
|
234
|
+
|
189
235
|
# Set OAuth app client_id
|
190
236
|
#
|
191
237
|
# @param value [String] 20 character GitHub OAuth app client_id
|
@@ -207,11 +253,14 @@ module Octokit
|
|
207
253
|
conn_opts[:url] = @api_endpoint
|
208
254
|
conn_opts[:builder] = @middleware.dup if @middleware
|
209
255
|
conn_opts[:proxy] = @proxy if @proxy
|
256
|
+
conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode
|
210
257
|
conn = Faraday.new(conn_opts) do |http|
|
211
258
|
if basic_authenticated?
|
212
|
-
http.
|
259
|
+
http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
|
213
260
|
elsif token_authenticated?
|
214
|
-
http.authorization 'token', @access_token
|
261
|
+
http.request :authorization, 'token', @access_token
|
262
|
+
elsif bearer_authenticated?
|
263
|
+
http.request :authorization, 'Bearer', @bearer_token
|
215
264
|
end
|
216
265
|
http.headers['accept'] = options[:accept] if options.key?(:accept)
|
217
266
|
end
|
data/lib/octokit/configurable.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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 ||=
|
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
|
-
|
147
|
+
Octokit::Configurable.keys.to_h { |key| [key, instance_variable_get(:"@#{key}")] }
|
136
148
|
end
|
137
149
|
|
138
150
|
def fetch_client_id_and_secret(overrides = {})
|