octokit 4.15.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +2 -4
  3. data/README.md +104 -80
  4. data/Rakefile +5 -3
  5. data/lib/ext/sawyer/relation.rb +4 -2
  6. data/lib/octokit/arguments.rb +2 -2
  7. data/lib/octokit/authentication.rb +12 -14
  8. data/lib/octokit/client/actions_artifacts.rb +71 -0
  9. data/lib/octokit/client/actions_secrets.rb +59 -0
  10. data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
  11. data/lib/octokit/client/actions_workflow_runs.rb +125 -0
  12. data/lib/octokit/client/actions_workflows.rb +68 -0
  13. data/lib/octokit/client/apps.rb +53 -53
  14. data/lib/octokit/client/checks.rb +18 -29
  15. data/lib/octokit/client/commit_branches.rb +20 -0
  16. data/lib/octokit/client/commit_comments.rb +8 -8
  17. data/lib/octokit/client/commit_pulls.rb +2 -2
  18. data/lib/octokit/client/commits.rb +31 -34
  19. data/lib/octokit/client/community_profile.rb +2 -3
  20. data/lib/octokit/client/contents.rb +24 -21
  21. data/lib/octokit/client/deployments.rb +16 -6
  22. data/lib/octokit/client/downloads.rb +5 -6
  23. data/lib/octokit/client/emojis.rb +3 -3
  24. data/lib/octokit/client/events.rb +4 -4
  25. data/lib/octokit/client/feeds.rb +4 -5
  26. data/lib/octokit/client/gists.rb +6 -6
  27. data/lib/octokit/client/gitignore.rb +3 -3
  28. data/lib/octokit/client/hooks.rb +9 -19
  29. data/lib/octokit/client/issues.rb +14 -15
  30. data/lib/octokit/client/labels.rb +10 -10
  31. data/lib/octokit/client/legacy_search.rb +3 -3
  32. data/lib/octokit/client/licenses.rb +3 -6
  33. data/lib/octokit/client/markdown.rb +3 -3
  34. data/lib/octokit/client/marketplace.rb +4 -4
  35. data/lib/octokit/client/meta.rb +4 -5
  36. data/lib/octokit/client/milestones.rb +5 -5
  37. data/lib/octokit/client/notifications.rb +6 -6
  38. data/lib/octokit/client/oauth_applications.rb +116 -0
  39. data/lib/octokit/client/objects.rb +14 -14
  40. data/lib/octokit/client/organizations.rb +112 -70
  41. data/lib/octokit/client/pages.rb +5 -7
  42. data/lib/octokit/client/projects.rb +44 -64
  43. data/lib/octokit/client/pub_sub_hubbub.rb +16 -16
  44. data/lib/octokit/client/pull_requests.rb +52 -42
  45. data/lib/octokit/client/rate_limit.rb +9 -11
  46. data/lib/octokit/client/reactions.rb +6 -11
  47. data/lib/octokit/client/refs.rb +32 -19
  48. data/lib/octokit/client/releases.rb +13 -13
  49. data/lib/octokit/client/repositories.rb +123 -69
  50. data/lib/octokit/client/repository_invitations.rb +3 -3
  51. data/lib/octokit/client/reviews.rb +7 -7
  52. data/lib/octokit/client/say.rb +4 -5
  53. data/lib/octokit/client/search.rb +24 -11
  54. data/lib/octokit/client/service_status.rb +19 -9
  55. data/lib/octokit/client/source_import.rb +7 -12
  56. data/lib/octokit/client/stats.rb +10 -9
  57. data/lib/octokit/client/statuses.rb +5 -5
  58. data/lib/octokit/client/tokens.rb +31 -0
  59. data/lib/octokit/client/traffic.rb +6 -11
  60. data/lib/octokit/client/users.rb +104 -24
  61. data/lib/octokit/client.rb +44 -18
  62. data/lib/octokit/configurable.rb +34 -30
  63. data/lib/octokit/connection.rb +28 -26
  64. data/lib/octokit/default.rb +46 -35
  65. data/lib/octokit/enterprise_admin_client/admin_stats.rb +13 -14
  66. data/lib/octokit/enterprise_admin_client/license.rb +3 -4
  67. data/lib/octokit/enterprise_admin_client/orgs.rb +3 -4
  68. data/lib/octokit/enterprise_admin_client/search_indexing.rb +7 -8
  69. data/lib/octokit/enterprise_admin_client/users.rb +5 -4
  70. data/lib/octokit/enterprise_admin_client.rb +9 -3
  71. data/lib/octokit/enterprise_management_console_client/management_console.rb +32 -32
  72. data/lib/octokit/enterprise_management_console_client.rb +8 -2
  73. data/lib/octokit/error.rb +72 -27
  74. data/lib/octokit/gist.rb +2 -3
  75. data/lib/octokit/middleware/follow_redirects.rb +15 -11
  76. data/lib/octokit/organization.rb +3 -1
  77. data/lib/octokit/rate_limit.rb +3 -3
  78. data/lib/octokit/repo_arguments.rb +2 -3
  79. data/lib/octokit/repository.rb +24 -24
  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 +4 -2
  85. data/lib/octokit/warnable.rb +4 -5
  86. data/lib/octokit.rb +15 -8
  87. data/octokit.gemspec +12 -10
  88. metadata +25 -17
  89. data/lib/octokit/client/authorizations.rb +0 -250
  90. data/lib/octokit/preview.rb +0 -46
@@ -1,250 +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
- # Techincally 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
- # Check if a token is valid.
144
- #
145
- # Applications can check if a token is valid without rate limits.
146
- #
147
- # @param token [String] 40 character GitHub OAuth access token
148
- #
149
- # @return [Sawyer::Resource] A single authorization for the authenticated user
150
- # @see https://developer.github.com/v3/oauth_authorizations/#check-an-authorization
151
- # @example
152
- # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
153
- # client.check_application_authorization('deadbeef1234567890deadbeef987654321')
154
- def check_application_authorization(token, options = {})
155
- opts = options.dup
156
- key = opts.delete(:client_id) || client_id
157
- secret = opts.delete(:client_secret) || client_secret
158
-
159
- as_app(key, secret) do |app_client|
160
- app_client.get "applications/#{client_id}/tokens/#{token}", opts
161
- end
162
- end
163
-
164
- # Reset a token
165
- #
166
- # Applications can reset a token without requiring a user to re-authorize.
167
- #
168
- # @param token [String] 40 character GitHub OAuth access token
169
- #
170
- # @return [Sawyer::Resource] A single authorization for the authenticated user
171
- # @see https://developer.github.com/v3/oauth_authorizations/#reset-an-authorization
172
- # @example
173
- # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
174
- # client.reset_application_authorization('deadbeef1234567890deadbeef987654321')
175
- def reset_application_authorization(token, options = {})
176
- opts = options.dup
177
- key = opts.delete(:client_id) || client_id
178
- secret = opts.delete(:client_secret) || client_secret
179
-
180
- as_app(key, secret) do |app_client|
181
- app_client.post "applications/#{client_id}/tokens/#{token}", opts
182
- end
183
- end
184
-
185
- # Revoke a token
186
- #
187
- # Applications can revoke (delete) a token
188
- #
189
- # @param token [String] 40 character GitHub OAuth access token
190
- #
191
- # @return [Boolean] Result
192
- # @see https://developer.github.com/v3/oauth_authorizations/#revoke-an-authorization-for-an-application
193
- # @example
194
- # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
195
- # client.revoke_application_authorization('deadbeef1234567890deadbeef987654321')
196
- def revoke_application_authorization(token, options = {})
197
- opts = options.dup
198
- key = opts.delete(:client_id) || client_id
199
- secret = opts.delete(:client_secret) || client_secret
200
-
201
- as_app(key, secret) do |app_client|
202
- app_client.delete "applications/#{client_id}/tokens/#{token}", opts
203
-
204
- app_client.last_response.status == 204
205
- end
206
- rescue Octokit::NotFound
207
- false
208
- end
209
- alias :delete_application_authorization :revoke_application_authorization
210
-
211
- # Revoke all tokens for an app
212
- #
213
- # Applications can revoke all of their tokens in a single request
214
- #
215
- # @deprecated As of January 25th, 2016: https://developer.github.com/changes/2014-04-08-reset-api-tokens/
216
- # @return [Boolean] false
217
- def revoke_all_application_authorizations(options = {})
218
- octokit_warn("Deprecated: If you need to revoke all tokens for your application, you can do so via the settings page for your application.")
219
- false
220
- end
221
-
222
- # Get the URL to authorize a user for an application via the web flow
223
- #
224
- # @param app_id [String] Client Id we received when our application was registered with GitHub.
225
- # @option options [String] :redirect_uri The url to redirect to after authorizing.
226
- # @option options [String] :scope The scopes to request from the user.
227
- # @option options [String] :state A random string to protect against CSRF.
228
- # @return [String] The url to redirect the user to authorize.
229
- # @see Octokit::Client
230
- # @see https://developer.github.com/v3/oauth/#web-application-flow
231
- # @example
232
- # @client.authorize_url('xxxx')
233
- def authorize_url(app_id = client_id, options = {})
234
- opts = options.dup
235
- if app_id.to_s.empty?
236
- raise Octokit::ApplicationCredentialsRequired.new "client_id required"
237
- end
238
- authorize_url = opts.delete(:endpoint) || Octokit.web_endpoint
239
- authorize_url << "login/oauth/authorize?client_id=#{app_id}"
240
-
241
- require 'cgi'
242
- opts.each do |key, value|
243
- authorize_url << "&#{key}=#{CGI.escape value}"
244
- end
245
-
246
- authorize_url
247
- end
248
- end
249
- end
250
- end
@@ -1,46 +0,0 @@
1
- module Octokit
2
-
3
- # Default setup options for preview features
4
- module Preview
5
-
6
- PREVIEW_TYPES = {
7
- :branch_protection => 'application/vnd.github.luke-cage-preview+json'.freeze,
8
- :checks => 'application/vnd.github.antiope-preview+json'.freeze,
9
- :commit_search => 'application/vnd.github.cloak-preview+json'.freeze,
10
- :commit_pulls => 'application/vnd.github.groot-preview+json'.freeze,
11
- :migrations => 'application/vnd.github.wyandotte-preview+json'.freeze,
12
- :licenses => 'application/vnd.github.drax-preview+json'.freeze,
13
- :source_imports => 'application/vnd.github.barred-rock-preview'.freeze,
14
- :reactions => 'application/vnd.github.squirrel-girl-preview'.freeze,
15
- :transfer_repository => 'application/vnd.github.nightshade-preview+json'.freeze,
16
- :issue_timelines => 'application/vnd.github.mockingbird-preview+json'.freeze,
17
- :nested_teams => 'application/vnd.github.hellcat-preview+json'.freeze,
18
- :pages => 'application/vnd.github.mister-fantastic-preview+json'.freeze,
19
- :projects => 'application/vnd.github.inertia-preview+json'.freeze,
20
- :traffic => 'application/vnd.github.spiderman-preview'.freeze,
21
- :integrations => 'application/vnd.github.machine-man-preview+json'.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
- :drafts => 'application/vnd.github.shadow-cat-preview'.freeze,
26
- :template_repositories => 'application/vnd.github.baptiste-preview+json'.freeze,
27
- :uninstall_github_app => 'application/vnd.github.gambit-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