octokit 4.14.0 → 4.21.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +14 -13
  3. data/README.md +20 -17
  4. data/lib/octokit/authentication.rb +2 -11
  5. data/lib/octokit/client/actions_secrets.rb +58 -0
  6. data/lib/octokit/client/actions_workflow_runs.rb +105 -0
  7. data/lib/octokit/client/actions_workflows.rb +43 -0
  8. data/lib/octokit/client/apps.rb +43 -30
  9. data/lib/octokit/client/authorizations.rb +2 -70
  10. data/lib/octokit/client/checks.rb +0 -20
  11. data/lib/octokit/client/commit_branches.rb +20 -0
  12. data/lib/octokit/client/commit_pulls.rb +20 -0
  13. data/lib/octokit/client/contents.rb +4 -0
  14. data/lib/octokit/client/deployments.rb +10 -0
  15. data/lib/octokit/client/events.rb +1 -0
  16. data/lib/octokit/client/issues.rb +7 -2
  17. data/lib/octokit/client/oauth_applications.rb +122 -0
  18. data/lib/octokit/client/organizations.rb +39 -11
  19. data/lib/octokit/client/pull_requests.rb +1 -1
  20. data/lib/octokit/client/refs.rb +19 -3
  21. data/lib/octokit/client/repositories.rb +106 -8
  22. data/lib/octokit/client/repository_invitations.rb +1 -1
  23. data/lib/octokit/client/reviews.rb +18 -0
  24. data/lib/octokit/client/search.rb +1 -1
  25. data/lib/octokit/client/users.rb +86 -0
  26. data/lib/octokit/client.rb +12 -0
  27. data/lib/octokit/connection.rb +11 -8
  28. data/lib/octokit/error.rb +54 -2
  29. data/lib/octokit/middleware/follow_redirects.rb +1 -1
  30. data/lib/octokit/preview.rb +7 -3
  31. data/lib/octokit/rate_limit.rb +1 -1
  32. data/lib/octokit/response/feed_parser.rb +0 -2
  33. data/lib/octokit/response/raise_error.rb +0 -2
  34. data/lib/octokit/version.rb +1 -1
  35. data/octokit.gemspec +1 -0
  36. metadata +22 -2
@@ -59,7 +59,7 @@ module Octokit
59
59
  # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
60
60
  # client.create_authorization({:idempotent => true, :client_id => 'xxxx', :client_secret => 'yyyy', :scopes => ["user"]})
61
61
  def create_authorization(options = {})
62
- # Techincally we can omit scopes as GitHub has a default, however the
62
+ # Technically we can omit scopes as GitHub has a default, however the
63
63
  # API will reject us if we send a POST request with an empty body.
64
64
  options = options.dup
65
65
  if options.delete :idempotent
@@ -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}"
@@ -23,7 +23,6 @@ module Octokit
23
23
  # check_run.head_sha # => "7638417db6d59f3c431d3e1f261cc637155684cd"
24
24
  # check_run.status # => "queued"
25
25
  def create_check_run(repo, name, head_sha, options = {})
26
- ensure_api_media_type(:checks, options)
27
26
  options[:name] = name
28
27
  options[:head_sha] = head_sha
29
28
 
@@ -41,8 +40,6 @@ module Octokit
41
40
  # check_run.id # => 51295429
42
41
  # check_run.status # => "in_progress"
43
42
  def update_check_run(repo, id, options = {})
44
- ensure_api_media_type(:checks, options)
45
-
46
43
  patch "#{Repository.path repo}/check-runs/#{id}", options
47
44
  end
48
45
 
@@ -63,8 +60,6 @@ module Octokit
63
60
  # result.check_runs[0].id # => 51295429
64
61
  # result.check_runs[0].status # => "in_progress"
65
62
  def check_runs_for_ref(repo, ref, options = {})
66
- ensure_api_media_type(:checks, options)
67
-
68
63
  get "#{Repository.path repo}/commits/#{ref}/check-runs", options
69
64
  end
70
65
  alias :list_check_runs_for_ref :check_runs_for_ref
@@ -86,8 +81,6 @@ module Octokit
86
81
  # result.check_runs[0].check_suite.id # => 50440400
87
82
  # result.check_runs[0].status # => "in_progress"
88
83
  def check_runs_for_check_suite(repo, id, options = {})
89
- ensure_api_media_type(:checks, options)
90
-
91
84
  get "#{Repository.path repo}/check-suites/#{id}/check-runs", options
92
85
  end
93
86
  alias :list_check_runs_for_check_suite :check_runs_for_check_suite
@@ -99,8 +92,6 @@ module Octokit
99
92
  # @return [Sawyer::Resource] A hash representing the check run
100
93
  # @see https://developer.github.com/v3/checks/runs/#get-a-single-check-run
101
94
  def check_run(repo, id, options = {})
102
- ensure_api_media_type(:checks, options)
103
-
104
95
  get "#{Repository.path repo}/check-runs/#{id}", options
105
96
  end
106
97
 
@@ -116,8 +107,6 @@ module Octokit
116
107
  # annotations[0].path # => "README.md"
117
108
  # annotations[0].message # => "Looks good!"
118
109
  def check_run_annotations(repo, id, options = {})
119
- ensure_api_media_type(:checks, options)
120
-
121
110
  get "#{Repository.path repo}/check-runs/#{id}/annotations", options
122
111
  end
123
112
 
@@ -132,8 +121,6 @@ module Octokit
132
121
  # @return [Sawyer::Resource] A hash representing the check suite
133
122
  # @see https://developer.github.com/v3/checks/suites/#get-a-single-check-suite
134
123
  def check_suite(repo, id, options = {})
135
- ensure_api_media_type(:checks, options)
136
-
137
124
  get "#{Repository.path repo}/check-suites/#{id}", options
138
125
  end
139
126
 
@@ -153,8 +140,6 @@ module Octokit
153
140
  # result.check_suites[0].id # => 50440400
154
141
  # result.check_suites[0].app.id # => 76765
155
142
  def check_suites_for_ref(repo, ref, options = {})
156
- ensure_api_media_type(:checks, options)
157
-
158
143
  get "#{Repository.path repo}/commits/#{ref}/check-suites", options
159
144
  end
160
145
  alias :list_check_suites_for_ref :check_suites_for_ref
@@ -172,8 +157,6 @@ module Octokit
172
157
  # result.preferences.auto_trigger_checks[0].setting # => false
173
158
  # result.repository.full_name # => "octocat/Hello-World"
174
159
  def set_check_suite_preferences(repo, options = {})
175
- ensure_api_media_type(:checks, options)
176
-
177
160
  patch "#{Repository.path repo}/check-suites/preferences", options
178
161
  end
179
162
 
@@ -188,7 +171,6 @@ module Octokit
188
171
  # check_suite.head_sha # => "7638417db6d59f3c431d3e1f261cc637155684cd"
189
172
  # check_suite.status # => "queued"
190
173
  def create_check_suite(repo, head_sha, options = {})
191
- ensure_api_media_type(:checks, options)
192
174
  options[:head_sha] = head_sha
193
175
 
194
176
  post "#{Repository.path repo}/check-suites", options
@@ -201,8 +183,6 @@ module Octokit
201
183
  # @return [Boolean] True if successful, raises an error otherwise
202
184
  # @see https://developer.github.com/v3/checks/suites/#rerequest-check-suite
203
185
  def rerequest_check_suite(repo, id, options = {})
204
- ensure_api_media_type(:checks, options)
205
-
206
186
  post "#{Repository.path repo}/check-suites/#{id}/rerequest", options
207
187
  true
208
188
  end
@@ -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
@@ -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
@@ -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 access_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 access_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
@@ -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
@@ -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.
@@ -676,7 +690,7 @@ module Octokit
676
690
 
677
691
  # Edit an organization membership
678
692
  #
679
- # @param org [String] Organization GitHub login.
693
+ # @param org [String, Integer] Organization GitHub login or id.
680
694
  # @option options [String] :role The role of the user in the organization.
681
695
  # @option options [String] :state The state that the membership should be in.
682
696
  # @option options [String] :user The login of the user, otherwise authenticated user.
@@ -687,7 +701,7 @@ module Octokit
687
701
  options = options.dup
688
702
  if user = options.delete(:user)
689
703
  options.delete(:state)
690
- put "orgs/#{org}/memberships/#{user}", options
704
+ put "#{Organization.path(org)}/memberships/#{user}", options
691
705
  else
692
706
  options.delete(:role)
693
707
  patch "user/memberships/orgs/#{org}", options
@@ -697,13 +711,13 @@ module Octokit
697
711
 
698
712
  # Remove an organization membership
699
713
  #
700
- # @param org [String] Organization GitHub login.
714
+ # @param org [String, Integer] Organization GitHub login or id.
701
715
  # @return [Boolean] Success
702
716
  # @see https://developer.github.com/v3/orgs/members/#remove-organization-membership
703
717
  def remove_organization_membership(org, options = {})
704
718
  options = options.dup
705
719
  user = options.delete(:user)
706
- user && boolean_from_response(:delete, "orgs/#{org}/memberships/#{user}", options)
720
+ user && boolean_from_response(:delete, "#{Organization.path(org)}/memberships/#{user}", options)
707
721
  end
708
722
  alias :remove_org_membership :remove_organization_membership
709
723
 
@@ -721,7 +735,7 @@ module Octokit
721
735
  def start_migration(org, repositories, options = {})
722
736
  options = ensure_api_media_type(:migrations, options)
723
737
  options[:repositories] = repositories
724
- post "orgs/#{org}/migrations", options
738
+ post "#{Organization.path(org)}/migrations", options
725
739
  end
726
740
 
727
741
  # Lists the most recent migrations.
@@ -733,7 +747,7 @@ module Octokit
733
747
  # @see https://developer.github.com/v3/orgs/migrations/#get-a-list-of-migrations
734
748
  def migrations(org, options = {})
735
749
  options = ensure_api_media_type(:migrations, options)
736
- paginate "orgs/#{org}/migrations", options
750
+ paginate "#{Organization.path(org)}/migrations", options
737
751
  end
738
752
 
739
753
  # Fetches the status of a migration.
@@ -745,7 +759,7 @@ module Octokit
745
759
  # @see https://developer.github.com/v3/orgs/migrations/#get-the-status-of-a-migration
746
760
  def migration_status(org, id, options = {})
747
761
  options = ensure_api_media_type(:migrations, options)
748
- get "orgs/#{org}/migrations/#{id}", options
762
+ get "#{Organization.path(org)}/migrations/#{id}", options
749
763
  end
750
764
 
751
765
  # Fetches the URL to a migration archive.
@@ -757,7 +771,7 @@ module Octokit
757
771
  # @see https://developer.github.com/v3/orgs/migrations/#download-a-migration-archive
758
772
  def migration_archive_url(org, id, options = {})
759
773
  options = ensure_api_media_type(:migrations, options)
760
- url = "orgs/#{org}/migrations/#{id}/archive"
774
+ url = "#{Organization.path(org)}/migrations/#{id}/archive"
761
775
 
762
776
  response = client_without_redirects(options).get(url)
763
777
  response.headers['location']
@@ -772,7 +786,7 @@ module Octokit
772
786
  # @see https://developer.github.com/v3/orgs/migrations/#delete-a-migration-archive
773
787
  def delete_migration_archive(org, id, options = {})
774
788
  options = ensure_api_media_type(:migrations, options)
775
- delete "orgs/#{org}/migrations/#{id}/archive", options
789
+ delete "#{Organization.path(org)}/migrations/#{id}/archive", options
776
790
  end
777
791
 
778
792
  # Unlock a previous migration archive.
@@ -785,7 +799,21 @@ module Octokit
785
799
  # @see https://developer.github.com/v3/orgs/migrations/#unlock-a-repository
786
800
  def unlock_repository(org, id, repo, options = {})
787
801
  options = ensure_api_media_type(:migrations, options)
788
- delete "orgs/#{org}/migrations/#{id}/repos/#{repo}/lock", options
802
+ delete "#{Organization.path(org)}/migrations/#{id}/repos/#{repo}/lock", options
803
+ end
804
+
805
+ # Get GitHub Actions billing for an organization
806
+ #
807
+ # Requires authenticated organization owner.
808
+ #
809
+ # @param org [String, Integer] Organization GitHub login or id.
810
+ # @return [Sawyer::Resource] Hash representing GitHub Actions billing for an organization.
811
+ # @see https://docs.github.com/en/rest/reference/billing#get-github-actions-billing-for-an-organization
812
+ #
813
+ # @example
814
+ # @client.billing_actions('github')
815
+ def billing_actions(org)
816
+ get "#{Organization.path(org)}/settings/billing/actions"
789
817
  end
790
818
  end
791
819
  end
@@ -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
@@ -23,6 +23,18 @@ module Octokit
23
23
  alias :references :refs
24
24
  alias :list_references :refs
25
25
 
26
+ # Fetch matching refs
27
+ #
28
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
29
+ # @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt> or <tt>heads/rails-3</tt>
30
+ # @return [Array<Sawyer::Resource>] The reference matching the given repo and the ref id
31
+ # @see https://developer.github.com/v3/git/refs/#list-matching-references
32
+ # @example Fetch refs matching tags/v2 for sferik/rails_admin
33
+ # Octokit.ref("sferik/rails_admin","tags/v2")
34
+ def matching_refs(repo, ref, options = {})
35
+ paginate "#{Repository.path repo}/git/matching-refs/#{ref}", options
36
+ end
37
+
26
38
  # Fetch a given reference
27
39
  #
28
40
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
@@ -60,11 +72,13 @@ module Octokit
60
72
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
61
73
  # @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
62
74
  # @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.
75
+ # @param force [Boolean] A flag indicating whether to force the update or to make sure the update is a fast-forward update.
64
76
  # @return [Array<Sawyer::Resource>] The list of references updated
65
77
  # @see https://developer.github.com/v3/git/refs/#update-a-reference
66
78
  # @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
67
79
  # Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
80
+ # @example Fast-forward update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
81
+ # Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", false)
68
82
  def update_ref(repo, ref, sha, force = true, options = {})
69
83
  parameters = {
70
84
  :sha => sha,
@@ -79,11 +93,13 @@ module Octokit
79
93
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
80
94
  # @param branch [String] The ref, e.g. <tt>feature/new-shiny</tt>
81
95
  # @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.
96
+ # @param force [Boolean] A flag indicating whether to force the update or to make sure the update is a fast-forward update.
83
97
  # @return [Array<Sawyer::Resource>] The list of references updated
84
98
  # @see https://developer.github.com/v3/git/refs/#update-a-reference
85
99
  # @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
86
- # Octokit.update_ref("octocat/Hello-World","sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
100
+ # Octokit.update_branch("octocat/Hello-World", "sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
101
+ # @example Fast-forward update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
102
+ # Octokit.update_branch("octocat/Hello-World", "sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", false)
87
103
  def update_branch(repo, branch, sha, force = true, options = {})
88
104
  update_ref repo, "heads/#{branch}", sha, force, options
89
105
  end