octokit 4.19.0 → 4.20.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9801b25dfdd07e517b87bdc1404ffa64fd12496b66af8bb8bc4af57f6f33483f
4
- data.tar.gz: b082dcc32f514846b53da5aaafe7666020c9de8d590dafb6e93743767a70573b
3
+ metadata.gz: 66d0ffe1bcb61d7c4661b0eed991cf4d8bc84c8d0460fe508f064bfc42e08bdf
4
+ data.tar.gz: fd2d7fb934734c88577d07c719ebdba6b8585738fb8e329a05b35e010b6b6b51
5
5
  SHA512:
6
- metadata.gz: 16595560313f6346448710adf2a0d641fe62521089ff017aff1c2f1dc6dd1d5dc06d8397e552a098cf1a6ada91edfa111863d9c4491df86d3d38d3143531a7b5
7
- data.tar.gz: 7dc816349c9050b31e0c0d09a7e1e25b6d455d59f6ae817db2f46b16900104bcdff15d3f280352e7bcb0ca195060824094ebe09ea022c3e46b52c8f559c0cc5b
6
+ metadata.gz: 795b13dc5aa33251042cb0a216e547c9f39fc063ee7ae0f0c009a50838459cb9da52bdd3dcb3883207173bd1fb19c922d86fd74380c8aa02cf51807f8c3420b0
7
+ data.tar.gz: ebe0c7d8d8290aa2a3ad6b55b27d7bd23eff2c0b4f479654aeac2eb5b760cd00174fea8ffcc3ebb5a7bfb4375690fb9096aa74c282780b260a480e23d1a06752
data/README.md CHANGED
@@ -41,7 +41,7 @@ Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
41
41
  1. [Debugging](#debugging)
42
42
  2. [Caching](#caching)
43
43
  14. [Hacking on Octokit.rb](#hacking-on-octokitrb)
44
- 1. [Code of Conduction](#code_of_conduct)
44
+ 1. [Code of Conduct](#code-of-conduct)
45
45
  2. [Running and writing new tests](#running-and-writing-new-tests)
46
46
  15. [Supported Ruby Versions](#supported-ruby-versions)
47
47
  16. [Versioning](#versioning)
@@ -12,8 +12,7 @@ module Octokit
12
12
  #
13
13
  # @return [Sawyer::Resource] App information
14
14
  def app(options = {})
15
- opts = ensure_api_media_type(:integrations, options)
16
- get "app", opts
15
+ get "app", options
17
16
  end
18
17
 
19
18
  # Find all installations that belong to an App
@@ -24,8 +23,7 @@ module Octokit
24
23
  #
25
24
  # @return [Array<Sawyer::Resource>] the total_count and an array of installations
26
25
  def find_app_installations(options = {})
27
- opts = ensure_api_media_type(:integrations, options)
28
- paginate "app/installations", opts
26
+ paginate "app/installations", options
29
27
  end
30
28
  alias find_installations find_app_installations
31
29
 
@@ -47,8 +45,7 @@ module Octokit
47
45
  #
48
46
  # @return [Sawyer::Resource] the total_count and an array of installations
49
47
  def find_user_installations(options = {})
50
- opts = ensure_api_media_type(:integrations, options)
51
- paginate("user/installations", opts) do |data, last_response|
48
+ paginate("user/installations", options) do |data, last_response|
52
49
  data.installations.concat last_response.data.installations
53
50
  end
54
51
  end
@@ -61,8 +58,7 @@ module Octokit
61
58
  #
62
59
  # @return [Sawyer::Resource] Installation information
63
60
  def installation(id, options = {})
64
- opts = ensure_api_media_type(:integrations, options)
65
- get "app/installations/#{id}", opts
61
+ get "app/installations/#{id}", options
66
62
  end
67
63
 
68
64
  # Create a new installation token
@@ -74,8 +70,7 @@ module Octokit
74
70
  #
75
71
  # @return [<Sawyer::Resource>] An installation token
76
72
  def create_app_installation_access_token(installation, options = {})
77
- opts = ensure_api_media_type(:integrations, options)
78
- post "app/installations/#{installation}/access_tokens", opts
73
+ post "app/installations/#{installation}/access_tokens", options
79
74
  end
80
75
  alias create_installation_access_token create_app_installation_access_token
81
76
 
@@ -98,8 +93,7 @@ module Octokit
98
93
  #
99
94
  # @return [Sawyer::Resource] Installation information
100
95
  def find_organization_installation(organization, options = {})
101
- opts = ensure_api_media_type(:integrations, options)
102
- get "#{Organization.path(organization)}/installation", opts
96
+ get "#{Organization.path(organization)}/installation", options
103
97
  end
104
98
 
105
99
  # Enables an app to find the repository's installation information.
@@ -111,8 +105,7 @@ module Octokit
111
105
  #
112
106
  # @return [Sawyer::Resource] Installation information
113
107
  def find_repository_installation(repo, options = {})
114
- opts = ensure_api_media_type(:integrations, options)
115
- get "#{Repository.path(repo)}/installation", opts
108
+ get "#{Repository.path(repo)}/installation", options
116
109
  end
117
110
 
118
111
  # Enables an app to find the user's installation information.
@@ -124,8 +117,7 @@ module Octokit
124
117
  #
125
118
  # @return [Sawyer::Resource] Installation information
126
119
  def find_user_installation(user, options = {})
127
- opts = ensure_api_media_type(:integrations, options)
128
- get "#{User.path(user)}/installation", opts
120
+ get "#{User.path(user)}/installation", options
129
121
  end
130
122
 
131
123
  # List repositories that are accessible to the authenticated installation
@@ -136,8 +128,7 @@ module Octokit
136
128
  #
137
129
  # @return [Sawyer::Resource] the total_count and an array of repositories
138
130
  def list_app_installation_repositories(options = {})
139
- opts = ensure_api_media_type(:integrations, options)
140
- paginate("installation/repositories", opts) do |data, last_response|
131
+ paginate("installation/repositories", options) do |data, last_response|
141
132
  data.repositories.concat last_response.data.repositories
142
133
  end
143
134
  end
@@ -163,8 +154,7 @@ module Octokit
163
154
  #
164
155
  # @return [Boolean] Success
165
156
  def add_repository_to_app_installation(installation, repo, options = {})
166
- opts = ensure_api_media_type(:integrations, options)
167
- boolean_from_response :put, "user/installations/#{installation}/repositories/#{repo}", opts
157
+ boolean_from_response :put, "user/installations/#{installation}/repositories/#{repo}", options
168
158
  end
169
159
  alias add_repo_to_installation add_repository_to_app_installation
170
160
 
@@ -188,8 +178,7 @@ module Octokit
188
178
  #
189
179
  # @return [Boolean] Success
190
180
  def remove_repository_from_app_installation(installation, repo, options = {})
191
- opts = ensure_api_media_type(:integrations, options)
192
- boolean_from_response :delete, "user/installations/#{installation}/repositories/#{repo}", opts
181
+ boolean_from_response :delete, "user/installations/#{installation}/repositories/#{repo}", options
193
182
  end
194
183
  alias remove_repo_from_installation remove_repository_from_app_installation
195
184
 
@@ -212,8 +201,7 @@ module Octokit
212
201
  #
213
202
  # @return [Sawyer::Resource] the total_count and an array of repositories
214
203
  def find_installation_repositories_for_user(installation, options = {})
215
- opts = ensure_api_media_type(:integrations, options)
216
- paginate("user/installations/#{installation}/repositories", opts) do |data, last_response|
204
+ paginate("user/installations/#{installation}/repositories", options) do |data, last_response|
217
205
  data.repositories.concat last_response.data.repositories
218
206
  end
219
207
  end
@@ -16,6 +16,8 @@ module Octokit
16
16
  # @see https://developer.github.com/v3/repos/contents/#get-the-readme
17
17
  # @example Get the readme file for a repo
18
18
  # Octokit.readme("octokit/octokit.rb")
19
+ # @example Get the readme file for a particular branch of the repo
20
+ # Octokit.readme("octokit/octokit.rb", :query => {:ref => 'some-other-branch'})
19
21
  def readme(repo, options={})
20
22
  get "#{Repository.path repo}/readme", options
21
23
  end
@@ -29,6 +31,8 @@ module Octokit
29
31
  # @see https://developer.github.com/v3/repos/contents/#get-contents
30
32
  # @example List the contents of lib/octokit.rb
31
33
  # Octokit.contents("octokit/octokit.rb", :path => 'lib/octokit.rb')
34
+ # @example Lists the contents of lib /octokit.rb on a particular branch
35
+ # Octokit.contents("octokit/octokit.rb", :path => 'lib/octokit.rb', :query => {:ref => 'some-other-branch'})
32
36
  def contents(repo, options={})
33
37
  options = options.dup
34
38
  repo_path = options.delete :path
@@ -43,6 +43,16 @@ module Octokit
43
43
  post("#{Repository.path repo}/deployments", options)
44
44
  end
45
45
 
46
+ # Delete a Deployment
47
+ #
48
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
49
+ # @param deployment_id [Integer, String, Repository, Hash] A GitHub repository
50
+ # @return [No Content]
51
+ # @see https://developer.github.com/v3/repos/deployments/#delete-a-deployment
52
+ def delete_deployment(repo, deployment_id, options = {})
53
+ delete("#{Repository.path repo}/deployments/#{deployment_id}", options)
54
+ end
55
+
46
56
  # List all statuses for a Deployment
47
57
  #
48
58
  # @param deployment_url [String] A URL for a deployment resource
@@ -236,7 +236,7 @@ module Octokit
236
236
  # @example
237
237
  # @client.outside_collaborators('github')
238
238
  def outside_collaborators(org, options={})
239
- get "#{Organization.path org}/outside_collaborators", options
239
+ paginate "#{Organization.path org}/outside_collaborators", options
240
240
  end
241
241
 
242
242
  # Remove outside collaborator from an organization
@@ -733,6 +733,49 @@ module Octokit
733
733
  def dispatch_event(repo, event_type, options = {})
734
734
  boolean_from_response :post, "#{Repository.path repo}/dispatches", options.merge({ event_type: event_type })
735
735
  end
736
+
737
+ # Check to see if vulnerability alerts are enabled for a repository
738
+ #
739
+ # The authenticated user must have admin access to the repository.
740
+ #
741
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
742
+ # @return [Boolean] True if vulnerability alerts are enabled, false otherwise.
743
+ # @see https://docs.github.com/en/rest/reference/repos#check-if-vulnerability-alerts-are-enabled-for-a-repository
744
+ #
745
+ # @example
746
+ # @client.vulnerability_alerts_enabled?("octokit/octokit.rb")
747
+ def vulnerability_alerts_enabled?(repo, options = {})
748
+ opts = ensure_api_media_type(:vulnerability_alerts, options)
749
+ boolean_from_response(:get, "#{Repository.path repo}/vulnerability-alerts", opts)
750
+ end
751
+
752
+ # Enable vulnerability alerts for a repository
753
+ #
754
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
755
+ # @param options [Hash]
756
+ #
757
+ # @return [Boolean] True if vulnerability alerts enabled, false otherwise.
758
+ # @see https://docs.github.com/en/rest/reference/repos#enable-vulnerability-alerts
759
+ # @example Enable vulnerability alerts for a repository
760
+ # @client.enable_vulnerability_alerts("octokit/octokit.rb")
761
+ def enable_vulnerability_alerts(repo, options = {})
762
+ opts = ensure_api_media_type(:vulnerability_alerts, options)
763
+ boolean_from_response(:put, "#{Repository.path repo}/vulnerability-alerts", opts)
764
+ end
765
+
766
+ # Disable vulnerability alerts for a repository
767
+ #
768
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
769
+ # @param options [Hash]
770
+ #
771
+ # @return [Boolean] True if vulnerability alerts disabled, false otherwise.
772
+ # @see https://docs.github.com/en/rest/reference/repos#disable-vulnerability-alerts
773
+ # @example Disable vulnerability alerts for a repository
774
+ # @client.disable_vulnerability_alerts("octokit/octokit.rb")
775
+ def disable_vulnerability_alerts(repo, options = {})
776
+ opts = ensure_api_media_type(:vulnerability_alerts, options)
777
+ boolean_from_response(:delete, "#{Repository.path repo}/vulnerability-alerts", opts)
778
+ end
736
779
  end
737
780
  end
738
781
  end
@@ -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
@@ -84,7 +84,7 @@ module Octokit
84
84
  Octokit::BillingIssue
85
85
  elsif body =~ /Resource protected by organization SAML enforcement/i
86
86
  Octokit::SAMLProtected
87
- elsif body =~ /suspended your access/i
87
+ elsif body =~ /suspended your access|This installation has been suspended/i
88
88
  Octokit::InstallationSuspended
89
89
  else
90
90
  Octokit::Forbidden
@@ -101,6 +101,16 @@ module Octokit
101
101
  end
102
102
  end
103
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
+ else
110
+ Octokit::UnprocessableEntity
111
+ end
112
+ end
113
+
104
114
  # Array of validation errors
105
115
  # @return [Array<Hash>] Error info
106
116
  def errors
@@ -300,6 +310,10 @@ module Octokit
300
310
  # Raised when GitHub returns a 422 HTTP status code
301
311
  class UnprocessableEntity < ClientError; end
302
312
 
313
+ # Raised when GitHub returns a 422 HTTP status code
314
+ # and body matches 'PullRequestReviewComment' and 'commit_id (or end_commit_oid) is not part of the pull request'
315
+ class CommitIsNotPartOfPullRequest < UnprocessableEntity; end
316
+
303
317
  # Raised when GitHub returns a 451 HTTP status code
304
318
  class UnavailableForLegalReasons < ClientError; end
305
319
 
@@ -20,7 +20,6 @@ module Octokit
20
20
  :pages => 'application/vnd.github.mister-fantastic-preview+json'.freeze,
21
21
  :projects => 'application/vnd.github.inertia-preview+json'.freeze,
22
22
  :traffic => 'application/vnd.github.spiderman-preview'.freeze,
23
- :integrations => 'application/vnd.github.machine-man-preview+json'.freeze,
24
23
  :topics => 'application/vnd.github.mercy-preview+json'.freeze,
25
24
  :community_profile => 'application/vnd.github.black-panther-preview+json'.freeze,
26
25
  :strict_validation => 'application/vnd.github.speedy-preview+json'.freeze,
@@ -28,6 +27,7 @@ module Octokit
28
27
  :template_repositories => 'application/vnd.github.baptiste-preview+json'.freeze,
29
28
  :uninstall_github_app => 'application/vnd.github.gambit-preview+json'.freeze,
30
29
  :project_card_events => 'application/vnd.github.starfox-preview+json'.freeze,
30
+ :vulnerability_alerts => 'application/vnd.github.dorian-preview+json'.freeze,
31
31
  }
32
32
 
33
33
  def ensure_api_media_type(type, options)
@@ -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 = 19
8
+ MINOR = 20
9
9
 
10
10
  # Current patch level.
11
11
  # @return [Integer]
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.19.0
4
+ version: 4.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wynn Netherland
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-10-20 00:00:00.000000000 Z
13
+ date: 2020-12-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler