octokit 4.13.0 → 4.19.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.
@@ -13,7 +13,7 @@ module Octokit
13
13
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
14
14
  # @param user [String] User GitHub username to add
15
15
  # @return [Sawyer::Resource] The repository invitation
16
- # @see https://developer.github.com/v3/repos/invitations/#invite-a-user-to-a-repository
16
+ # @see https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
17
17
  def invite_user_to_repository(repo, user, options = {})
18
18
  put "#{Repository.path repo}/collaborators/#{user}", options
19
19
  end
@@ -204,6 +204,24 @@ module Octokit
204
204
  options = options.merge(reviewers)
205
205
  delete "#{Repository.path repo}/pulls/#{id}/requested_reviewers", options
206
206
  end
207
+
208
+ # Update a review request comment
209
+ #
210
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
211
+ # @param number [Integer] Number ID of the pull request
212
+ # @param review [Integer] The id of the review
213
+ # @param body [String] body text of the pull request review.
214
+ # @param options [Hash] Method options
215
+ # @see https://developer.github.com/v3/pulls/reviews/#update-a-pull-request-review
216
+ #
217
+ # @example
218
+ # @client.update_pull_request_review('octokit/octokit.rb', 825, 6505518, 'This is close to perfect! Please address the suggested inline change. And add more about this.')
219
+ #
220
+ # @return [Sawyer::Resource] Hash representing the review comment
221
+ def update_pull_request_review(repo, number, review, body, options = {})
222
+ options[:body] = body
223
+ put "#{Repository.path repo}/pulls/#{number}/reviews/#{review}", options
224
+ end
207
225
  end
208
226
  end
209
227
  end
@@ -44,7 +44,7 @@ module Octokit
44
44
  # @option options [Integer] :page Page of paginated results
45
45
  # @option options [Integer] :per_page Number of items per page
46
46
  # @return [Sawyer::Resource] Search results object
47
- # @see https://developer.github.com/v3/search/#search-issues
47
+ # @see https://developer.github.com/v3/search/#search-issues-and-pull-requests
48
48
  def search_issues(query, options = {})
49
49
  search "search/issues", query, options
50
50
  end
@@ -340,6 +340,92 @@ module Octokit
340
340
  end
341
341
  alias :watched :subscriptions
342
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 = ensure_api_media_type(:migrations, options)
356
+ options[:repositories] = repositories
357
+ post "user/migrations", options
358
+ end
359
+
360
+ # Lists the most recent migrations.
361
+ #
362
+ # Requires authenticated user.
363
+ #
364
+ # @return [Array<Sawyer::Resource>] Array of migration resources.
365
+ # @see https://docs.github.com/en/rest/reference/migrations#list-user-migrations
366
+ def user_migrations(options = {})
367
+ options = ensure_api_media_type(:migrations, options)
368
+ paginate "user/migrations", options
369
+ end
370
+
371
+ # Fetches the status of a migration.
372
+ #
373
+ # Requires authenticated user.
374
+ #
375
+ # @param id [Integer] ID number of the migration.
376
+ # @see https://docs.github.com/en/rest/reference/migrations#get-a-user-migration-status
377
+ def user_migration_status(id, options = {})
378
+ options = ensure_api_media_type(:migrations, options)
379
+ get "user/migrations/#{id}", options
380
+ end
381
+
382
+ # Fetches the URL to a migration archive.
383
+ #
384
+ # Requires authenticated user.
385
+ #
386
+ # @param id [Integer] ID number of the migration.
387
+ # @see https://docs.github.com/en/rest/reference/migrations#download-a-user-migration-archive
388
+ def user_migration_archive_url(id, options = {})
389
+ options = ensure_api_media_type(:migrations, options)
390
+ url = "user/migrations/#{id}/archive"
391
+
392
+ response = client_without_redirects(options).get(url)
393
+ response.headers['location']
394
+ end
395
+
396
+ # Deletes a previous migration archive.
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#delete-a-user-migration-archive
402
+ def delete_user_migration_archive(id, options = {})
403
+ options = ensure_api_media_type(:migrations, options)
404
+ delete "user/migrations/#{id}/archive", options
405
+ end
406
+
407
+ # List repositories for a user migration.
408
+ #
409
+ # Requires authenticated user.
410
+ #
411
+ # @param id [Integer] ID number of the migration.
412
+ # @see https://docs.github.com/en/rest/reference/migrations#list-repositories-for-a-user-migration
413
+ def user_migration_repositories(id, options = {})
414
+ options = ensure_api_media_type(:migrations, options)
415
+ get "user/migrations/#{id}/repositories", options
416
+ end
417
+
418
+ # Unlock a user repository which has been locked by a migration.
419
+ #
420
+ # Requires authenticated user.
421
+ #
422
+ # @param id [Integer] ID number of the migration.
423
+ # @param repo [String] Name of the repository.
424
+ # @see https://docs.github.com/en/rest/reference/migrations#unlock-a-user-repository
425
+ def unlock_user_repository(id, repo, options = {})
426
+ options = ensure_api_media_type(:migrations, options)
427
+ delete "user/migrations/#{id}/repos/#{repo}/lock", options
428
+ end
343
429
  end
344
430
 
345
431
  private
@@ -113,7 +113,7 @@ module Octokit
113
113
  elsif bearer_authenticated?
114
114
  http.authorization 'Bearer', @bearer_token
115
115
  elsif application_authenticated?
116
- http.params = http.params.merge application_authentication
116
+ http.basic_auth(@client_id, @client_secret)
117
117
  end
118
118
  end
119
119
  end
@@ -155,6 +155,9 @@ module Octokit
155
155
 
156
156
  @last_response = response = agent.call(method, Addressable::URI.parse(path.to_s).normalize.to_s, data, options)
157
157
  response.data
158
+ rescue Octokit::Error => error
159
+ @last_response = nil
160
+ raise error
158
161
  end
159
162
 
160
163
  # Executes the request, checking if it was successful
@@ -162,7 +165,7 @@ module Octokit
162
165
  # @return [Boolean] True on success, false otherwise
163
166
  def boolean_from_response(method, path, options = {})
164
167
  request(method, path, options)
165
- @last_response.status == 204
168
+ [201, 202, 204].include? @last_response.status
166
169
  rescue Octokit::NotFound
167
170
  false
168
171
  end
@@ -175,7 +178,15 @@ module Octokit
175
178
  conn_opts = @connection_options
176
179
  conn_opts[:builder] = @middleware if @middleware
177
180
  conn_opts[:proxy] = @proxy if @proxy
178
- conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode
181
+ if conn_opts[:ssl].nil?
182
+ conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode
183
+ else
184
+ verify = @connection_options[:ssl][:verify]
185
+ conn_opts[:ssl] = {
186
+ :verify => verify,
187
+ :verify_mode => verify == false ? 0 : @ssl_verify_mode
188
+ }
189
+ end
179
190
  opts[:faraday] = Faraday.new(conn_opts)
180
191
 
181
192
  opts
@@ -1,7 +1,7 @@
1
1
  module Octokit
2
2
  # Custom error class for rescuing from all GitHub errors
3
3
  class Error < StandardError
4
-
4
+ attr_reader :context
5
5
  # Returns the appropriate Octokit::Error subclass based
6
6
  # on status and response message
7
7
  #
@@ -34,9 +34,16 @@ module Octokit
34
34
  end
35
35
  end
36
36
 
37
+ def build_error_context
38
+ if RATE_LIMITED_ERRORS.include?(self.class)
39
+ @context = Octokit::RateLimit.from_response(@response)
40
+ end
41
+ end
42
+
37
43
  def initialize(response=nil)
38
44
  @response = response
39
45
  super(build_error_message)
46
+ build_error_context
40
47
  end
41
48
 
42
49
  # Documentation URL returned by the API for some errors
@@ -63,6 +70,8 @@ module Octokit
63
70
  Octokit::TooManyRequests
64
71
  elsif body =~ /login attempts exceeded/i
65
72
  Octokit::TooManyLoginAttempts
73
+ elsif body =~ /returns blobs up to [0-9]+ MB/i
74
+ Octokit::TooLargeContent
66
75
  elsif body =~ /abuse/i
67
76
  Octokit::AbuseDetected
68
77
  elsif body =~ /repository access blocked/i
@@ -71,6 +80,12 @@ module Octokit
71
80
  Octokit::UnverifiedEmail
72
81
  elsif body =~ /account was suspended/i
73
82
  Octokit::AccountSuspended
83
+ elsif body =~ /billing issue/i
84
+ Octokit::BillingIssue
85
+ elsif body =~ /Resource protected by organization SAML enforcement/i
86
+ Octokit::SAMLProtected
87
+ elsif body =~ /suspended your access/i
88
+ Octokit::InstallationSuspended
74
89
  else
75
90
  Octokit::Forbidden
76
91
  end
@@ -231,6 +246,10 @@ module Octokit
231
246
  # and body matches 'login attempts exceeded'
232
247
  class TooManyLoginAttempts < Forbidden; end
233
248
 
249
+ # Raised when GitHub returns a 403 HTTP status code
250
+ # and body matches 'returns blobs up to [0-9]+ MB'
251
+ class TooLargeContent < Forbidden; end
252
+
234
253
  # Raised when GitHub returns a 403 HTTP status code
235
254
  # and body matches 'abuse'
236
255
  class AbuseDetected < Forbidden; end
@@ -247,6 +266,18 @@ module Octokit
247
266
  # and body matches 'account was suspended'
248
267
  class AccountSuspended < Forbidden; end
249
268
 
269
+ # Raised when GitHub returns a 403 HTTP status code
270
+ # and body matches 'billing issue'
271
+ class BillingIssue < Forbidden; end
272
+
273
+ # Raised when GitHub returns a 403 HTTP status code
274
+ # and body matches 'Resource protected by organization SAML enforcement'
275
+ class SAMLProtected < Forbidden; end
276
+
277
+ # Raised when GitHub returns a 403 HTTP status code
278
+ # and body matches 'suspended your access'
279
+ class InstallationSuspended < Forbidden; end
280
+
250
281
  # Raised when GitHub returns a 404 HTTP status code
251
282
  class NotFound < ClientError; end
252
283
 
@@ -297,4 +328,5 @@ module Octokit
297
328
  # Raised when a repository is created with an invalid format
298
329
  class InvalidRepository < ArgumentError; end
299
330
 
331
+ RATE_LIMITED_ERRORS = [Octokit::TooManyRequests, Octokit::AbuseDetected]
300
332
  end
@@ -11,7 +11,7 @@ module Octokit
11
11
  module Middleware
12
12
 
13
13
  # Public: Exception thrown when the maximum amount of requests is exceeded.
14
- class RedirectLimitReached < Faraday::Error::ClientError
14
+ class RedirectLimitReached < Faraday::ClientError
15
15
  attr_reader :response
16
16
 
17
17
  def initialize(response)
@@ -4,8 +4,12 @@ module Octokit
4
4
  module Preview
5
5
 
6
6
  PREVIEW_TYPES = {
7
- :branch_protection => 'application/vnd.github.loki-preview+json'.freeze,
7
+ :applications_api => 'application/vnd.github.doctor-strange-preview+json'.freeze,
8
+ :branch_protection => 'application/vnd.github.luke-cage-preview+json'.freeze,
9
+ :checks => 'application/vnd.github.antiope-preview+json'.freeze,
8
10
  :commit_search => 'application/vnd.github.cloak-preview+json'.freeze,
11
+ :commit_pulls => 'application/vnd.github.groot-preview+json'.freeze,
12
+ :commit_branches => 'application/vnd.github.groot-preview+json'.freeze,
9
13
  :migrations => 'application/vnd.github.wyandotte-preview+json'.freeze,
10
14
  :licenses => 'application/vnd.github.drax-preview+json'.freeze,
11
15
  :source_imports => 'application/vnd.github.barred-rock-preview'.freeze,
@@ -20,6 +24,10 @@ module Octokit
20
24
  :topics => 'application/vnd.github.mercy-preview+json'.freeze,
21
25
  :community_profile => 'application/vnd.github.black-panther-preview+json'.freeze,
22
26
  :strict_validation => 'application/vnd.github.speedy-preview+json'.freeze,
27
+ :drafts => 'application/vnd.github.shadow-cat-preview'.freeze,
28
+ :template_repositories => 'application/vnd.github.baptiste-preview+json'.freeze,
29
+ :uninstall_github_app => 'application/vnd.github.gambit-preview+json'.freeze,
30
+ :project_card_events => 'application/vnd.github.starfox-preview+json'.freeze,
23
31
  }
24
32
 
25
33
  def ensure_api_media_type(type, options)
@@ -20,7 +20,7 @@ module Octokit
20
20
  # @return [RateLimit]
21
21
  def self.from_response(response)
22
22
  info = new
23
- if response && !response.headers.nil?
23
+ if response && response.respond_to?(:headers) && !response.headers.nil?
24
24
  info.limit = (response.headers['X-RateLimit-Limit'] || 1).to_i
25
25
  info.remaining = (response.headers['X-RateLimit-Remaining'] || 1).to_i
26
26
  info.resets_at = Time.at((response.headers['X-RateLimit-Reset'] || Time.now).to_i)
@@ -88,7 +88,7 @@ module Octokit
88
88
 
89
89
  def raise_invalid_repository!(repo)
90
90
  msg = "#{repo.inspect} is invalid as a repository identifier. " +
91
- "Use the repo/user (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys."
91
+ "Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys."
92
92
  raise Octokit::InvalidRepository, msg
93
93
  end
94
94
  end
@@ -5,7 +5,7 @@ module Octokit
5
5
 
6
6
  # Current minor release.
7
7
  # @return [Integer]
8
- MINOR = 13
8
+ MINOR = 19
9
9
 
10
10
  # Current patch level.
11
11
  # @return [Integer]
@@ -4,8 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'octokit/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.add_development_dependency 'bundler', '~> 1.0'
7
+ spec.add_development_dependency 'bundler', '>= 1', '< 3'
8
8
  spec.add_dependency 'sawyer', '>= 0.5.3', '~> 0.8.0'
9
+ spec.add_dependency 'faraday', '>= 0.9'
9
10
  spec.authors = ["Wynn Netherland", "Erik Michaels-Ober", "Clint Shryock"]
10
11
  spec.description = %q{Simple wrapper for the GitHub API}
11
12
  spec.email = ['wynn.netherland@gmail.com', 'sferik@gmail.com', 'clint@ctshryock.com']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.13.0
4
+ version: 4.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wynn Netherland
@@ -10,22 +10,28 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-10-11 00:00:00.000000000 Z
13
+ date: 2020-10-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '1'
22
+ - - "<"
20
23
  - !ruby/object:Gem::Version
21
- version: '1.0'
24
+ version: '3'
22
25
  type: :development
23
26
  prerelease: false
24
27
  version_requirements: !ruby/object:Gem::Requirement
25
28
  requirements:
26
- - - "~>"
29
+ - - ">="
27
30
  - !ruby/object:Gem::Version
28
- version: '1.0'
31
+ version: '1'
32
+ - - "<"
33
+ - !ruby/object:Gem::Version
34
+ version: '3'
29
35
  - !ruby/object:Gem::Dependency
30
36
  name: sawyer
31
37
  requirement: !ruby/object:Gem::Requirement
@@ -46,6 +52,20 @@ dependencies:
46
52
  - - "~>"
47
53
  - !ruby/object:Gem::Version
48
54
  version: 0.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
49
69
  description: Simple wrapper for the GitHub API
50
70
  email:
51
71
  - wynn.netherland@gmail.com
@@ -65,9 +85,15 @@ files:
65
85
  - lib/octokit/arguments.rb
66
86
  - lib/octokit/authentication.rb
67
87
  - lib/octokit/client.rb
88
+ - lib/octokit/client/actions_secrets.rb
89
+ - lib/octokit/client/actions_workflow_runs.rb
90
+ - lib/octokit/client/actions_workflows.rb
68
91
  - lib/octokit/client/apps.rb
69
92
  - lib/octokit/client/authorizations.rb
93
+ - lib/octokit/client/checks.rb
94
+ - lib/octokit/client/commit_branches.rb
70
95
  - lib/octokit/client/commit_comments.rb
96
+ - lib/octokit/client/commit_pulls.rb
71
97
  - lib/octokit/client/commits.rb
72
98
  - lib/octokit/client/community_profile.rb
73
99
  - lib/octokit/client/contents.rb
@@ -88,6 +114,7 @@ files:
88
114
  - lib/octokit/client/meta.rb
89
115
  - lib/octokit/client/milestones.rb
90
116
  - lib/octokit/client/notifications.rb
117
+ - lib/octokit/client/oauth_applications.rb
91
118
  - lib/octokit/client/objects.rb
92
119
  - lib/octokit/client/organizations.rb
93
120
  - lib/octokit/client/pages.rb
@@ -153,8 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
180
  - !ruby/object:Gem::Version
154
181
  version: 1.3.5
155
182
  requirements: []
156
- rubyforge_project:
157
- rubygems_version: 2.7.7
183
+ rubygems_version: 3.0.3
158
184
  signing_key:
159
185
  specification_version: 4
160
186
  summary: Ruby toolkit for working with the GitHub API