octokit 4.6.2 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +14 -13
  3. data/LICENSE.md +1 -1
  4. data/README.md +218 -109
  5. data/Rakefile +5 -3
  6. data/lib/ext/sawyer/relation.rb +4 -2
  7. data/lib/octokit/arguments.rb +2 -2
  8. data/lib/octokit/authentication.rb +20 -14
  9. data/lib/octokit/client/actions_secrets.rb +57 -0
  10. data/lib/octokit/client/actions_workflow_jobs.rb +61 -0
  11. data/lib/octokit/client/actions_workflow_runs.rb +121 -0
  12. data/lib/octokit/client/actions_workflows.rb +66 -0
  13. data/lib/octokit/client/apps.rb +222 -0
  14. data/lib/octokit/client/authorizations.rb +30 -89
  15. data/lib/octokit/client/checks.rb +200 -0
  16. data/lib/octokit/client/commit_branches.rb +20 -0
  17. data/lib/octokit/client/commit_comments.rb +8 -8
  18. data/lib/octokit/client/commit_pulls.rb +20 -0
  19. data/lib/octokit/client/commits.rb +31 -34
  20. data/lib/octokit/client/community_profile.rb +21 -0
  21. data/lib/octokit/client/contents.rb +25 -20
  22. data/lib/octokit/client/deployments.rb +25 -5
  23. data/lib/octokit/client/downloads.rb +5 -6
  24. data/lib/octokit/client/emojis.rb +3 -3
  25. data/lib/octokit/client/events.rb +4 -4
  26. data/lib/octokit/client/feeds.rb +4 -5
  27. data/lib/octokit/client/gists.rb +7 -6
  28. data/lib/octokit/client/gitignore.rb +3 -3
  29. data/lib/octokit/client/hooks.rb +10 -10
  30. data/lib/octokit/client/issues.rb +60 -14
  31. data/lib/octokit/client/labels.rb +17 -17
  32. data/lib/octokit/client/legacy_search.rb +3 -3
  33. data/lib/octokit/client/licenses.rb +4 -7
  34. data/lib/octokit/client/markdown.rb +3 -3
  35. data/lib/octokit/client/marketplace.rb +56 -0
  36. data/lib/octokit/client/meta.rb +4 -5
  37. data/lib/octokit/client/milestones.rb +5 -5
  38. data/lib/octokit/client/notifications.rb +6 -10
  39. data/lib/octokit/client/oauth_applications.rb +116 -0
  40. data/lib/octokit/client/objects.rb +14 -14
  41. data/lib/octokit/client/organizations.rb +181 -61
  42. data/lib/octokit/client/pages.rb +5 -7
  43. data/lib/octokit/client/projects.rb +49 -69
  44. data/lib/octokit/client/pub_sub_hubbub.rb +16 -16
  45. data/lib/octokit/client/pull_requests.rb +47 -46
  46. data/lib/octokit/client/rate_limit.rb +11 -13
  47. data/lib/octokit/client/reactions.rb +6 -11
  48. data/lib/octokit/client/refs.rb +33 -18
  49. data/lib/octokit/client/releases.rb +14 -13
  50. data/lib/octokit/client/repositories.rb +194 -53
  51. data/lib/octokit/client/repository_invitations.rb +4 -11
  52. data/lib/octokit/client/reviews.rb +227 -0
  53. data/lib/octokit/client/say.rb +4 -5
  54. data/lib/octokit/client/search.rb +45 -17
  55. data/lib/octokit/client/service_status.rb +19 -9
  56. data/lib/octokit/client/source_import.rb +8 -13
  57. data/lib/octokit/client/stats.rb +12 -9
  58. data/lib/octokit/client/statuses.rb +6 -6
  59. data/lib/octokit/client/traffic.rb +6 -11
  60. data/lib/octokit/client/users.rb +106 -25
  61. data/lib/octokit/client.rb +60 -15
  62. data/lib/octokit/configurable.rb +42 -30
  63. data/lib/octokit/connection.rb +34 -20
  64. data/lib/octokit/default.rb +61 -34
  65. data/lib/octokit/enterprise_admin_client/admin_stats.rb +14 -15
  66. data/lib/octokit/enterprise_admin_client/license.rb +4 -5
  67. data/lib/octokit/enterprise_admin_client/orgs.rb +5 -6
  68. data/lib/octokit/enterprise_admin_client/search_indexing.rb +8 -9
  69. data/lib/octokit/enterprise_admin_client/users.rb +17 -16
  70. data/lib/octokit/enterprise_admin_client.rb +9 -3
  71. data/lib/octokit/enterprise_management_console_client/management_console.rb +33 -33
  72. data/lib/octokit/enterprise_management_console_client.rb +9 -3
  73. data/lib/octokit/error.rb +106 -25
  74. data/lib/octokit/gist.rb +3 -4
  75. data/lib/octokit/middleware/follow_redirects.rb +17 -13
  76. data/lib/octokit/organization.rb +3 -1
  77. data/lib/octokit/rate_limit.rb +6 -6
  78. data/lib/octokit/repo_arguments.rb +2 -3
  79. data/lib/octokit/repository.rb +27 -25
  80. data/lib/octokit/response/base_middleware.rb +10 -0
  81. data/lib/octokit/response/feed_parser.rb +5 -9
  82. data/lib/octokit/response/raise_error.rb +4 -6
  83. data/lib/octokit/user.rb +4 -2
  84. data/lib/octokit/version.rb +5 -3
  85. data/lib/octokit/warnable.rb +4 -5
  86. data/lib/octokit.rb +15 -8
  87. data/octokit.gemspec +13 -10
  88. metadata +52 -21
  89. data/lib/octokit/preview.rb +0 -35
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the Authorizations API
5
6
  #
6
7
  # @see https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api
7
8
  module Authorizations
8
-
9
9
  # List the authenticated user's authorizations
10
10
  #
11
11
  # API for users to manage their own tokens.
@@ -59,17 +59,23 @@ 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
66
66
  client_id, client_secret = fetch_client_id_and_secret(options)
67
- raise ArgumentError.new("Client ID and Secret required for idempotent authorizations") unless client_id && client_secret
67
+ unless client_id && client_secret
68
+ raise ArgumentError, 'Client ID and Secret required for idempotent authorizations'
69
+ end
68
70
 
69
- if fingerprint = options.delete(:fingerprint)
70
- put "authorizations/clients/#{client_id}/#{fingerprint}", options.merge(:client_secret => client_secret)
71
+ # Remove the client_id from the body otherwise
72
+ # this will result in a 422.
73
+ options.delete(:client_id)
74
+
75
+ if (fingerprint = options.delete(:fingerprint))
76
+ put "authorizations/clients/#{client_id}/#{fingerprint}", options.merge(client_secret: client_secret)
71
77
  else
72
- put "authorizations/clients/#{client_id}", options.merge(:client_secret => client_secret)
78
+ put "authorizations/clients/#{client_id}", options.merge(client_secret: client_secret)
73
79
  end
74
80
 
75
81
  else
@@ -122,95 +128,28 @@ module Octokit
122
128
  # @return [Array<String>] OAuth scopes
123
129
  # @see https://developer.github.com/v3/oauth/#scopes
124
130
  def scopes(token = @access_token, options = {})
125
- raise ArgumentError.new("Access token required") if token.nil?
131
+ options = options.dup
132
+ raise ArgumentError, 'Access token required' if token.nil?
126
133
 
127
- auth = { "Authorization" => "token #{token}" }
134
+ auth = { 'Authorization' => "token #{token}" }
128
135
  headers = (options.delete(:headers) || {}).merge(auth)
129
136
 
130
- agent.call(:get, "user", :headers => headers).
131
- headers['X-OAuth-Scopes'].
132
- to_s.
133
- split(',').
134
- map(&:strip).
135
- sort
136
- end
137
-
138
- # Check if a token is valid.
139
- #
140
- # Applications can check if a token is valid without rate limits.
141
- #
142
- # @param token [String] 40 character GitHub OAuth access token
143
- #
144
- # @return [Sawyer::Resource] A single authorization for the authenticated user
145
- # @see https://developer.github.com/v3/oauth_authorizations/#check-an-authorization
146
- # @example
147
- # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
148
- # client.check_application_authorization('deadbeef1234567890deadbeef987654321')
149
- def check_application_authorization(token, options = {})
150
- opts = options.dup
151
- key = opts.delete(:client_id) || client_id
152
- secret = opts.delete(:client_secret) || client_secret
153
-
154
- as_app(key, secret) do |app_client|
155
- app_client.get "/applications/#{client_id}/tokens/#{token}", opts
156
- end
137
+ agent.call(:get, 'user', headers: headers)
138
+ .headers['X-OAuth-Scopes']
139
+ .to_s
140
+ .split(',')
141
+ .map(&:strip)
142
+ .sort
157
143
  end
158
144
 
159
- # Reset a token
160
- #
161
- # Applications can reset a token without requiring a user to re-authorize.
162
- #
163
- # @param token [String] 40 character GitHub OAuth access token
164
- #
165
- # @return [Sawyer::Resource] A single authorization for the authenticated user
166
- # @see https://developer.github.com/v3/oauth_authorizations/#reset-an-authorization
167
- # @example
168
- # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
169
- # client.reset_application_authorization('deadbeef1234567890deadbeef987654321')
170
- def reset_application_authorization(token, options = {})
171
- opts = options.dup
172
- key = opts.delete(:client_id) || client_id
173
- secret = opts.delete(:client_secret) || client_secret
174
-
175
- as_app(key, secret) do |app_client|
176
- app_client.post "/applications/#{client_id}/tokens/#{token}", opts
177
- end
178
- end
179
-
180
- # Revoke a token
181
- #
182
- # Applications can revoke (delete) a token
183
- #
184
- # @param token [String] 40 character GitHub OAuth access token
185
- #
186
- # @return [Boolean] Result
187
- # @see https://developer.github.com/v3/oauth_authorizations/#revoke-an-authorization-for-an-application
188
- # @example
189
- # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
190
- # client.revoke_application_authorization('deadbeef1234567890deadbeef987654321')
191
- def revoke_application_authorization(token, options = {})
192
- opts = options.dup
193
- key = opts.delete(:client_id) || client_id
194
- secret = opts.delete(:client_secret) || client_secret
195
-
196
- as_app(key, secret) do |app_client|
197
- app_client.delete "/applications/#{client_id}/tokens/#{token}", opts
198
-
199
- app_client.last_response.status == 204
200
- end
201
- rescue Octokit::NotFound
202
- false
203
- end
204
- alias :delete_application_authorization :revoke_application_authorization
205
-
206
145
  # Revoke all tokens for an app
207
146
  #
208
147
  # Applications can revoke all of their tokens in a single request
209
148
  #
210
149
  # @deprecated As of January 25th, 2016: https://developer.github.com/changes/2014-04-08-reset-api-tokens/
211
150
  # @return [Boolean] false
212
- def revoke_all_application_authorizations(options = {})
213
- octokit_warn("Deprecated: If you need to revoke all tokens for your application, you can do so via the settings page for your application.")
151
+ def revoke_all_application_authorizations(_options = {})
152
+ octokit_warn('Deprecated: If you need to revoke all tokens for your application, you can do so via the settings page for your application.')
214
153
  false
215
154
  end
216
155
 
@@ -226,14 +165,16 @@ module Octokit
226
165
  # @example
227
166
  # @client.authorize_url('xxxx')
228
167
  def authorize_url(app_id = client_id, options = {})
168
+ opts = options.dup
229
169
  if app_id.to_s.empty?
230
- raise Octokit::ApplicationCredentialsRequired.new "client_id required"
170
+ raise Octokit::ApplicationCredentialsRequired, 'client_id required'
231
171
  end
232
- authorize_url = options.delete(:endpoint) || Octokit.web_endpoint
172
+
173
+ authorize_url = opts.delete(:endpoint) || Octokit.web_endpoint
233
174
  authorize_url << "login/oauth/authorize?client_id=#{app_id}"
234
175
 
235
176
  require 'cgi'
236
- options.each do |key, value|
177
+ opts.each do |key, value|
237
178
  authorize_url << "&#{key}=#{CGI.escape value}"
238
179
  end
239
180
 
@@ -0,0 +1,200 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the Checks API
6
+ #
7
+ # @see https://developer.github.com/v3/checks/
8
+ module Checks
9
+ # Methods for Check Runs
10
+ #
11
+ # @see https://developer.github.com/v3/checks/runs/
12
+
13
+ # Create a check run
14
+ #
15
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
16
+ # @param name [String] The name of the check
17
+ # @param head_sha [String] The SHA of the commit to check
18
+ # @return [Sawyer::Resource] A hash representing the new check run
19
+ # @see https://developer.github.com/v3/checks/runs/#create-a-check-run
20
+ # @example Create a check run
21
+ # check_run = @client.create_check_run("octocat/Hello-World", "my-check", "7638417db6d59f3c431d3e1f261cc637155684cd")
22
+ # check_run.name # => "my-check"
23
+ # check_run.head_sha # => "7638417db6d59f3c431d3e1f261cc637155684cd"
24
+ # check_run.status # => "queued"
25
+ def create_check_run(repo, name, head_sha, options = {})
26
+ options[:name] = name
27
+ options[:head_sha] = head_sha
28
+
29
+ post "#{Repository.path repo}/check-runs", options
30
+ end
31
+
32
+ # Update a check run
33
+ #
34
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
35
+ # @param id [Integer] The ID of the check run
36
+ # @return [Sawyer::Resource] A hash representing the updated check run
37
+ # @see https://developer.github.com/v3/checks/runs/#update-a-check-run
38
+ # @example Update a check run
39
+ # check_run = @client.update_check_run("octocat/Hello-World", 51295429, status: "in_progress")
40
+ # check_run.id # => 51295429
41
+ # check_run.status # => "in_progress"
42
+ def update_check_run(repo, id, options = {})
43
+ patch "#{Repository.path repo}/check-runs/#{id}", options
44
+ end
45
+
46
+ # List check runs for a specific ref
47
+ #
48
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
49
+ # @param ref [String] A SHA, branch name, or tag name
50
+ # @param options [Hash] A set of optional filters
51
+ # @option options [String] :check_name Returns check runs with the specified <tt>name</tt>
52
+ # @option options [String] :status Returns check runs with the specified <tt>status</tt>
53
+ # @option options [String] :filter Filters check runs by their <tt>completed_at</tt> timestamp
54
+ # @return [Sawyer::Resource] A hash representing a collection of check runs
55
+ # @see https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref
56
+ # @example List check runs for a specific ref
57
+ # result = @client.check_runs_for_ref("octocat/Hello-World", "7638417db6d59f3c431d3e1f261cc637155684cd", status: "in_progress")
58
+ # result.total_count # => 1
59
+ # result.check_runs.count # => 1
60
+ # result.check_runs[0].id # => 51295429
61
+ # result.check_runs[0].status # => "in_progress"
62
+ def check_runs_for_ref(repo, ref, options = {})
63
+ paginate "#{Repository.path repo}/commits/#{ref}/check-runs", options do |data, last_response|
64
+ data.check_runs.concat last_response.data.check_runs
65
+ data.total_count += last_response.data.total_count
66
+ end
67
+ end
68
+ alias list_check_runs_for_ref check_runs_for_ref
69
+
70
+ # List check runs in a check suite
71
+ #
72
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
73
+ # @param id [Integer] The ID of the check suite
74
+ # @param options [Hash] A set of optional filters
75
+ # @option options [String] :check_name Returns check runs with the specified <tt>name</tt>
76
+ # @option options [String] :status Returns check runs with the specified <tt>status</tt>
77
+ # @option options [String] :filter Filters check runs by their <tt>completed_at</tt> timestamp
78
+ # @return [Sawyer::Resource] A hash representing a collection of check runs
79
+ # @see https://developer.github.com/v3/checks/runs/#list-check-runs-in-a-check-suite
80
+ # @example List check runs in a check suite
81
+ # result = @client.check_runs_for_check_suite("octocat/Hello-World", 50440400, status: "in_progress")
82
+ # result.total_count # => 1
83
+ # result.check_runs.count # => 1
84
+ # result.check_runs[0].check_suite.id # => 50440400
85
+ # result.check_runs[0].status # => "in_progress"
86
+ def check_runs_for_check_suite(repo, id, options = {})
87
+ paginate "#{Repository.path repo}/check-suites/#{id}/check-runs", options do |data, last_response|
88
+ data.check_runs.concat last_response.data.check_runs
89
+ data.total_count += last_response.data.total_count
90
+ end
91
+ end
92
+ alias list_check_runs_for_check_suite check_runs_for_check_suite
93
+
94
+ # Get a single check run
95
+ #
96
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
97
+ # @param id [Integer] The ID of the check run
98
+ # @return [Sawyer::Resource] A hash representing the check run
99
+ # @see https://developer.github.com/v3/checks/runs/#get-a-single-check-run
100
+ def check_run(repo, id, options = {})
101
+ get "#{Repository.path repo}/check-runs/#{id}", options
102
+ end
103
+
104
+ # List annotations for a check run
105
+ #
106
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
107
+ # @param id [Integer] The ID of the check run
108
+ # @return [Array<Sawyer::Resource>] An array of hashes representing check run annotations
109
+ # @see https://developer.github.com/v3/checks/runs/#list-annotations-for-a-check-run
110
+ # @example List annotations for a check run
111
+ # annotations = @client.check_run_annotations("octocat/Hello-World", 51295429)
112
+ # annotations.count # => 1
113
+ # annotations[0].path # => "README.md"
114
+ # annotations[0].message # => "Looks good!"
115
+ def check_run_annotations(repo, id, options = {})
116
+ paginate "#{Repository.path repo}/check-runs/#{id}/annotations", options
117
+ end
118
+
119
+ # Methods for Check Suites
120
+ #
121
+ # @see https://developer.github.com/v3/checks/suites/
122
+
123
+ # Get a single check suite
124
+ #
125
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
126
+ # @param id [Integer] The ID of the check suite
127
+ # @return [Sawyer::Resource] A hash representing the check suite
128
+ # @see https://developer.github.com/v3/checks/suites/#get-a-single-check-suite
129
+ def check_suite(repo, id, options = {})
130
+ get "#{Repository.path repo}/check-suites/#{id}", options
131
+ end
132
+
133
+ # List check suites for a specific ref
134
+ #
135
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
136
+ # @param ref [String] A SHA, branch name, or tag name
137
+ # @param options [Hash] A set of optional filters
138
+ # @option options [Integer] :app_id Filters check suites by GitHub App <tt>id</tt>
139
+ # @option options [String] :check_name Filters checks suites by the <tt>name</tt> of the check run
140
+ # @return [Sawyer::Resource] A hash representing a collection of check suites
141
+ # @see https://developer.github.com/v3/checks/suites/#list-check-suites-for-a-specific-ref
142
+ # @example List check suites for a specific ref
143
+ # result = @client.check_suites_for_ref("octocat/Hello-World", "7638417db6d59f3c431d3e1f261cc637155684cd", app_id: 76765)
144
+ # result.total_count # => 1
145
+ # result.check_suites.count # => 1
146
+ # result.check_suites[0].id # => 50440400
147
+ # result.check_suites[0].app.id # => 76765
148
+ def check_suites_for_ref(repo, ref, options = {})
149
+ paginate "#{Repository.path repo}/commits/#{ref}/check-suites", options do |data, last_response|
150
+ data.check_suites.concat last_response.data.check_suites
151
+ data.total_count += last_response.data.total_count
152
+ end
153
+ end
154
+ alias list_check_suites_for_ref check_suites_for_ref
155
+
156
+ # Set preferences for check suites on a repository
157
+ #
158
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
159
+ # @param options [Hash] Preferences to set
160
+ # @return [Sawyer::Resource] A hash representing the repository's check suite preferences
161
+ # @see https://developer.github.com/v3/checks/suites/#set-preferences-for-check-suites-on-a-repository
162
+ # @example Set preferences for check suites on a repository
163
+ # result = @client.set_check_suite_preferences("octocat/Hello-World", auto_trigger_checks: [{ app_id: 76765, setting: false }])
164
+ # result.preferences.auto_trigger_checks.count # => 1
165
+ # result.preferences.auto_trigger_checks[0].app_id # => 76765
166
+ # result.preferences.auto_trigger_checks[0].setting # => false
167
+ # result.repository.full_name # => "octocat/Hello-World"
168
+ def set_check_suite_preferences(repo, options = {})
169
+ patch "#{Repository.path repo}/check-suites/preferences", options
170
+ end
171
+
172
+ # Create a check suite
173
+ #
174
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
175
+ # @param head_sha [String] The SHA of the commit to check
176
+ # @return [Sawyer::Resource] A hash representing the new check suite
177
+ # @see https://developer.github.com/v3/checks/suites/#create-a-check-suite
178
+ # @example Create a check suite
179
+ # check_suite = @client.create_check_suite("octocat/Hello-World", "7638417db6d59f3c431d3e1f261cc637155684cd")
180
+ # check_suite.head_sha # => "7638417db6d59f3c431d3e1f261cc637155684cd"
181
+ # check_suite.status # => "queued"
182
+ def create_check_suite(repo, head_sha, options = {})
183
+ options[:head_sha] = head_sha
184
+
185
+ post "#{Repository.path repo}/check-suites", options
186
+ end
187
+
188
+ # Rerequest check suite
189
+ #
190
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
191
+ # @param id [Integer] The ID of the check suite
192
+ # @return [Boolean] True if successful, raises an error otherwise
193
+ # @see https://developer.github.com/v3/checks/suites/#rerequest-check-suite
194
+ def rerequest_check_suite(repo, id, options = {})
195
+ post "#{Repository.path repo}/check-suites/#{id}/rerequest", options
196
+ true
197
+ end
198
+ end
199
+ end
200
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the Branches for HEAD API
6
+ #
7
+ # @see https://developer.github.com/v3/repos/commits/
8
+ module CommitBranches
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
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the Commit Comments API
5
6
  #
6
7
  # @see https://developer.github.com/v3/repos/comments/
7
8
  module CommitComments
8
-
9
9
  # List all commit comments
10
10
  #
11
11
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -53,12 +53,12 @@ module Octokit
53
53
  # comment.path # => "README.md"
54
54
  # comment.line # => 10
55
55
  # comment.position # => 1
56
- def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options = {})
56
+ def create_commit_comment(repo, sha, body, path = nil, line = nil, position = nil, options = {})
57
57
  params = {
58
- :body => body,
59
- :path => path,
60
- :line => line,
61
- :position => position
58
+ body: body,
59
+ path: path,
60
+ line: line,
61
+ position: position
62
62
  }
63
63
  post "#{Repository.path repo}/commits/#{sha}/comments", options.merge(params)
64
64
  end
@@ -76,7 +76,7 @@ module Octokit
76
76
  # comment.body # => "Updated commit comment"
77
77
  def update_commit_comment(repo, id, body, options = {})
78
78
  params = {
79
- :body => body
79
+ body: body
80
80
  }
81
81
  patch "#{Repository.path repo}/comments/#{id}", options.merge(params)
82
82
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the Commit Pulls API
6
+ #
7
+ # @see https://developer.github.com/v3/repos/comments/
8
+ module CommitPulls
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
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
 
3
5
  module Octokit
4
6
  class Client
5
-
6
7
  # Methods for the Commits API
7
8
  #
8
9
  # @see https://developer.github.com/v3/repos/commits/
9
10
  module Commits
10
-
11
11
  # List commits
12
12
  #
13
13
  # @overload commits(repo, sha_or_branch, options = {})
@@ -23,12 +23,10 @@ module Octokit
23
23
  def commits(*args)
24
24
  arguments = Octokit::RepoArguments.new(args)
25
25
  sha_or_branch = arguments.pop
26
- if sha_or_branch
27
- arguments.options[:sha] = sha_or_branch
28
- end
26
+ arguments.options[:sha] = sha_or_branch if sha_or_branch
29
27
  paginate "#{Repository.new(arguments.repo).path}/commits", arguments.options
30
28
  end
31
- alias :list_commits :commits
29
+ alias list_commits commits
32
30
 
33
31
  # Get commits after a specified date
34
32
  #
@@ -48,13 +46,11 @@ module Octokit
48
46
  # Octokit.commits_since('octokit/octokit.rb', '2012-10-01')
49
47
  def commits_since(*args)
50
48
  arguments = Octokit::RepoArguments.new(args)
51
- date = parse_date(arguments.shift)
49
+ date = parse_date(arguments.shift)
52
50
  params = arguments.options
53
- params.merge!(:since => iso8601(date))
51
+ params.merge!(since: iso8601(date))
54
52
  sha_or_branch = arguments.pop
55
- if sha_or_branch
56
- params[:sha] = sha_or_branch
57
- end
53
+ params[:sha] = sha_or_branch if sha_or_branch
58
54
  commits(arguments.repo, params)
59
55
  end
60
56
 
@@ -74,13 +70,11 @@ module Octokit
74
70
  # Octokit.commits_before('octokit/octokit.rb', '2012-10-01')
75
71
  def commits_before(*args)
76
72
  arguments = Octokit::RepoArguments.new(args)
77
- date = parse_date(arguments.shift)
73
+ date = parse_date(arguments.shift)
78
74
  params = arguments.options
79
- params.merge!(:until => iso8601(date))
75
+ params.merge!(until: iso8601(date))
80
76
  sha_or_branch = arguments.pop
81
- if sha_or_branch
82
- params[:sha] = sha_or_branch
83
- end
77
+ params[:sha] = sha_or_branch if sha_or_branch
84
78
  commits(arguments.repo, params)
85
79
  end
86
80
 
@@ -100,14 +94,12 @@ module Octokit
100
94
  # Octokit.commits_on('octokit/octokit.rb', '2012-10-01')
101
95
  def commits_on(*args)
102
96
  arguments = Octokit::RepoArguments.new(args)
103
- date = parse_date(arguments.shift)
97
+ date = parse_date(arguments.shift)
104
98
  params = arguments.options
105
99
  end_date = date + 1
106
- params.merge!(:since => iso8601(date), :until => iso8601(end_date))
100
+ params.merge!(since: iso8601(date), until: iso8601(end_date))
107
101
  sha_or_branch = arguments.pop
108
- if sha_or_branch
109
- params[:sha] = sha_or_branch
110
- end
102
+ params[:sha] = sha_or_branch if sha_or_branch
111
103
  commits(arguments.repo, params)
112
104
  end
113
105
 
@@ -129,16 +121,16 @@ module Octokit
129
121
  # Octokit.commits_between('octokit/octokit.rb', '2012-10-01', '2012-11-01')
130
122
  def commits_between(*args)
131
123
  arguments = Octokit::RepoArguments.new(args)
132
- date = parse_date(arguments.shift)
133
- end_date = parse_date(arguments.shift)
134
- raise ArgumentError, "Start date #{date} does not precede #{end_date}" if date > end_date
124
+ date = parse_date(arguments.shift)
125
+ end_date = parse_date(arguments.shift)
126
+ if date > end_date
127
+ raise ArgumentError, "Start date #{date} does not precede #{end_date}"
128
+ end
135
129
 
136
130
  params = arguments.options
137
- params.merge!(:since => iso8601(date), :until => iso8601(end_date))
131
+ params.merge!(since: iso8601(date), until: iso8601(end_date))
138
132
  sha_or_branch = arguments.pop
139
- if sha_or_branch
140
- params[:sha] = sha_or_branch
141
- end
133
+ params[:sha] = sha_or_branch if sha_or_branch
142
134
  commits(arguments.repo, params)
143
135
  end
144
136
 
@@ -181,21 +173,26 @@ module Octokit
181
173
  # commit.tree.sha # => "827efc6d56897b048c772eb4087f854f46256132"
182
174
  # commit.message # => "My commit message"
183
175
  # commit.committer # => { "name" => "Wynn Netherland", "email" => "wynn@github.com", ... }
184
- def create_commit(repo, message, tree, parents=nil, options = {})
185
- params = { :message => message, :tree => tree }
176
+ def create_commit(repo, message, tree, parents = nil, options = {})
177
+ params = { message: message, tree: tree }
186
178
  params[:parents] = [parents].flatten if parents
187
179
  post "#{Repository.path repo}/git/commits", options.merge(params)
188
180
  end
189
181
 
190
182
  # Compare two commits
191
183
  #
184
+ # When using auto_pagination, commits from all pages will be concatenated
185
+ # into the <tt>commits</tt> attribute of the first page's response.
186
+ #
192
187
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
193
188
  # @param start [String] The sha of the starting commit
194
189
  # @param endd [String] The sha of the ending commit
195
190
  # @return [Sawyer::Resource] A hash representing the comparison
196
191
  # @see https://developer.github.com/v3/repos/commits/#compare-two-commits
197
192
  def compare(repo, start, endd, options = {})
198
- get "#{Repository.path repo}/compare/#{start}...#{endd}", options
193
+ paginate "#{Repository.path repo}/compare/#{start}...#{endd}", options do |data, last_response|
194
+ data.commits.concat last_response.data.commits
195
+ end
199
196
  end
200
197
 
201
198
  # Merge a branch or sha
@@ -208,8 +205,8 @@ module Octokit
208
205
  # @see https://developer.github.com/v3/repos/merging/#perform-a-merge
209
206
  def merge(repo, base, head, options = {})
210
207
  params = {
211
- :base => base,
212
- :head => head
208
+ base: base,
209
+ head: head
213
210
  }.merge(options)
214
211
  post "#{Repository.path repo}/merges", params
215
212
  end
@@ -220,7 +217,7 @@ module Octokit
220
217
  if date.respond_to?(:iso8601)
221
218
  date.iso8601
222
219
  else
223
- date.strftime("%Y-%m-%dT%H:%M:%S%Z")
220
+ date.strftime('%Y-%m-%dT%H:%M:%S%Z')
224
221
  end
225
222
  end
226
223
 
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the Community Profile API
6
+ #
7
+ # @see https://developer.github.com/v3/repos/community/
8
+ module CommunityProfile
9
+ # Get community profile metrics for a repository
10
+ #
11
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
12
+ # @return [Sawyer::Resource] Community profile metrics
13
+ # @see https://developer.github.com/v3/repos/community/#retrieve-community-profile-metrics
14
+ # @example Get community profile metrics for octokit/octokit.rb
15
+ # @client.community_profile('octokit/octokit.rb')
16
+ def community_profile(repo, options = {})
17
+ get "#{Repository.path repo}/community/profile", options
18
+ end
19
+ end
20
+ end
21
+ end