octokit 4.15.0 → 4.21.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
 
@@ -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
@@ -333,7 +333,7 @@ module Octokit
333
333
  # @return [Sawyer::Resource] Hash representing team.
334
334
  # @see https://developer.github.com/v3/teams/#get-team-by-name
335
335
  # @example
336
- # @client.team("github", "justice-league")
336
+ # @client.team_by_name("github", "justice-league")
337
337
  def team_by_name(org, team_slug, options = {})
338
338
  get "#{Organization.path(org)}/teams/#{team_slug}", options
339
339
  end
@@ -690,7 +690,7 @@ module Octokit
690
690
 
691
691
  # Edit an organization membership
692
692
  #
693
- # @param org [String] Organization GitHub login.
693
+ # @param org [String, Integer] Organization GitHub login or id.
694
694
  # @option options [String] :role The role of the user in the organization.
695
695
  # @option options [String] :state The state that the membership should be in.
696
696
  # @option options [String] :user The login of the user, otherwise authenticated user.
@@ -701,7 +701,7 @@ module Octokit
701
701
  options = options.dup
702
702
  if user = options.delete(:user)
703
703
  options.delete(:state)
704
- put "orgs/#{org}/memberships/#{user}", options
704
+ put "#{Organization.path(org)}/memberships/#{user}", options
705
705
  else
706
706
  options.delete(:role)
707
707
  patch "user/memberships/orgs/#{org}", options
@@ -711,13 +711,13 @@ module Octokit
711
711
 
712
712
  # Remove an organization membership
713
713
  #
714
- # @param org [String] Organization GitHub login.
714
+ # @param org [String, Integer] Organization GitHub login or id.
715
715
  # @return [Boolean] Success
716
716
  # @see https://developer.github.com/v3/orgs/members/#remove-organization-membership
717
717
  def remove_organization_membership(org, options = {})
718
718
  options = options.dup
719
719
  user = options.delete(:user)
720
- user && boolean_from_response(:delete, "orgs/#{org}/memberships/#{user}", options)
720
+ user && boolean_from_response(:delete, "#{Organization.path(org)}/memberships/#{user}", options)
721
721
  end
722
722
  alias :remove_org_membership :remove_organization_membership
723
723
 
@@ -735,7 +735,7 @@ module Octokit
735
735
  def start_migration(org, repositories, options = {})
736
736
  options = ensure_api_media_type(:migrations, options)
737
737
  options[:repositories] = repositories
738
- post "orgs/#{org}/migrations", options
738
+ post "#{Organization.path(org)}/migrations", options
739
739
  end
740
740
 
741
741
  # Lists the most recent migrations.
@@ -747,7 +747,7 @@ module Octokit
747
747
  # @see https://developer.github.com/v3/orgs/migrations/#get-a-list-of-migrations
748
748
  def migrations(org, options = {})
749
749
  options = ensure_api_media_type(:migrations, options)
750
- paginate "orgs/#{org}/migrations", options
750
+ paginate "#{Organization.path(org)}/migrations", options
751
751
  end
752
752
 
753
753
  # Fetches the status of a migration.
@@ -759,7 +759,7 @@ module Octokit
759
759
  # @see https://developer.github.com/v3/orgs/migrations/#get-the-status-of-a-migration
760
760
  def migration_status(org, id, options = {})
761
761
  options = ensure_api_media_type(:migrations, options)
762
- get "orgs/#{org}/migrations/#{id}", options
762
+ get "#{Organization.path(org)}/migrations/#{id}", options
763
763
  end
764
764
 
765
765
  # Fetches the URL to a migration archive.
@@ -771,7 +771,7 @@ module Octokit
771
771
  # @see https://developer.github.com/v3/orgs/migrations/#download-a-migration-archive
772
772
  def migration_archive_url(org, id, options = {})
773
773
  options = ensure_api_media_type(:migrations, options)
774
- url = "orgs/#{org}/migrations/#{id}/archive"
774
+ url = "#{Organization.path(org)}/migrations/#{id}/archive"
775
775
 
776
776
  response = client_without_redirects(options).get(url)
777
777
  response.headers['location']
@@ -786,7 +786,7 @@ module Octokit
786
786
  # @see https://developer.github.com/v3/orgs/migrations/#delete-a-migration-archive
787
787
  def delete_migration_archive(org, id, options = {})
788
788
  options = ensure_api_media_type(:migrations, options)
789
- delete "orgs/#{org}/migrations/#{id}/archive", options
789
+ delete "#{Organization.path(org)}/migrations/#{id}/archive", options
790
790
  end
791
791
 
792
792
  # Unlock a previous migration archive.
@@ -799,7 +799,21 @@ module Octokit
799
799
  # @see https://developer.github.com/v3/orgs/migrations/#unlock-a-repository
800
800
  def unlock_repository(org, id, repo, options = {})
801
801
  options = ensure_api_media_type(:migrations, options)
802
- 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"
803
817
  end
804
818
  end
805
819
  end