octokit 4.14.0 → 4.20.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}"
@@ -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,7 @@ 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
789
803
  end
790
804
  end
791
805
  end