octokit 4.6.0 → 4.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +14 -13
  3. data/LICENSE.md +1 -1
  4. data/README.md +141 -60
  5. data/lib/ext/sawyer/relation.rb +10 -0
  6. data/lib/octokit/authentication.rb +10 -11
  7. data/lib/octokit/client/actions_secrets.rb +58 -0
  8. data/lib/octokit/client/actions_workflow_runs.rb +105 -0
  9. data/lib/octokit/client/actions_workflows.rb +43 -0
  10. data/lib/octokit/client/apps.rb +222 -0
  11. data/lib/octokit/client/authorizations.rb +12 -74
  12. data/lib/octokit/client/checks.rb +191 -0
  13. data/lib/octokit/client/commit_branches.rb +20 -0
  14. data/lib/octokit/client/commit_pulls.rb +20 -0
  15. data/lib/octokit/client/community_profile.rb +22 -0
  16. data/lib/octokit/client/contents.rb +6 -0
  17. data/lib/octokit/client/deployments.rb +20 -0
  18. data/lib/octokit/client/events.rb +1 -0
  19. data/lib/octokit/client/gists.rb +3 -2
  20. data/lib/octokit/client/issues.rb +48 -1
  21. data/lib/octokit/client/labels.rb +7 -7
  22. data/lib/octokit/client/licenses.rb +1 -1
  23. data/lib/octokit/client/marketplace.rb +56 -0
  24. data/lib/octokit/client/notifications.rb +0 -4
  25. data/lib/octokit/client/oauth_applications.rb +122 -0
  26. data/lib/octokit/client/organizations.rb +149 -16
  27. data/lib/octokit/client/projects.rb +7 -7
  28. data/lib/octokit/client/pull_requests.rb +7 -5
  29. data/lib/octokit/client/rate_limit.rb +2 -2
  30. data/lib/octokit/client/refs.rb +19 -3
  31. data/lib/octokit/client/releases.rb +1 -0
  32. data/lib/octokit/client/repositories.rb +169 -8
  33. data/lib/octokit/client/repository_invitations.rb +1 -8
  34. data/lib/octokit/client/reviews.rb +227 -0
  35. data/lib/octokit/client/search.rb +24 -9
  36. data/lib/octokit/client/source_import.rb +1 -1
  37. data/lib/octokit/client/stats.rb +2 -0
  38. data/lib/octokit/client/statuses.rb +2 -2
  39. data/lib/octokit/client/users.rb +88 -1
  40. data/lib/octokit/client.rb +41 -9
  41. data/lib/octokit/configurable.rb +10 -2
  42. data/lib/octokit/connection.rb +19 -4
  43. data/lib/octokit/default.rb +17 -1
  44. data/lib/octokit/enterprise_admin_client/admin_stats.rb +1 -1
  45. data/lib/octokit/enterprise_admin_client/license.rb +1 -1
  46. data/lib/octokit/enterprise_admin_client/orgs.rb +2 -2
  47. data/lib/octokit/enterprise_admin_client/search_indexing.rb +1 -1
  48. data/lib/octokit/enterprise_admin_client/users.rb +12 -12
  49. data/lib/octokit/enterprise_management_console_client/management_console.rb +1 -1
  50. data/lib/octokit/enterprise_management_console_client.rb +1 -1
  51. data/lib/octokit/error.rb +74 -4
  52. data/lib/octokit/gist.rb +1 -1
  53. data/lib/octokit/middleware/follow_redirects.rb +2 -2
  54. data/lib/octokit/preview.rb +14 -3
  55. data/lib/octokit/rate_limit.rb +4 -4
  56. data/lib/octokit/repository.rb +10 -8
  57. data/lib/octokit/response/feed_parser.rb +0 -2
  58. data/lib/octokit/response/raise_error.rb +0 -2
  59. data/lib/octokit/version.rb +1 -1
  60. data/octokit.gemspec +2 -1
  61. metadata +39 -9
data/lib/octokit/error.rb CHANGED
@@ -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
  #
@@ -21,7 +21,7 @@ module Octokit
21
21
  when 406 then Octokit::NotAcceptable
22
22
  when 409 then Octokit::Conflict
23
23
  when 415 then Octokit::UnsupportedMediaType
24
- when 422 then Octokit::UnprocessableEntity
24
+ when 422 then error_for_422(body)
25
25
  when 451 then Octokit::UnavailableForLegalReasons
26
26
  when 400..499 then Octokit::ClientError
27
27
  when 500 then Octokit::InternalServerError
@@ -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|This installation has been suspended/i
88
+ Octokit::InstallationSuspended
74
89
  else
75
90
  Octokit::Forbidden
76
91
  end
@@ -86,6 +101,18 @@ module Octokit
86
101
  end
87
102
  end
88
103
 
104
+ # Return most appropriate error for 422 HTTP status code
105
+ # @private
106
+ def self.error_for_422(body)
107
+ if body =~ /PullRequestReviewComment/i && body =~ /(commit_id|end_commit_oid) is not part of the pull request/i
108
+ Octokit::CommitIsNotPartOfPullRequest
109
+ elsif body =~ /Path diff too large/i
110
+ Octokit::PathDiffTooLarge
111
+ else
112
+ Octokit::UnprocessableEntity
113
+ end
114
+ end
115
+
89
116
  # Array of validation errors
90
117
  # @return [Array<Hash>] Error info
91
118
  def errors
@@ -103,6 +130,20 @@ module Octokit
103
130
  @response[:status]
104
131
  end
105
132
 
133
+ # Headers returned by the GitHub server.
134
+ #
135
+ # @return [Hash]
136
+ def response_headers
137
+ @response[:response_headers]
138
+ end
139
+
140
+ # Body returned by the GitHub server.
141
+ #
142
+ # @return [String]
143
+ def response_body
144
+ @response[:body]
145
+ end
146
+
106
147
  private
107
148
 
108
149
  def data
@@ -138,8 +179,12 @@ module Octokit
138
179
  return nil unless data.is_a?(Hash) && !Array(data[:errors]).empty?
139
180
 
140
181
  summary = "\nError summary:\n"
141
- summary << data[:errors].map do |hash|
142
- hash.map { |k,v| " #{k}: #{v}" }
182
+ summary << data[:errors].map do |error|
183
+ if error.is_a? Hash
184
+ error.map { |k,v| " #{k}: #{v}" }
185
+ else
186
+ " #{error}"
187
+ end
143
188
  end.join("\n")
144
189
 
145
190
  summary
@@ -213,6 +258,10 @@ module Octokit
213
258
  # and body matches 'login attempts exceeded'
214
259
  class TooManyLoginAttempts < Forbidden; end
215
260
 
261
+ # Raised when GitHub returns a 403 HTTP status code
262
+ # and body matches 'returns blobs up to [0-9]+ MB'
263
+ class TooLargeContent < Forbidden; end
264
+
216
265
  # Raised when GitHub returns a 403 HTTP status code
217
266
  # and body matches 'abuse'
218
267
  class AbuseDetected < Forbidden; end
@@ -229,6 +278,18 @@ module Octokit
229
278
  # and body matches 'account was suspended'
230
279
  class AccountSuspended < Forbidden; end
231
280
 
281
+ # Raised when GitHub returns a 403 HTTP status code
282
+ # and body matches 'billing issue'
283
+ class BillingIssue < Forbidden; end
284
+
285
+ # Raised when GitHub returns a 403 HTTP status code
286
+ # and body matches 'Resource protected by organization SAML enforcement'
287
+ class SAMLProtected < Forbidden; end
288
+
289
+ # Raised when GitHub returns a 403 HTTP status code
290
+ # and body matches 'suspended your access'
291
+ class InstallationSuspended < Forbidden; end
292
+
232
293
  # Raised when GitHub returns a 404 HTTP status code
233
294
  class NotFound < ClientError; end
234
295
 
@@ -251,6 +312,14 @@ module Octokit
251
312
  # Raised when GitHub returns a 422 HTTP status code
252
313
  class UnprocessableEntity < ClientError; end
253
314
 
315
+ # Raised when GitHub returns a 422 HTTP status code
316
+ # and body matches 'PullRequestReviewComment' and 'commit_id (or end_commit_oid) is not part of the pull request'
317
+ class CommitIsNotPartOfPullRequest < UnprocessableEntity; end
318
+
319
+ # Raised when GitHub returns a 422 HTTP status code and body matches 'Path diff too large'.
320
+ # It could occur when attempting to post review comments on a "too large" file.
321
+ class PathDiffTooLarge < UnprocessableEntity; end
322
+
254
323
  # Raised when GitHub returns a 451 HTTP status code
255
324
  class UnavailableForLegalReasons < ClientError; end
256
325
 
@@ -279,4 +348,5 @@ module Octokit
279
348
  # Raised when a repository is created with an invalid format
280
349
  class InvalidRepository < ArgumentError; end
281
350
 
351
+ RATE_LIMITED_ERRORS = [Octokit::TooManyRequests, Octokit::AbuseDetected]
282
352
  end
data/lib/octokit/gist.rb CHANGED
@@ -15,7 +15,7 @@ module Octokit
15
15
 
16
16
  def initialize(gist)
17
17
  case gist
18
- when Fixnum, String
18
+ when Integer, String
19
19
  @id = gist.to_s
20
20
  end
21
21
  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)
@@ -49,7 +49,7 @@ module Octokit
49
49
  # Public: Initialize the middleware.
50
50
  #
51
51
  # options - An options Hash (default: {}):
52
- # :limit - A Fixnum redirect limit (default: 3).
52
+ # :limit - A Integer redirect limit (default: 3).
53
53
  def initialize(app, options = {})
54
54
  super(app)
55
55
  @options = options
@@ -4,16 +4,27 @@ 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
+ :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,
8
12
  :migrations => 'application/vnd.github.wyandotte-preview+json'.freeze,
9
13
  :licenses => 'application/vnd.github.drax-preview+json'.freeze,
10
14
  :source_imports => 'application/vnd.github.barred-rock-preview'.freeze,
11
15
  :reactions => 'application/vnd.github.squirrel-girl-preview'.freeze,
12
- :repository_invitations => 'application/vnd.github.swamp-thing-preview+json'.freeze,
16
+ :transfer_repository => 'application/vnd.github.nightshade-preview+json'.freeze,
13
17
  :issue_timelines => 'application/vnd.github.mockingbird-preview+json'.freeze,
18
+ :nested_teams => 'application/vnd.github.hellcat-preview+json'.freeze,
14
19
  :pages => 'application/vnd.github.mister-fantastic-preview+json'.freeze,
15
20
  :projects => 'application/vnd.github.inertia-preview+json'.freeze,
16
- :traffic => 'application/vnd.github.spiderman-preview'.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,
17
28
  }
18
29
 
19
30
  def ensure_api_media_type(type, options)
@@ -3,13 +3,13 @@ module Octokit
3
3
  # Class for API Rate Limit info
4
4
  #
5
5
  # @!attribute [w] limit
6
- # @return [Fixnum] Max tries per rate limit period
6
+ # @return [Integer] Max tries per rate limit period
7
7
  # @!attribute [w] remaining
8
- # @return [Fixnum] Remaining tries per rate limit period
8
+ # @return [Integer] Remaining tries per rate limit period
9
9
  # @!attribute [w] resets_at
10
10
  # @return [Time] Indicates when rate limit resets
11
11
  # @!attribute [w] resets_in
12
- # @return [Fixnum] Number of seconds when rate limit resets
12
+ # @return [Integer] Number of seconds when rate limit resets
13
13
  #
14
14
  # @see https://developer.github.com/v3/#rate-limiting
15
15
  class RateLimit < Struct.new(:limit, :remaining, :resets_at, :resets_in)
@@ -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)
@@ -28,13 +28,13 @@ module Octokit
28
28
  @owner = repo.owner
29
29
  @name = repo.name
30
30
  when Hash
31
- @name = repo[:repo] ||= repo[:name]
32
- @owner = repo[:owner] ||= repo[:user] ||= repo[:username]
31
+ @name = repo[:repo] || repo[:name]
32
+ @owner = repo[:owner] || repo[:user] || repo[:username]
33
33
  else
34
- raise_invalid_repository!
34
+ raise_invalid_repository!(repo)
35
35
  end
36
36
  if @owner && @name
37
- validate_owner_and_name!
37
+ validate_owner_and_name!(repo)
38
38
  end
39
39
  end
40
40
 
@@ -80,14 +80,16 @@ module Octokit
80
80
 
81
81
  private
82
82
 
83
- def validate_owner_and_name!
83
+ def validate_owner_and_name!(repo)
84
84
  if @owner.include?('/') || @name.include?('/') || !url.match(URI::ABS_URI)
85
- raise_invalid_repository!
85
+ raise_invalid_repository!(repo)
86
86
  end
87
87
  end
88
88
 
89
- def raise_invalid_repository!
90
- raise Octokit::InvalidRepository, "Invalid Repository. Use user/repo format."
89
+ def raise_invalid_repository!(repo)
90
+ msg = "#{repo.inspect} is invalid as a repository identifier. " +
91
+ "Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys."
92
+ raise Octokit::InvalidRepository, msg
91
93
  end
92
94
  end
93
95
  end
@@ -7,8 +7,6 @@ module Octokit
7
7
  # Parses RSS and Atom feed responses.
8
8
  class FeedParser < Faraday::Response::Middleware
9
9
 
10
- private
11
-
12
10
  def on_complete(env)
13
11
  if env[:response_headers]["content-type"] =~ /(\batom|\brss)/
14
12
  require 'rss'
@@ -9,8 +9,6 @@ module Octokit
9
9
  # HTTP status codes returned by the API
10
10
  class RaiseError < Faraday::Response::Middleware
11
11
 
12
- private
13
-
14
12
  def on_complete(response)
15
13
  if error = Octokit::Error.from_response(response)
16
14
  raise error
@@ -5,7 +5,7 @@ module Octokit
5
5
 
6
6
  # Current minor release.
7
7
  # @return [Integer]
8
- MINOR = 6
8
+ MINOR = 21
9
9
 
10
10
  # Current patch level.
11
11
  # @return [Integer]
data/octokit.gemspec CHANGED
@@ -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.6.0
4
+ version: 4.21.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: 2016-11-08 00:00:00.000000000 Z
13
+ date: 2021-04-26 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
@@ -60,13 +80,22 @@ files:
60
80
  - LICENSE.md
61
81
  - README.md
62
82
  - Rakefile
83
+ - lib/ext/sawyer/relation.rb
63
84
  - lib/octokit.rb
64
85
  - lib/octokit/arguments.rb
65
86
  - lib/octokit/authentication.rb
66
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
91
+ - lib/octokit/client/apps.rb
67
92
  - lib/octokit/client/authorizations.rb
93
+ - lib/octokit/client/checks.rb
94
+ - lib/octokit/client/commit_branches.rb
68
95
  - lib/octokit/client/commit_comments.rb
96
+ - lib/octokit/client/commit_pulls.rb
69
97
  - lib/octokit/client/commits.rb
98
+ - lib/octokit/client/community_profile.rb
70
99
  - lib/octokit/client/contents.rb
71
100
  - lib/octokit/client/deployments.rb
72
101
  - lib/octokit/client/downloads.rb
@@ -81,9 +110,11 @@ files:
81
110
  - lib/octokit/client/legacy_search.rb
82
111
  - lib/octokit/client/licenses.rb
83
112
  - lib/octokit/client/markdown.rb
113
+ - lib/octokit/client/marketplace.rb
84
114
  - lib/octokit/client/meta.rb
85
115
  - lib/octokit/client/milestones.rb
86
116
  - lib/octokit/client/notifications.rb
117
+ - lib/octokit/client/oauth_applications.rb
87
118
  - lib/octokit/client/objects.rb
88
119
  - lib/octokit/client/organizations.rb
89
120
  - lib/octokit/client/pages.rb
@@ -96,6 +127,7 @@ files:
96
127
  - lib/octokit/client/releases.rb
97
128
  - lib/octokit/client/repositories.rb
98
129
  - lib/octokit/client/repository_invitations.rb
130
+ - lib/octokit/client/reviews.rb
99
131
  - lib/octokit/client/say.rb
100
132
  - lib/octokit/client/search.rb
101
133
  - lib/octokit/client/service_status.rb
@@ -148,10 +180,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
180
  - !ruby/object:Gem::Version
149
181
  version: 1.3.5
150
182
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 2.4.5.1
183
+ rubygems_version: 3.0.3
153
184
  signing_key:
154
185
  specification_version: 4
155
186
  summary: Ruby toolkit for working with the GitHub API
156
187
  test_files: []
157
- has_rdoc: