octokit 4.22.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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +117 -95
  3. data/Rakefile +20 -14
  4. data/lib/ext/sawyer/relation.rb +4 -2
  5. data/lib/octokit/arguments.rb +3 -3
  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 +111 -8
  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 +63 -26
  13. data/lib/octokit/client/checks.rb +18 -9
  14. data/lib/octokit/client/code_scanning.rb +190 -0
  15. data/lib/octokit/client/codespaces_secrets.rb +108 -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 +19 -22
  22. data/lib/octokit/client/dependabot_secrets.rb +108 -0
  23. data/lib/octokit/client/deployments.rb +8 -8
  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 +58 -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 +1 -7
  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/pull_requests.rb +66 -45
  47. data/lib/octokit/client/rate_limit.rb +9 -11
  48. data/lib/octokit/client/reactions.rb +62 -16
  49. data/lib/octokit/client/refs.rb +14 -17
  50. data/lib/octokit/client/releases.rb +13 -13
  51. data/lib/octokit/client/repositories.rb +92 -69
  52. data/lib/octokit/client/repository_invitations.rb +3 -3
  53. data/lib/octokit/client/reviews.rb +8 -8
  54. data/lib/octokit/client/say.rb +4 -5
  55. data/lib/octokit/client/search.rb +24 -10
  56. data/lib/octokit/client/service_status.rb +19 -9
  57. data/lib/octokit/client/source_import.rb +7 -12
  58. data/lib/octokit/client/stats.rb +10 -9
  59. data/lib/octokit/client/statuses.rb +5 -5
  60. data/lib/octokit/client/tokens.rb +31 -0
  61. data/lib/octokit/client/traffic.rb +6 -11
  62. data/lib/octokit/client/users.rb +54 -33
  63. data/lib/octokit/client.rb +42 -18
  64. data/lib/octokit/configurable.rb +51 -31
  65. data/lib/octokit/connection.rb +30 -21
  66. data/lib/octokit/default.rb +66 -35
  67. data/lib/octokit/enterprise_admin_client/admin_stats.rb +13 -14
  68. data/lib/octokit/enterprise_admin_client/license.rb +3 -4
  69. data/lib/octokit/enterprise_admin_client/orgs.rb +3 -4
  70. data/lib/octokit/enterprise_admin_client/search_indexing.rb +7 -8
  71. data/lib/octokit/enterprise_admin_client/users.rb +5 -4
  72. data/lib/octokit/enterprise_admin_client.rb +9 -3
  73. data/lib/octokit/enterprise_management_console_client/management_console.rb +51 -33
  74. data/lib/octokit/enterprise_management_console_client.rb +8 -2
  75. data/lib/octokit/error.rb +51 -34
  76. data/lib/octokit/gist.rb +3 -4
  77. data/lib/octokit/manage_ghes_client/manage_ghes.rb +178 -0
  78. data/lib/octokit/manage_ghes_client.rb +64 -0
  79. data/lib/octokit/middleware/follow_redirects.rb +13 -12
  80. data/lib/octokit/organization.rb +3 -1
  81. data/lib/octokit/rate_limit.rb +8 -6
  82. data/lib/octokit/repo_arguments.rb +3 -4
  83. data/lib/octokit/repository.rb +32 -25
  84. data/lib/octokit/response/base_middleware.rb +10 -0
  85. data/lib/octokit/response/feed_parser.rb +5 -7
  86. data/lib/octokit/response/raise_error.rb +4 -4
  87. data/lib/octokit/user.rb +4 -2
  88. data/lib/octokit/version.rb +4 -2
  89. data/lib/octokit/warnable.rb +4 -5
  90. data/lib/octokit.rb +30 -8
  91. data/octokit.gemspec +12 -11
  92. metadata +19 -31
  93. data/lib/octokit/client/authorizations.rb +0 -182
  94. data/lib/octokit/client/pub_sub_hubbub.rb +0 -111
  95. data/lib/octokit/preview.rb +0 -46
@@ -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
@@ -1,111 +0,0 @@
1
- module Octokit
2
- class Client
3
-
4
- # Methods for the PubSubHubbub API
5
- #
6
- # @see https://developer.github.com/v3/repos/hooks/#pubsubhubbub
7
- module PubSubHubbub
8
-
9
- # Subscribe to a pubsub topic
10
- #
11
- # @param topic [String] A recoginized and supported pubsub topic
12
- # @param callback [String] A callback url to be posted to when the topic event is fired
13
- # @param secret [String] An optional shared secret used to generate a SHA1 HMAC of the outgoing body content
14
- # @return [Boolean] true if the subscribe was successful, otherwise an error is raised
15
- # @see https://developer.github.com/v3/repos/hooks/#subscribing
16
- # @example Subscribe to push events from one of your repositories, having an email sent when fired
17
- # client = Octokit::Client.new(:oauth_token = "token")
18
- # client.subscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com")
19
- def subscribe(topic, callback, secret = nil)
20
- options = {
21
- :"hub.callback" => callback,
22
- :"hub.mode" => "subscribe",
23
- :"hub.topic" => topic
24
- }
25
- options.merge!(:"hub.secret" => secret) unless secret.nil?
26
-
27
- response = pub_sub_hubbub_request(options)
28
-
29
- response.status == 204
30
- end
31
-
32
- # Unsubscribe from a pubsub topic
33
- #
34
- # @param topic [String] A recoginized pubsub topic
35
- # @param callback [String] A callback url to be unsubscribed from
36
- # @return [Boolean] true if the unsubscribe was successful, otherwise an error is raised
37
- # @see https://developer.github.com/v3/repos/hooks/#subscribing
38
- # @example Unsubscribe to push events from one of your repositories, no longer having an email sent when fired
39
- # client = Octokit::Client.new(:oauth_token = "token")
40
- # client.unsubscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com")
41
- def unsubscribe(topic, callback)
42
- options = {
43
- :"hub.callback" => callback,
44
- :"hub.mode" => "unsubscribe",
45
- :"hub.topic" => topic
46
- }
47
- response = pub_sub_hubbub_request(options)
48
-
49
- response.status == 204
50
- end
51
-
52
- # Subscribe to a repository through pubsub
53
- #
54
- # @param repo [String, Repository, Hash] A GitHub repository
55
- # @param service_name [String] service name owner
56
- # @param service_arguments [Hash] params that will be passed by subscribed hook.
57
- # List of services is available @ https://github.com/github/github-services/tree/master/docs.
58
- # Please refer Data node for complete list of arguments.
59
- # @param secret [String] An optional shared secret used to generate a SHA1 HMAC of the outgoing body content
60
- # @return [Boolean] True if subscription successful, false otherwise
61
- # @see https://developer.github.com/v3/repos/hooks/#subscribing
62
- # @example Subscribe to push events to one of your repositories to Travis-CI
63
- # client = Octokit::Client.new(:oauth_token = "token")
64
- # client.subscribe_service_hook('joshk/device_imapable', 'Travis', { :token => "test", :domain => "domain", :user => "user" })
65
- def subscribe_service_hook(repo, service_name, service_arguments = {}, secret = nil)
66
- topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push"
67
- callback = "github://#{service_name}?#{service_arguments.collect{ |k,v| [ k,v ].map{ |p| URI.encode_www_form_component(p) }.join("=") }.join("&") }"
68
- subscribe(topic, callback, secret)
69
- end
70
-
71
- # Unsubscribe repository through pubsub
72
- #
73
- # @param repo [String, Repository, Hash] A GitHub repository
74
- # @param service_name [String] service name owner
75
- # List of services is available @ https://github.com/github/github-services/tree/master/docs.
76
- # @see https://developer.github.com/v3/repos/hooks/#subscribing
77
- # @example Subscribe to push events to one of your repositories to Travis-CI
78
- # client = Octokit::Client.new(:oauth_token = "token")
79
- # client.unsubscribe_service_hook('joshk/device_imapable', 'Travis')
80
- def unsubscribe_service_hook(repo, service_name)
81
- topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push"
82
- callback = "github://#{service_name}"
83
- unsubscribe(topic, callback)
84
- end
85
-
86
- private
87
-
88
- def pub_sub_hubbub_request(options = {})
89
- # This method is janky, bypass normal stack so we don't
90
- # serialize request as JSON
91
- conn = Faraday.new(:url => @api_endpoint) do |http|
92
- http.headers[:user_agent] = user_agent
93
- if basic_authenticated?
94
- http.request :basic_auth, @login, @password
95
- elsif token_authenticated?
96
- http.request :authorization, 'token', @access_token
97
- end
98
- http.request :url_encoded
99
- http.use Octokit::Response::RaiseError
100
- http.adapter Faraday.default_adapter
101
- end
102
-
103
- conn.post do |req|
104
- req.url "hub"
105
- req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
106
- req.body = options
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,46 +0,0 @@
1
- module Octokit
2
-
3
- # Default setup options for preview features
4
- module Preview
5
-
6
- PREVIEW_TYPES = {
7
- :applications_api => 'application/vnd.github.doctor-strange-preview+json'.freeze,
8
- :branch_protection => 'application/vnd.github.luke-cage-preview+json'.freeze,
9
- :commit_search => 'application/vnd.github.cloak-preview+json'.freeze,
10
- :commit_pulls => 'application/vnd.github.groot-preview+json'.freeze,
11
- :commit_branches => 'application/vnd.github.groot-preview+json'.freeze,
12
- :migrations => 'application/vnd.github.wyandotte-preview+json'.freeze,
13
- :licenses => 'application/vnd.github.drax-preview+json'.freeze,
14
- :source_imports => 'application/vnd.github.barred-rock-preview'.freeze,
15
- :reactions => 'application/vnd.github.squirrel-girl-preview'.freeze,
16
- :transfer_repository => 'application/vnd.github.nightshade-preview+json'.freeze,
17
- :issue_timelines => 'application/vnd.github.mockingbird-preview+json'.freeze,
18
- :nested_teams => 'application/vnd.github.hellcat-preview+json'.freeze,
19
- :pages => 'application/vnd.github.mister-fantastic-preview+json'.freeze,
20
- :projects => 'application/vnd.github.inertia-preview+json'.freeze,
21
- :traffic => 'application/vnd.github.spiderman-preview'.freeze,
22
- :topics => 'application/vnd.github.mercy-preview+json'.freeze,
23
- :community_profile => 'application/vnd.github.black-panther-preview+json'.freeze,
24
- :strict_validation => 'application/vnd.github.speedy-preview+json'.freeze,
25
- :template_repositories => 'application/vnd.github.baptiste-preview+json'.freeze,
26
- :project_card_events => 'application/vnd.github.starfox-preview+json'.freeze,
27
- :vulnerability_alerts => 'application/vnd.github.dorian-preview+json'.freeze,
28
- }
29
-
30
- def ensure_api_media_type(type, options)
31
- if options[:accept].nil?
32
- options[:accept] = PREVIEW_TYPES[type]
33
- warn_preview(type)
34
- end
35
- options
36
- end
37
-
38
- def warn_preview(type)
39
- octokit_warn <<-EOS
40
- WARNING: The preview version of the #{type.to_s.capitalize} API is not yet suitable for production use.
41
- You can avoid this message by supplying an appropriate media type in the 'Accept' request
42
- header.
43
- EOS
44
- end
45
- end
46
- end