octokit 4.14.0 → 4.18.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: da3e4a3c93344024b60cb7d3c5e13bc90742576c6e43dc3e438f3e16819cdc9f
4
- data.tar.gz: 9a47ad957027e32a4f74ca93250476ae46627d961b6bd349cf62a632da04477f
3
+ metadata.gz: 6769ee0502378ac696ca5c6fe2cf854eb67ad86affebf92342a6f30997d3f181
4
+ data.tar.gz: 9a189f3ee1bdd7164ce1a189d62f014e0440a648ac40dfdc8e7bf8c57af4d5fa
5
5
  SHA512:
6
- metadata.gz: 22921fbc5478cbdcbe17f033b7a63666dc69ff63b1b2fda1f47f37eb2967cd055539c1935a5a767d46e24ed427c2d64457c6057141f77caa3bfdf2ebcd6bd179
7
- data.tar.gz: 1bc0add3fdff8b42dc752c3886f95ba51e8ffd234ff3f0091b7dc7a22dbfd8286b0df2d043646a859cdc0bb2837663b6259339c82a0602296dc9cb305b68ab4a
6
+ metadata.gz: 61f2200517ff1f3f805926d3ce20b3155429e77d6e35ef89ebc0b1e2a826064e658bcc9f32c368cd89618677fa9c1b14d65668b6083ebba56ab36375e605a035
7
+ data.tar.gz: 8bf0ef345c8f3850196d8a2695b5ae9a3f2d90a7c63e9e02944c2876bf381613bb2fd0ecd5c3b11a4aaba75e22d5345269d1ad324c777224b4c65ec4f27eaf4a
data/CONTRIBUTING.md CHANGED
@@ -1,21 +1,24 @@
1
1
  ## Submitting a Pull Request
2
2
 
3
- 0. Check out Hacking on Octokit in the README guide for
3
+ 0. Read our [Code of Conduct](CODE_OF_CONDUCT.md).
4
+ 1. Check out Hacking on Octokit in the README guide for
4
5
  bootstrapping the project for local development.
5
- 1. [Fork the repository.][fork]
6
- 2. [Create a topic branch.][branch]
7
- 3. Add specs for your unimplemented feature or bug fix.
8
- 4. Run `script/test`. If your specs pass, return to step 3.
9
- 5. Implement your feature or bug fix.
10
- 6. Run `script/test`. If your specs fail, return to step 5.
11
- 7. Run `open coverage/index.html`. If your changes are not completely covered
6
+ 2. [Fork the repository.][fork]
7
+ 3. [Create a topic branch.][branch]
8
+ 4. Add specs for your unimplemented feature or bug fix.
9
+ 5. Run `script/test`. If your specs pass, return to step 3.
10
+ 6. Implement your feature or bug fix.
11
+ 7. Run `script/test`. If your specs fail, return to step 5.
12
+ 8. Run `open coverage/index.html`. If your changes are not completely covered
12
13
  by your tests, return to step 4.
13
- 8. Add documentation for your feature or bug fix.
14
- 9. Run `bundle exec rake doc:yard`. If your changes are not 100% documented, go
14
+ 9. Add documentation for your feature or bug fix.
15
+ 10. Run `bundle exec rake doc:yard`. If your changes are not 100% documented, go
15
16
  back to step 8.
16
- 10. Add, commit, and push your changes. For documentation-only fixes, please
17
+ 11. Add, commit, and push your changes. For documentation-only fixes, please
17
18
  add "[ci skip]" to your commit message to avoid needless CI builds.
18
- 11. [Submit a pull request.][pr]
19
+ 12. [Submit a pull request.][pr]
20
+
21
+ Please abide by
19
22
 
20
23
  [fork]: https://help.github.com/articles/fork-a-repo
21
24
  [branch]: https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
data/README.md CHANGED
@@ -41,7 +41,8 @@ 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. [Running and writing new tests](#running-and-writing-new-tests)
44
+ 1. [Code of Conduction](#code_of_conduct)
45
+ 2. [Running and writing new tests](#running-and-writing-new-tests)
45
46
  15. [Supported Ruby Versions](#supported-ruby-versions)
46
47
  16. [Versioning](#versioning)
47
48
  17. [Making Repeating Requests](#making-repeating-requests)
@@ -63,7 +64,7 @@ client.readme 'al3x/sovereign', :accept => 'application/vnd.github.html'
63
64
  ```
64
65
 
65
66
  [wrappers]: http://wynnnetherland.com/journal/what-makes-a-good-api-wrapper
66
- [github-api]: http://developer.github.com
67
+ [github-api]: https://developer.github.com/v3/
67
68
 
68
69
  ## Quick start
69
70
 
@@ -289,7 +290,7 @@ link relations](#hypermedia-agent).
289
290
 
290
291
  ```ruby
291
292
  issues = client.issues 'rails/rails'
292
- issues.concat client.last_response.rels[:next].get.data
293
+ issues.concat client.get(client.last_response.rels[:next].href)
293
294
  ```
294
295
 
295
296
  ### Auto pagination
@@ -653,6 +654,12 @@ to run a Ruby console to poke on Octokit, you can crank one up with:
653
654
  Using the scripts in `./scripts` instead of `bundle exec rspec`, `bundle
654
655
  console`, etc. ensures your dependencies are up-to-date.
655
656
 
657
+ ### Code of Conduct
658
+
659
+ We want both the Octokit.rb and larger Octokit communities to be an open
660
+ and welcoming environments. Please read and follow both in spirit and
661
+ letter [Code of Conduct](CODE_OF_CONDUCT.md).
662
+
656
663
  ### Running and writing new tests
657
664
 
658
665
  Octokit uses [VCR][] for recording and playing back API fixtures during test
@@ -752,7 +759,7 @@ The changes made between versions can be seen on the [project releases page][rel
752
759
  [releases]: https://github.com/octokit/octokit.rb/releases
753
760
 
754
761
  ## Making Repeating Requests
755
- In most cases it would be best to use a [webhooks](https://developer.github.com/webhooks/), but sometimes webhooks don't provide all of the information needed. In those cases where one might need to poll for progress or retry a request on failure, we designed [Octopoller](https://github.com/octokit/octopoller.rb). Octopoller is a micro gem perfect for making repeating requests.
762
+ In most cases it would be best to use a [webhooks](https://developer.github.com/webhooks/), but sometimes webhooks don't provide all of the information needed. In those cases where one might need to poll for progress or retry a request on failure, we designed [Octopoller](https://github.com/octokit/octopoller.rb). Octopoller is a micro gem perfect for making repeating requests.
756
763
 
757
764
  ```ruby
758
765
  Octopoller.poll(timeout: 15.seconds) do
@@ -43,22 +43,13 @@ module Octokit
43
43
  # requests at a higher rate limit
44
44
  #
45
45
  # @see https://developer.github.com/v3/#unauthenticated-rate-limited-requests
46
- # @return Boolean
46
+ # @return [Boolean]
47
47
  def application_authenticated?
48
- !!application_authentication
48
+ @client_id && @client_secret
49
49
  end
50
50
 
51
51
  private
52
52
 
53
- def application_authentication
54
- if @client_id && @client_secret
55
- {
56
- :client_id => @client_id,
57
- :client_secret => @client_secret
58
- }
59
- end
60
- end
61
-
62
53
  def login_from_netrc
63
54
  return unless netrc?
64
55
 
@@ -8,7 +8,7 @@ module Octokit
8
8
  #
9
9
  # @param options [Hash] A customizable set of options
10
10
  #
11
- # @see https://developer.github.com/v3/apps/#find-installations
11
+ # @see https://developer.github.com/v3/apps/#list-installations
12
12
  #
13
13
  # @return [Array<Sawyer::Resource>] the total_count and an array of installations
14
14
  def find_app_installations(options = {})
@@ -31,7 +31,7 @@ module Octokit
31
31
  #
32
32
  # @param options [Hash] A customizable set of options
33
33
  #
34
- # @see https://developer.github.com/v3/apps/#list-installations-for-user
34
+ # @see https://developer.github.com/v3/apps/installations/#list-installations-for-a-user
35
35
  #
36
36
  # @return [Sawyer::Resource] the total_count and an array of installations
37
37
  def find_user_installations(options = {})
@@ -45,7 +45,7 @@ module Octokit
45
45
  #
46
46
  # @param id [Integer] Installation id
47
47
  #
48
- # @see https://developer.github.com/v3/apps/#get-a-single-installation
48
+ # @see https://developer.github.com/v3/apps/#get-an-installation
49
49
  #
50
50
  # @return [Sawyer::Resource] Installation information
51
51
  def installation(id, options = {})
@@ -58,7 +58,7 @@ module Octokit
58
58
  # @param installation [Integer] The id of a GitHub App Installation
59
59
  # @param options [Hash] A customizable set of options
60
60
  #
61
- # @see https://developer.github.com/v3/apps/#find-installations
61
+ # @see https://developer.github.com/v3/apps/#create-a-new-installation-token
62
62
  #
63
63
  # @return [<Sawyer::Resource>] An installation token
64
64
  def create_app_installation_access_token(installation, options = {})
@@ -82,7 +82,7 @@ module Octokit
82
82
  # @param organization [String] Organization GitHub login
83
83
  # @param options [Hash] A customizable set of options
84
84
  #
85
- # @see https://developer.github.com/v3/apps/#find-organization-installation
85
+ # @see https://developer.github.com/v3/apps/#get-an-organization-installation
86
86
  #
87
87
  # @return [Sawyer::Resource] Installation information
88
88
  def find_organization_installation(organization, options = {})
@@ -95,7 +95,7 @@ module Octokit
95
95
  # @param repo [String] A GitHub repository
96
96
  # @param options [Hash] A customizable set of options
97
97
  #
98
- # @see https://developer.github.com/v3/apps/#find-repository-installation
98
+ # @see https://developer.github.com/v3/apps/#get-a-repository-installation
99
99
  #
100
100
  # @return [Sawyer::Resource] Installation information
101
101
  def find_repository_installation(repo, options = {})
@@ -108,7 +108,7 @@ module Octokit
108
108
  # @param user [String] GitHub user login
109
109
  # @param options [Hash] A customizable set of options
110
110
  #
111
- # @see https://developer.github.com/v3/apps/#find-user-installation
111
+ # @see https://developer.github.com/v3/apps/#get-a-user-installation
112
112
  #
113
113
  # @return [Sawyer::Resource] Installation information
114
114
  def find_user_installation(user, options = {})
@@ -119,6 +119,7 @@ module Octokit
119
119
  # List repositories that are accessible to the authenticated installation
120
120
  #
121
121
  # @param options [Hash] A customizable set of options
122
+ #
122
123
  # @see https://developer.github.com/v3/apps/installations/#list-repositories
123
124
  #
124
125
  # @return [Sawyer::Resource] the total_count and an array of repositories
@@ -195,7 +196,7 @@ module Octokit
195
196
  # @param installation [Integer] The id of a GitHub App Installation
196
197
  # @param options [Hash] A customizable set of options
197
198
  #
198
- # @see https://developer.github.com/apps/building-integrations/setting-up-and-registering-github-apps/identifying-users-for-github-apps/
199
+ # @see https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-user-for-an-installation
199
200
  #
200
201
  # @return [Sawyer::Resource] the total_count and an array of repositories
201
202
  def find_installation_repositories_for_user(installation, options = {})
@@ -204,6 +205,19 @@ module Octokit
204
205
  data.repositories.concat last_response.data.repositories
205
206
  end
206
207
  end
208
+
209
+ # Delete an installation and uninstall a GitHub App
210
+ #
211
+ # @param installation [Integer] The id of a GitHub App Installation
212
+ # @param options [Hash] A customizable set of options
213
+ #
214
+ # @see https://developer.github.com/v3/apps/#delete-an-installation
215
+ #
216
+ # @return [Boolean] Success
217
+ def delete_installation(installation, options = {})
218
+ opts = ensure_api_media_type(:uninstall_github_app, options)
219
+ boolean_from_response :delete, "app/installations/#{installation}", opts
220
+ end
207
221
  end
208
222
  end
209
223
  end
@@ -140,74 +140,6 @@ module Octokit
140
140
  sort
141
141
  end
142
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
143
  # Revoke all tokens for an app
212
144
  #
213
145
  # Applications can revoke all of their tokens in a single request
@@ -233,7 +165,7 @@ module Octokit
233
165
  def authorize_url(app_id = client_id, options = {})
234
166
  opts = options.dup
235
167
  if app_id.to_s.empty?
236
- raise Octokit::ApplicationCredentialsRequired.new "client_id required"
168
+ raise Octokit::ApplicationCredentialsRequired, "client_id required"
237
169
  end
238
170
  authorize_url = opts.delete(:endpoint) || Octokit.web_endpoint
239
171
  authorize_url << "login/oauth/authorize?client_id=#{app_id}"
@@ -0,0 +1,20 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Branches for HEAD API
5
+ #
6
+ # @see https://developer.github.com/v3/repos/commits/
7
+ module CommitBranches
8
+
9
+ # List branches for a single HEAD commit
10
+ #
11
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
12
+ # @param sha [String] The SHA of the commit whose branches will be fetched
13
+ # @return [Array] List of branches
14
+ # @see https://developer.github.com/v3/repos/commits/#list-branches-for-head-commit
15
+ def commit_branches(repo, sha, options = {})
16
+ paginate "#{Repository.path repo}/commits/#{sha}/branches-where-head", options
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Commit Pulls API
5
+ #
6
+ # @see https://developer.github.com/v3/repos/comments/
7
+ module CommitPulls
8
+
9
+ # List pulls for a single commit
10
+ #
11
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
12
+ # @param sha [String] The SHA of the commit whose pulls will be fetched
13
+ # @return [Array] List of commit pulls
14
+ # @see https://developer.github.com/v3/repos/commits/#list-pull-requests-associated-with-commit
15
+ def commit_pulls(repo, sha, options = {})
16
+ paginate "#{Repository.path repo}/commits/#{sha}/pulls", options
17
+ end
18
+ end
19
+ end
20
+ end
@@ -131,6 +131,7 @@ module Octokit
131
131
  # @example List all issues events for issue #38 on octokit/octokit.rb
132
132
  # Octokit.issue_events("octokit/octokit.rb", 38)
133
133
  def issue_events(repo, number, options = {})
134
+ options = ensure_api_media_type(:project_card_events, options)
134
135
  paginate "#{Repository.path repo}/issues/#{number}/events", options
135
136
  end
136
137
 
@@ -81,6 +81,7 @@ module Octokit
81
81
  # @param body [String] An optional concise description
82
82
  # @param options [Hash] A customizable set of options.
83
83
  # @option options [String] :assignee User login.
84
+ # @option options [Array<String>] :assignees User login.
84
85
  # @option options [Integer] :milestone Milestone number.
85
86
  # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui,@high</tt>.
86
87
  # @return [Sawyer::Resource] Your newly created issue
@@ -120,6 +121,7 @@ module Octokit
120
121
  # @param number [Integer] Number ID of the issue
121
122
  # @param options [Hash] A customizable set of options.
122
123
  # @option options [String] :assignee User login.
124
+ # @option options [Array<String>] :assignees User login.
123
125
  # @option options [Integer] :milestone Milestone number.
124
126
  # @option options [Array<String>] :labels List of Label names. Example: <tt>['bug', 'ui', '@high']</tt>.
125
127
  # @return [Sawyer::Resource] The updated Issue
@@ -136,6 +138,7 @@ module Octokit
136
138
  # @param number [Integer] Number ID of the issue
137
139
  # @param options [Hash] A customizable set of options.
138
140
  # @option options [String] :assignee User login.
141
+ # @option options [Array<String>] :assignees User login.
139
142
  # @option options [Integer] :milestone Milestone number.
140
143
  # @option options [Array<String>] :labels List of Label names. Example: <tt>['bug', 'ui', '@high']</tt>.
141
144
  # @return [Sawyer::Resource] The updated Issue
@@ -179,6 +182,7 @@ module Octokit
179
182
  # @param body [String] Updated body of the issue
180
183
  # @param options [Hash] A customizable set of options.
181
184
  # @option options [String] :assignee User login.
185
+ # @option options [Array<String>] :assignees User login.
182
186
  # @option options [Integer] :milestone Milestone number.
183
187
  # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui,@high</tt>.
184
188
  # @option options [String] :state State of the issue. <tt>open</tt> or <tt>closed</tt>
@@ -190,6 +194,7 @@ module Octokit
190
194
  # @option options [String] :title Updated title for the issue
191
195
  # @option options [String] :body Updated body of the issue
192
196
  # @option options [String] :assignee User login.
197
+ # @option options [Array<String>] :assignees User login.
193
198
  # @option options [Integer] :milestone Milestone number.
194
199
  # @option options [Array<String>] :labels List of Label names. Example: <tt>['bug', 'ui', '@high']</tt>.
195
200
  # @option options [String] :state State of the issue. <tt>open</tt> or <tt>closed</tt>
@@ -332,7 +337,7 @@ module Octokit
332
337
  #
333
338
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
334
339
  # @param number [Integer] Issue number
335
- # @param assignees [Array] Assignees to be added
340
+ # @param assignees [Array<String>] Assignees to be added
336
341
  # @return [Sawyer::Resource] Issue
337
342
  # @see https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue
338
343
  # @example Add assignees "pengwynn" and "joeyw" to Issue #23 on octokit/octokit.rb
@@ -345,7 +350,7 @@ module Octokit
345
350
  #
346
351
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
347
352
  # @param number [Integer] Issue number
348
- # @param assignees [Array] Assignees to be removed
353
+ # @param assignees [Array<String>] Assignees to be removed
349
354
  # @param options [Hash] Header params for request
350
355
  # @return [Sawyer::Resource] Issue
351
356
  # @see https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+
6
+ # Methods for the OauthApplications API
7
+ #
8
+ # @see https://developer.github.com/v3/apps/oauth_applications
9
+ module OauthApplications
10
+
11
+ # Check if a token is valid.
12
+ #
13
+ # Applications can check if a token is valid without rate limits.
14
+ #
15
+ # @param access_token [String] 40 character GitHub OAuth access token
16
+ #
17
+ # @return [Sawyer::Resource] A single authorization for the authenticated user
18
+ # @see https://developer.github.com/v3/apps/oauth_applications/#check-a-token
19
+ #
20
+ # @example
21
+ # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
22
+ # client.check_token('deadbeef1234567890deadbeef987654321')
23
+ def check_token(access_token, options = {})
24
+ options = ensure_api_media_type(:applications_api, options.dup)
25
+ options[:access_token] = access_token
26
+
27
+ key = options.delete(:client_id) || client_id
28
+ secret = options.delete(:client_secret) || client_secret
29
+
30
+ as_app(key, secret) do |app_client|
31
+ app_client.post "applications/#{client_id}/token", options
32
+ end
33
+ end
34
+ alias check_application_authorization check_token
35
+
36
+ # Reset a token
37
+ #
38
+ # Applications can reset a token without requiring a user to re-authorize.
39
+ #
40
+ # @param access_token [String] 40 character GitHub OAuth access token
41
+ #
42
+ # @return [Sawyer::Resource] A single authorization for the authenticated user
43
+ # @see https://developer.github.com/v3/apps/oauth_applications/#reset-a-token
44
+ #
45
+ # @example
46
+ # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
47
+ # client.reset_token('deadbeef1234567890deadbeef987654321')
48
+ def reset_token(access_token, options = {})
49
+ options = ensure_api_media_type(:applications_api, options.dup)
50
+ options[:access_token] = access_token
51
+
52
+ key = options.delete(:client_id) || client_id
53
+ secret = options.delete(:client_secret) || client_secret
54
+
55
+ as_app(key, secret) do |app_client|
56
+ app_client.patch "applications/#{client_id}/token", options
57
+ end
58
+ end
59
+ alias reset_application_authorization reset_token
60
+
61
+ # Delete an app token
62
+ #
63
+ # Applications can revoke (delete) a token
64
+ #
65
+ # @param token [String] 40 character GitHub OAuth access token
66
+ #
67
+ # @return [Boolean] Result
68
+ # @see https://developer.github.com/v3/apps/oauth_applications/#delete-an-app-token
69
+ #
70
+ # @example
71
+ # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
72
+ # client.delete_token('deadbeef1234567890deadbeef987654321')
73
+ def delete_app_token(access_token, options = {})
74
+ options = ensure_api_media_type(:applications_api, options.dup)
75
+ options[:access_token] = access_token
76
+
77
+ key = options.delete(:client_id) || client_id
78
+ secret = options.delete(:client_secret) || client_secret
79
+
80
+ begin
81
+ as_app(key, secret) do |app_client|
82
+ app_client.delete "applications/#{client_id}/token", options
83
+ app_client.last_response.status == 204
84
+ end
85
+ rescue Octokit::NotFound
86
+ false
87
+ end
88
+ end
89
+ alias delete_application_authorization delete_app_token
90
+ alias revoke_application_authorization delete_app_token
91
+
92
+ # Delete an app authorization
93
+ #
94
+ # OAuth application owners can revoke a grant for their OAuth application and a specific user.
95
+ #
96
+ # @param accces_token [String] 40 character GitHub OAuth access token
97
+ #
98
+ # @return [Boolean] Result
99
+ # @see https://developer.github.com/v3/apps/oauth_applications/#delete-an-app-token
100
+ #
101
+ # @example
102
+ # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
103
+ # client.delete_app_authorization('deadbeef1234567890deadbeef987654321')
104
+ def delete_app_authorization(access_token, options = {})
105
+ options = ensure_api_media_type(:applications_api, options.dup)
106
+ options[:access_token] = access_token
107
+
108
+ key = options.delete(:client_id) || client_id
109
+ secret = options.delete(:client_secret) || client_secret
110
+
111
+ begin
112
+ as_app(key, secret) do |app_client|
113
+ app_client.delete "applications/#{client_id}/grant", options
114
+ app_client.last_response.status == 204
115
+ end
116
+ rescue Octokit::NotFound
117
+ false
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -324,6 +324,20 @@ module Octokit
324
324
  get "teams/#{team_id}", options
325
325
  end
326
326
 
327
+ # Get team by name and org
328
+ #
329
+ # Requires authenticated organization member.
330
+ #
331
+ # @param org [String, Integer] Organization GitHub login or id.
332
+ # @param team_slug [String] Team slug.
333
+ # @return [Sawyer::Resource] Hash representing team.
334
+ # @see https://developer.github.com/v3/teams/#get-team-by-name
335
+ # @example
336
+ # @client.team_by_name("github", "justice-league")
337
+ def team_by_name(org, team_slug, options = {})
338
+ get "#{Organization.path(org)}/teams/#{team_slug}", options
339
+ end
340
+
327
341
  # List child teams
328
342
  #
329
343
  # Requires authenticated organization member.
@@ -11,7 +11,7 @@ module Octokit
11
11
  # @overload pull_requests(repo, options)
12
12
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
13
13
  # @param options [Hash] Method options
14
- # @option options [String] :state `open` or `closed`.
14
+ # @option options [String] :state `open` or `closed` or `all`.
15
15
  # @return [Array<Sawyer::Resource>] Array of pulls
16
16
  # @see https://developer.github.com/v3/pulls/#list-pull-requests
17
17
  # @example
@@ -60,11 +60,13 @@ module Octokit
60
60
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
61
61
  # @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
62
62
  # @param sha [String] A SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
63
- # @param force [Boolean] A flag indicating one wants to force the update to make sure the update is a fast-forward update.
63
+ # @param force [Boolean] A flag indicating whether to force the update or to make sure the update is a fast-forward update.
64
64
  # @return [Array<Sawyer::Resource>] The list of references updated
65
65
  # @see https://developer.github.com/v3/git/refs/#update-a-reference
66
66
  # @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
67
67
  # Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
68
+ # @example Fast-forward update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
69
+ # Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", false)
68
70
  def update_ref(repo, ref, sha, force = true, options = {})
69
71
  parameters = {
70
72
  :sha => sha,
@@ -79,11 +81,13 @@ module Octokit
79
81
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
80
82
  # @param branch [String] The ref, e.g. <tt>feature/new-shiny</tt>
81
83
  # @param sha [String] A SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
82
- # @param force [Boolean] A flag indicating one wants to force the update to make sure the update is a fast-forward update.
84
+ # @param force [Boolean] A flag indicating whether to force the update or to make sure the update is a fast-forward update.
83
85
  # @return [Array<Sawyer::Resource>] The list of references updated
84
86
  # @see https://developer.github.com/v3/git/refs/#update-a-reference
85
87
  # @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
86
- # Octokit.update_ref("octocat/Hello-World","sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
88
+ # Octokit.update_branch("octocat/Hello-World", "sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
89
+ # @example Fast-forward update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
90
+ # Octokit.update_branch("octocat/Hello-World", "sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", false)
87
91
  def update_branch(repo, branch, sha, force = true, options = {})
88
92
  update_ref repo, "heads/#{branch}", sha, force, options
89
93
  end
@@ -41,11 +41,15 @@ module Octokit
41
41
  # @option options [String] :private `true` makes the repository private, and `false` makes it public.
42
42
  # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
43
43
  # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
44
+ # @option options [Boolean] :is_template `true` makes the repository a template, `false` makes it not a template.
44
45
  # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
45
46
  # @option options [String] :default_branch Update the default branch for this repository.
46
47
  # @return [Sawyer::Resource] Repository information
47
48
  def edit_repository(repo, options = {})
48
49
  repo = Repository.new(repo)
50
+ if options.include? :is_template
51
+ options = ensure_api_media_type(:template_repositories, options)
52
+ end
49
53
  options[:name] ||= repo.name
50
54
  patch "repos/#{repo}", options
51
55
  end
@@ -144,6 +148,7 @@ module Octokit
144
148
  # @option options [String] :private `true` makes the repository private, and `false` makes it public.
145
149
  # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
146
150
  # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
151
+ # @option options [Boolean] :is_template `true` makes this repo available as a template repository, `false` to prevent it.
147
152
  # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
148
153
  # @option options [String] :organization Short name for the org under which to create the repo.
149
154
  # @option options [Integer] :team_id The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization.
@@ -155,6 +160,9 @@ module Octokit
155
160
  opts = options.dup
156
161
  organization = opts.delete :organization
157
162
  opts.merge! :name => name
163
+ if opts.include? :is_template
164
+ opts = ensure_api_media_type(:template_repositories, opts)
165
+ end
158
166
 
159
167
  if organization.nil?
160
168
  post 'user/repos', opts
@@ -192,6 +200,22 @@ module Octokit
192
200
  end
193
201
  alias :transfer_repo :transfer_repository
194
202
 
203
+ # Create a repository for a user or organization generated from a template repository
204
+ #
205
+ # @param repo [Integer, String, Hash, Repository] A GitHub template repository
206
+ # @param name [String] Name of the new repo
207
+ # @option options [String] :owner Organization or user who the new repository will belong to.
208
+ # @option options [String] :description Description of the repo
209
+ # @option options [String] :private `true` makes the repository private, and `false` makes it public.
210
+ # @option options [Boolean] :include_all_branches `true` copies all branches from the template repository, `false` (default) makes it only copy the master branch.
211
+ # @return [Sawyer::Resource] Repository info for the new repository
212
+ def create_repository_from_template(repo, name, options = {})
213
+ options.merge! :name => name
214
+ options = ensure_api_media_type(:template_repositories, options)
215
+ post "#{Repository.path repo}/generate", options
216
+ end
217
+ alias :create_repo_from_template :create_repository_from_template
218
+
195
219
  # Hide a public repository
196
220
  #
197
221
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -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
@@ -15,6 +15,8 @@ require 'octokit/client/authorizations'
15
15
  require 'octokit/client/checks'
16
16
  require 'octokit/client/commits'
17
17
  require 'octokit/client/commit_comments'
18
+ require 'octokit/client/commit_pulls'
19
+ require 'octokit/client/commit_branches'
18
20
  require 'octokit/client/community_profile'
19
21
  require 'octokit/client/contents'
20
22
  require 'octokit/client/downloads'
@@ -34,6 +36,7 @@ require 'octokit/client/markdown'
34
36
  require 'octokit/client/marketplace'
35
37
  require 'octokit/client/milestones'
36
38
  require 'octokit/client/notifications'
39
+ require 'octokit/client/oauth_applications'
37
40
  require 'octokit/client/objects'
38
41
  require 'octokit/client/organizations'
39
42
  require 'octokit/client/pages'
@@ -73,6 +76,8 @@ module Octokit
73
76
  include Octokit::Client::Checks
74
77
  include Octokit::Client::Commits
75
78
  include Octokit::Client::CommitComments
79
+ include Octokit::Client::CommitPulls
80
+ include Octokit::Client::CommitBranches
76
81
  include Octokit::Client::CommunityProfile
77
82
  include Octokit::Client::Contents
78
83
  include Octokit::Client::Deployments
@@ -93,6 +98,7 @@ module Octokit
93
98
  include Octokit::Client::Marketplace
94
99
  include Octokit::Client::Milestones
95
100
  include Octokit::Client::Notifications
101
+ include Octokit::Client::OauthApplications
96
102
  include Octokit::Client::Objects
97
103
  include Octokit::Client::Organizations
98
104
  include Octokit::Client::Pages
@@ -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
data/lib/octokit/error.rb CHANGED
@@ -63,6 +63,8 @@ module Octokit
63
63
  Octokit::TooManyRequests
64
64
  elsif body =~ /login attempts exceeded/i
65
65
  Octokit::TooManyLoginAttempts
66
+ elsif body =~ /returns blobs up to [0-9]+ MB/i
67
+ Octokit::TooLargeContent
66
68
  elsif body =~ /abuse/i
67
69
  Octokit::AbuseDetected
68
70
  elsif body =~ /repository access blocked/i
@@ -71,6 +73,10 @@ module Octokit
71
73
  Octokit::UnverifiedEmail
72
74
  elsif body =~ /account was suspended/i
73
75
  Octokit::AccountSuspended
76
+ elsif body =~ /billing issue/i
77
+ Octokit::BillingIssue
78
+ elsif body =~ /Resource protected by organization SAML enforcement/i
79
+ Octokit::SAMLProtected
74
80
  else
75
81
  Octokit::Forbidden
76
82
  end
@@ -231,6 +237,10 @@ module Octokit
231
237
  # and body matches 'login attempts exceeded'
232
238
  class TooManyLoginAttempts < Forbidden; end
233
239
 
240
+ # Raised when GitHub returns a 403 HTTP status code
241
+ # and body matches 'returns blobs up to [0-9]+ MB'
242
+ class TooLargeContent < Forbidden; end
243
+
234
244
  # Raised when GitHub returns a 403 HTTP status code
235
245
  # and body matches 'abuse'
236
246
  class AbuseDetected < Forbidden; end
@@ -247,6 +257,14 @@ module Octokit
247
257
  # and body matches 'account was suspended'
248
258
  class AccountSuspended < Forbidden; end
249
259
 
260
+ # Raised when GitHub returns a 403 HTTP status code
261
+ # and body matches 'billing issue'
262
+ class BillingIssue < Forbidden; end
263
+
264
+ # Raised when GitHub returns a 403 HTTP status code
265
+ # and body matches 'Resource protected by organization SAML enforcement'
266
+ class SAMLProtected < Forbidden; end
267
+
250
268
  # Raised when GitHub returns a 404 HTTP status code
251
269
  class NotFound < ClientError; end
252
270
 
@@ -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,9 +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,
8
9
  :checks => 'application/vnd.github.antiope-preview+json'.freeze,
9
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,
10
13
  :migrations => 'application/vnd.github.wyandotte-preview+json'.freeze,
11
14
  :licenses => 'application/vnd.github.drax-preview+json'.freeze,
12
15
  :source_imports => 'application/vnd.github.barred-rock-preview'.freeze,
@@ -21,6 +24,10 @@ module Octokit
21
24
  :topics => 'application/vnd.github.mercy-preview+json'.freeze,
22
25
  :community_profile => 'application/vnd.github.black-panther-preview+json'.freeze,
23
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,
24
31
  }
25
32
 
26
33
  def ensure_api_media_type(type, options)
@@ -5,7 +5,7 @@ module Octokit
5
5
 
6
6
  # Current minor release.
7
7
  # @return [Integer]
8
- MINOR = 14
8
+ MINOR = 18
9
9
 
10
10
  # Current patch level.
11
11
  # @return [Integer]
data/octokit.gemspec CHANGED
@@ -6,6 +6,7 @@ require 'octokit/version'
6
6
  Gem::Specification.new do |spec|
7
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.14.0
4
+ version: 4.18.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: 2019-03-29 00:00:00.000000000 Z
13
+ date: 2020-03-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
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'
55
69
  description: Simple wrapper for the GitHub API
56
70
  email:
57
71
  - wynn.netherland@gmail.com
@@ -74,7 +88,9 @@ files:
74
88
  - lib/octokit/client/apps.rb
75
89
  - lib/octokit/client/authorizations.rb
76
90
  - lib/octokit/client/checks.rb
91
+ - lib/octokit/client/commit_branches.rb
77
92
  - lib/octokit/client/commit_comments.rb
93
+ - lib/octokit/client/commit_pulls.rb
78
94
  - lib/octokit/client/commits.rb
79
95
  - lib/octokit/client/community_profile.rb
80
96
  - lib/octokit/client/contents.rb
@@ -95,6 +111,7 @@ files:
95
111
  - lib/octokit/client/meta.rb
96
112
  - lib/octokit/client/milestones.rb
97
113
  - lib/octokit/client/notifications.rb
114
+ - lib/octokit/client/oauth_applications.rb
98
115
  - lib/octokit/client/objects.rb
99
116
  - lib/octokit/client/organizations.rb
100
117
  - lib/octokit/client/pages.rb