octokit 4.6.0 → 4.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +14 -13
  3. data/LICENSE.md +1 -1
  4. data/README.md +141 -60
  5. data/lib/ext/sawyer/relation.rb +10 -0
  6. data/lib/octokit/authentication.rb +10 -11
  7. data/lib/octokit/client/actions_secrets.rb +58 -0
  8. data/lib/octokit/client/actions_workflow_runs.rb +105 -0
  9. data/lib/octokit/client/actions_workflows.rb +43 -0
  10. data/lib/octokit/client/apps.rb +222 -0
  11. data/lib/octokit/client/authorizations.rb +12 -74
  12. data/lib/octokit/client/checks.rb +191 -0
  13. data/lib/octokit/client/commit_branches.rb +20 -0
  14. data/lib/octokit/client/commit_pulls.rb +20 -0
  15. data/lib/octokit/client/community_profile.rb +22 -0
  16. data/lib/octokit/client/contents.rb +6 -0
  17. data/lib/octokit/client/deployments.rb +20 -0
  18. data/lib/octokit/client/events.rb +1 -0
  19. data/lib/octokit/client/gists.rb +3 -2
  20. data/lib/octokit/client/issues.rb +48 -1
  21. data/lib/octokit/client/labels.rb +7 -7
  22. data/lib/octokit/client/licenses.rb +1 -1
  23. data/lib/octokit/client/marketplace.rb +56 -0
  24. data/lib/octokit/client/notifications.rb +0 -4
  25. data/lib/octokit/client/oauth_applications.rb +122 -0
  26. data/lib/octokit/client/organizations.rb +149 -16
  27. data/lib/octokit/client/projects.rb +7 -7
  28. data/lib/octokit/client/pull_requests.rb +7 -5
  29. data/lib/octokit/client/rate_limit.rb +2 -2
  30. data/lib/octokit/client/refs.rb +19 -3
  31. data/lib/octokit/client/releases.rb +1 -0
  32. data/lib/octokit/client/repositories.rb +169 -8
  33. data/lib/octokit/client/repository_invitations.rb +1 -8
  34. data/lib/octokit/client/reviews.rb +227 -0
  35. data/lib/octokit/client/search.rb +24 -9
  36. data/lib/octokit/client/source_import.rb +1 -1
  37. data/lib/octokit/client/stats.rb +2 -0
  38. data/lib/octokit/client/statuses.rb +2 -2
  39. data/lib/octokit/client/users.rb +88 -1
  40. data/lib/octokit/client.rb +41 -9
  41. data/lib/octokit/configurable.rb +10 -2
  42. data/lib/octokit/connection.rb +19 -4
  43. data/lib/octokit/default.rb +17 -1
  44. data/lib/octokit/enterprise_admin_client/admin_stats.rb +1 -1
  45. data/lib/octokit/enterprise_admin_client/license.rb +1 -1
  46. data/lib/octokit/enterprise_admin_client/orgs.rb +2 -2
  47. data/lib/octokit/enterprise_admin_client/search_indexing.rb +1 -1
  48. data/lib/octokit/enterprise_admin_client/users.rb +12 -12
  49. data/lib/octokit/enterprise_management_console_client/management_console.rb +1 -1
  50. data/lib/octokit/enterprise_management_console_client.rb +1 -1
  51. data/lib/octokit/error.rb +74 -4
  52. data/lib/octokit/gist.rb +1 -1
  53. data/lib/octokit/middleware/follow_redirects.rb +2 -2
  54. data/lib/octokit/preview.rb +14 -3
  55. data/lib/octokit/rate_limit.rb +4 -4
  56. data/lib/octokit/repository.rb +10 -8
  57. data/lib/octokit/response/feed_parser.rb +0 -2
  58. data/lib/octokit/response/raise_error.rb +0 -2
  59. data/lib/octokit/version.rb +1 -1
  60. data/octokit.gemspec +2 -1
  61. metadata +39 -9
@@ -10,7 +10,7 @@ module Octokit
10
10
  #
11
11
  # @see https://developer.github.com/v3/repos/#get
12
12
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
13
- # @return [Sawyer::Resource] if a repository exists, false otherwise
13
+ # @return [Boolean]
14
14
  def repository?(repo, options = {})
15
15
  !!repository(repo, options)
16
16
  rescue Octokit::InvalidRepository
@@ -32,7 +32,7 @@ module Octokit
32
32
 
33
33
  # Edit a repository
34
34
  #
35
- # @see https://developer.github.com/v3/repos/#edit
35
+ # @see https://developer.github.com/v3/repos/#update-a-repository
36
36
  # @param repo [String, Hash, Repository] A GitHub repository
37
37
  # @param options [Hash] Repository information to update
38
38
  # @option options [String] :name Name of the repo
@@ -41,11 +41,15 @@ module Octokit
41
41
  # @option options [String] :private `true` makes the repository private, and `false` makes it public.
42
42
  # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
43
43
  # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
44
+ # @option options [Boolean] :is_template `true` makes the repository a template, `false` makes it not a template.
44
45
  # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
45
46
  # @option options [String] :default_branch Update the default branch for this repository.
46
47
  # @return [Sawyer::Resource] Repository information
47
48
  def edit_repository(repo, options = {})
48
49
  repo = Repository.new(repo)
50
+ if options.include? :is_template
51
+ options = ensure_api_media_type(:template_repositories, options)
52
+ end
49
53
  options[:name] ||= repo.name
50
54
  patch "repos/#{repo}", options
51
55
  end
@@ -144,6 +148,7 @@ module Octokit
144
148
  # @option options [String] :private `true` makes the repository private, and `false` makes it public.
145
149
  # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
146
150
  # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
151
+ # @option options [Boolean] :is_template `true` makes this repo available as a template repository, `false` to prevent it.
147
152
  # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
148
153
  # @option options [String] :organization Short name for the org under which to create the repo.
149
154
  # @option options [Integer] :team_id The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization.
@@ -155,6 +160,9 @@ module Octokit
155
160
  opts = options.dup
156
161
  organization = opts.delete :organization
157
162
  opts.merge! :name => name
163
+ if opts.include? :is_template
164
+ opts = ensure_api_media_type(:template_repositories, opts)
165
+ end
158
166
 
159
167
  if organization.nil?
160
168
  post 'user/repos', opts
@@ -177,6 +185,37 @@ module Octokit
177
185
  end
178
186
  alias :delete_repo :delete_repository
179
187
 
188
+ # Transfer repository
189
+ #
190
+ # Transfer a repository owned by your organization
191
+ #
192
+ # @see https://developer.github.com/v3/repos/#transfer-a-repository
193
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
194
+ # @param new_owner [String] The username or organization name the repository will be transferred to.
195
+ # @param options [Array<Integer>] :team_ids ID of the team or teams to add to the repository. Teams can only be added to organization-owned repositories.
196
+ # @return [Sawyer::Resource] Repository info for the transferred repository
197
+ def transfer_repository(repo, new_owner, options = {})
198
+ options = ensure_api_media_type(:transfer_repository, options)
199
+ post "#{Repository.path repo}/transfer", options.merge({ new_owner: new_owner })
200
+ end
201
+ alias :transfer_repo :transfer_repository
202
+
203
+ # Create a repository for a user or organization generated from a template repository
204
+ #
205
+ # @param repo [Integer, String, Hash, Repository] A GitHub template repository
206
+ # @param name [String] Name of the new repo
207
+ # @option options [String] :owner Organization or user who the new repository will belong to.
208
+ # @option options [String] :description Description of the repo
209
+ # @option options [String] :private `true` makes the repository private, and `false` makes it public.
210
+ # @option options [Boolean] :include_all_branches `true` copies all branches from the template repository, `false` (default) makes it only copy the master branch.
211
+ # @return [Sawyer::Resource] Repository info for the new repository
212
+ def create_repository_from_template(repo, name, options = {})
213
+ options.merge! :name => name
214
+ options = ensure_api_media_type(:template_repositories, options)
215
+ post "#{Repository.path repo}/generate", options
216
+ end
217
+ alias :create_repo_from_template :create_repository_from_template
218
+
180
219
  # Hide a public repository
181
220
  #
182
221
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -277,6 +316,9 @@ module Octokit
277
316
  # Requires authenticated client for private repos.
278
317
  #
279
318
  # @param repo [Integer, String, Hash, Repository] A GitHub repository.
319
+ # @option options [String] :affiliation Filters the return array by affiliation.
320
+ # Can be one of: <tt>outside</tt>, <tt>direct</tt>, or <tt>all</tt>.
321
+ # If not specified, defaults to <tt>all</tt>
280
322
  # @return [Array<Sawyer::Resource>] Array of hashes representing collaborating users.
281
323
  # @see https://developer.github.com/v3/repos/collaborators/#list-collaborators
282
324
  # @example
@@ -346,6 +388,18 @@ module Octokit
346
388
  boolean_from_response :get, "#{Repository.path repo}/collaborators/#{collaborator}", options
347
389
  end
348
390
 
391
+ # Get a user's permission level for a repo.
392
+ #
393
+ # Requires authenticated client
394
+ #
395
+ # @return [Sawyer::Resource] Hash representing the user's permission level for the given repository
396
+ # @see https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
397
+ # @example
398
+ # @client.permission_level('octokit/octokit.rb', 'lizzhale')
399
+ def permission_level(repo, collaborator, options={})
400
+ get "#{Repository.path repo}/collaborators/#{collaborator}/permission", options
401
+ end
402
+
349
403
  # List teams for a repo
350
404
  #
351
405
  # Requires authenticated client that is an owner or collaborator of the repo.
@@ -365,6 +419,39 @@ module Octokit
365
419
  alias :repo_teams :repository_teams
366
420
  alias :teams :repository_teams
367
421
 
422
+ # List all topics for a repository
423
+ #
424
+ # Requires authenticated client for private repos.
425
+ #
426
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
427
+ # @return [Sawyer::Resource] representing the topics for given repo
428
+ # @see https://developer.github.com/v3/repos/#list-all-topics-for-a-repository
429
+ # @example List topics for octokit/octokit.rb
430
+ # Octokit.topics('octokit/octokit.rb')
431
+ # @example List topics for octokit/octokit.rb
432
+ # client.topics('octokit/octokit.rb')
433
+ def topics(repo, options = {})
434
+ opts = ensure_api_media_type(:topics, options)
435
+ paginate "#{Repository.path repo}/topics", opts
436
+ end
437
+
438
+ # Replace all topics for a repository
439
+ #
440
+ # Requires authenticated client.
441
+ #
442
+ # @param repo [Integer, String, Repository, Hash] A Github repository
443
+ # @param names [Array] An array of topics to add to the repository.
444
+ # @return [Sawyer::Resource] representing the replaced topics for given repo
445
+ # @see https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository
446
+ # @example Replace topics for octokit/octokit.rb
447
+ # client.replace_all_topics('octokit/octokit.rb', ['octocat', 'atom', 'electron', 'API'])
448
+ # @example Clear all topics for octokit/octokit.rb
449
+ # client.replace_all_topics('octokit/octokit.rb', [])
450
+ def replace_all_topics(repo, names, options = {})
451
+ opts = ensure_api_media_type(:topics, options)
452
+ put "#{Repository.path repo}/topics", opts.merge(:names => names)
453
+ end
454
+
368
455
  # List contributors to a repo
369
456
  #
370
457
  # Requires authenticated client for private repos.
@@ -499,14 +586,14 @@ module Octokit
499
586
  #
500
587
  # @param repo [Integer, String, Hash, Repository] A GitHub repository.
501
588
  # @param branch [String] Branch name
502
- # @option options [Hash] :required_status_checks If not null, the following keys are required:
503
- # <tt>:include_admins [boolean] Enforce required status checks for repository administrators.</tt>
504
- # <tt>:strict [boolean] Require branches to be up to date before merging.</tt>
505
- # <tt>:contexts [Array] The list of status checks to require in order to merge into this branch</tt>
589
+ # @option options [Hash] :required_status_checks If not null, the following keys are required:
590
+ # <tt>:enforce_admins [boolean] Enforce required status checks for repository administrators.</tt>
591
+ # <tt>:strict [boolean] Require branches to be up to date before merging.</tt>
592
+ # <tt>:contexts [Array] The list of status checks to require in order to merge into this branch</tt>
506
593
  #
507
594
  # @option options [Hash] :restrictions If not null, the following keys are required:
508
- # <tt>:users [Array] The list of user logins with push access</tt>
509
- # <tt>:teams [Array] The list of team slugs with push access</tt>.
595
+ # <tt>:users [Array] The list of user logins with push access</tt>
596
+ # <tt>:teams [Array] The list of team slugs with push access</tt>.
510
597
  #
511
598
  # Teams and users restrictions are only available for organization-owned repositories.
512
599
  # @return [Sawyer::Resource] The protected branch
@@ -553,6 +640,24 @@ module Octokit
553
640
  boolean_from_response :delete, "#{Repository.path repo}/branches/#{branch}/protection", opts
554
641
  end
555
642
 
643
+ # Rename a single branch from a repository
644
+ #
645
+ # Requires authenticated client
646
+ #
647
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
648
+ # @param branch [String] Current branch name
649
+ # @param new_name [String] New branch name
650
+ # @return [Sawyer::Resource] The renamed branch
651
+ # @see https://developer.github.com/v3/repos/#rename-a-branch
652
+ # @example
653
+ # @client.rename_branch('octokit/octokit.rb', 'master', 'main')
654
+ def rename_branch(repo, branch, new_name, options = {})
655
+ params = {
656
+ new_name: new_name,
657
+ }
658
+ post "#{Repository.path repo}/branches/#{branch}/rename", params.merge(options)
659
+ end
660
+
556
661
  # List users available for assigning to issues.
557
662
  #
558
663
  # Requires authenticated client for private repos.
@@ -633,6 +738,62 @@ module Octokit
633
738
  def delete_subscription(repo, options = {})
634
739
  boolean_from_response :delete, "#{Repository.path repo}/subscription", options
635
740
  end
741
+
742
+ # Create a repository dispatch event
743
+ #
744
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
745
+ # @param event_type [String] A custom webhook event name.
746
+ # @option options [Hash] :client_payload payload with extra information
747
+ # about the webhook event that your action or worklow may use.
748
+ #
749
+ # @return [Boolean] True if event was dispatched, false otherwise.
750
+ # @see https://developer.github.com/v3/repos/#create-a-repository-dispatch-event
751
+ def dispatch_event(repo, event_type, options = {})
752
+ boolean_from_response :post, "#{Repository.path repo}/dispatches", options.merge({ event_type: event_type })
753
+ end
754
+
755
+ # Check to see if vulnerability alerts are enabled for a repository
756
+ #
757
+ # The authenticated user must have admin access to the repository.
758
+ #
759
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
760
+ # @return [Boolean] True if vulnerability alerts are enabled, false otherwise.
761
+ # @see https://docs.github.com/en/rest/reference/repos#check-if-vulnerability-alerts-are-enabled-for-a-repository
762
+ #
763
+ # @example
764
+ # @client.vulnerability_alerts_enabled?("octokit/octokit.rb")
765
+ def vulnerability_alerts_enabled?(repo, options = {})
766
+ opts = ensure_api_media_type(:vulnerability_alerts, options)
767
+ boolean_from_response(:get, "#{Repository.path repo}/vulnerability-alerts", opts)
768
+ end
769
+
770
+ # Enable vulnerability alerts for a repository
771
+ #
772
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
773
+ # @param options [Hash]
774
+ #
775
+ # @return [Boolean] True if vulnerability alerts enabled, false otherwise.
776
+ # @see https://docs.github.com/en/rest/reference/repos#enable-vulnerability-alerts
777
+ # @example Enable vulnerability alerts for a repository
778
+ # @client.enable_vulnerability_alerts("octokit/octokit.rb")
779
+ def enable_vulnerability_alerts(repo, options = {})
780
+ opts = ensure_api_media_type(:vulnerability_alerts, options)
781
+ boolean_from_response(:put, "#{Repository.path repo}/vulnerability-alerts", opts)
782
+ end
783
+
784
+ # Disable vulnerability alerts for a repository
785
+ #
786
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
787
+ # @param options [Hash]
788
+ #
789
+ # @return [Boolean] True if vulnerability alerts disabled, false otherwise.
790
+ # @see https://docs.github.com/en/rest/reference/repos#disable-vulnerability-alerts
791
+ # @example Disable vulnerability alerts for a repository
792
+ # @client.disable_vulnerability_alerts("octokit/octokit.rb")
793
+ def disable_vulnerability_alerts(repo, options = {})
794
+ opts = ensure_api_media_type(:vulnerability_alerts, options)
795
+ boolean_from_response(:delete, "#{Repository.path repo}/vulnerability-alerts", opts)
796
+ end
636
797
  end
637
798
  end
638
799
  end
@@ -13,9 +13,8 @@ module Octokit
13
13
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
14
14
  # @param user [String] User GitHub username to add
15
15
  # @return [Sawyer::Resource] The repository invitation
16
- # @see https://developer.github.com/v3/repos/invitations/#invite-a-user-to-a-repository
16
+ # @see https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
17
17
  def invite_user_to_repository(repo, user, options = {})
18
- options = ensure_api_media_type(:repository_invitations, options)
19
18
  put "#{Repository.path repo}/collaborators/#{user}", options
20
19
  end
21
20
  alias invite_user_to_repo invite_user_to_repository
@@ -28,7 +27,6 @@ module Octokit
28
27
  # @return [Array<Sawyer::Resource>] A list of invitations
29
28
  # @see https://developer.github.com/v3/repos/invitations/#list-invitations-for-a-repository
30
29
  def repository_invitations(repo, options = {})
31
- options = ensure_api_media_type(:repository_invitations, options)
32
30
  paginate "#{Repository.path repo}/invitations", options
33
31
  end
34
32
  alias repo_invitations repository_invitations
@@ -42,7 +40,6 @@ module Octokit
42
40
  # @return [Boolean] True if the invitation was successfully deleted
43
41
  # @see https://developer.github.com/v3/repos/invitations/#delete-a-repository-invitation
44
42
  def delete_repository_invitation(repo, invitation_id, options = {})
45
- options = ensure_api_media_type(:repository_invitations, options)
46
43
  boolean_from_response :delete, "#{Repository.path repo}/invitations/#{invitation_id}", options
47
44
  end
48
45
  alias delete_repo_invitation delete_repository_invitation
@@ -56,7 +53,6 @@ module Octokit
56
53
  # @return [Sawyer::Resource] The updated repository invitation
57
54
  # @see https://developer.github.com/v3/repos/invitations/#update-a-repository-invitation
58
55
  def update_repository_invitation(repo, invitation_id, options = {})
59
- options = ensure_api_media_type(:repository_invitations, options)
60
56
  patch "#{Repository.path repo}/invitations/#{invitation_id}", options
61
57
  end
62
58
  alias update_repo_invitation update_repository_invitation
@@ -68,7 +64,6 @@ module Octokit
68
64
  # @return [Array<Sawyer::Resource>] The users repository invitations
69
65
  # @see https://developer.github.com/v3/repos/invitations/#list-a-users-repository-invitations
70
66
  def user_repository_invitations(options = {})
71
- options = ensure_api_media_type(:repository_invitations, options)
72
67
  paginate "/user/repository_invitations", options
73
68
  end
74
69
  alias user_repo_invitations user_repository_invitations
@@ -81,7 +76,6 @@ module Octokit
81
76
  # @return [Boolean] True if the acceptance of the invitation was successful
82
77
  # @see https://developer.github.com/v3/repos/invitations/#accept-a-repository-invitation
83
78
  def accept_repository_invitation(invitation_id, options = {})
84
- options = ensure_api_media_type(:repository_invitations, options)
85
79
  patch "/user/repository_invitations/#{invitation_id}", options
86
80
  end
87
81
  alias accept_repo_invitation accept_repository_invitation
@@ -94,7 +88,6 @@ module Octokit
94
88
  # @return [Boolean] True if the acceptance of the invitation was successful
95
89
  # @see https://developer.github.com/v3/repos/invitations/#decline-a-repository-invitation
96
90
  def decline_repository_invitation(invitation_id, options = {})
97
- options = ensure_api_media_type(:repository_invitations, options)
98
91
  boolean_from_response :delete, "/user/repository_invitations/#{invitation_id}", options
99
92
  end
100
93
  alias decline_invitation decline_repository_invitation
@@ -0,0 +1,227 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Reviews API
5
+ #
6
+ # @see https://developer.github.com/v3/pulls/reviews/
7
+ module Reviews
8
+
9
+ # List reviews on a pull request
10
+ #
11
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
12
+ # @param number [Integer] Number ID of the pull request
13
+ # @see https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request
14
+ #
15
+ # @example
16
+ # @client.pull_request_reviews('octokit/octokit.rb', 2)
17
+ #
18
+ # @return [Array<Sawyer::Resource>] Array of Hashes representing the reviews
19
+ def pull_request_reviews(repo, number, options = {})
20
+ paginate "#{Repository.path repo}/pulls/#{number}/reviews", options
21
+ end
22
+
23
+ # Get a single review
24
+ #
25
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
26
+ # @param number [Integer] Number ID of the pull request
27
+ # @param review [Integer] The id of the review
28
+ # @see https://developer.github.com/v3/pulls/reviews/#get-a-single-review
29
+ #
30
+ # @example
31
+ # @client.pull_request_review('octokit/octokit.rb', 825, 6505518)
32
+ #
33
+ # @return [Sawyer::Resource] Hash representing the review
34
+ def pull_request_review(repo, number, review, options = {})
35
+ get "#{Repository.path repo}/pulls/#{number}/reviews/#{review}", options
36
+ end
37
+
38
+ # Delete a pending review
39
+ #
40
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
41
+ # @param number [Integer] Number ID of the pull request
42
+ # @param review [Integer] The id of the review
43
+ # @see https://developer.github.com/v3/pulls/reviews/#delete-a-pending-review
44
+ #
45
+ # @example
46
+ # @client.delete_pull_request_review('octokit/octokit.rb', 825, 6505518)
47
+ #
48
+ # @return [Sawyer::Resource] Hash representing the deleted review
49
+ def delete_pull_request_review(repo, number, review, options = {})
50
+ delete "#{Repository.path repo}/pulls/#{number}/reviews/#{review}", options
51
+ end
52
+
53
+ # Get comments for a single review
54
+ #
55
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
56
+ # @param number [Integer] Number ID of the pull request
57
+ # @param review [Integer] The id of the review
58
+ # @see https://developer.github.com/v3/pulls/reviews/#get-comments-for-a-single-review
59
+ #
60
+ # @example
61
+ # @client.pull_request_review_comments('octokit/octokit.rb', 825, 6505518)
62
+ #
63
+ # @return [Array<Sawyer::Resource>] Array of Hashes representing the review comments
64
+ def pull_request_review_comments(repo, number, review, options = {})
65
+ paginate "#{Repository.path repo}/pulls/#{number}/reviews/#{review}/comments", options
66
+ end
67
+
68
+ # Create a pull request review
69
+ #
70
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
71
+ # @param number [Integer] Number ID of the pull request
72
+ # @param options [Hash] Method options
73
+ # @option options [String] :event The review action (event) to perform;
74
+ # can be one of APPROVE, REQUEST_CHANGES, or COMMENT.
75
+ # If left blank, the review is left PENDING.
76
+ # @option options [String] :body The body text of the pull request review
77
+ # @option options [Array<Hash>] :comments Comments part of the review
78
+ # @option comments [String] :path The path to the file being commented on
79
+ # @option comments [Integer] :position The position in the file to be commented on
80
+ # @option comments [String] :body Body of the comment
81
+ # @see https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
82
+ #
83
+ # @example
84
+ # comments = [
85
+ # { path: '.travis.yml', position: 10, body: 'ruby-head is under development that is not stable.' },
86
+ # { path: '.travis.yml', position: 32, body: 'ruby-head is also required in thervm section.' },
87
+ # ]
88
+ # options = { event: 'REQUEST_CHANGES', comments: comments }
89
+ # @client.create_pull_request_review('octokit/octokit.rb', 844, options)
90
+ #
91
+ # @return [Sawyer::Resource>] Hash respresenting the review
92
+ def create_pull_request_review(repo, number, options = {})
93
+ post "#{Repository.path repo}/pulls/#{number}/reviews", options
94
+ end
95
+
96
+ # Submit a pull request review
97
+ #
98
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
99
+ # @param number [Integer] Number ID of the pull request
100
+ # @param review [Integer] The id of the review
101
+ # @param event [String] The review action (event) to perform; can be one of
102
+ # APPROVE, REQUEST_CHANGES, or COMMENT.
103
+ # @param options [Hash] Method options
104
+ # @option options [String] :body The body text of the pull request review
105
+ # @see https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review
106
+ #
107
+ # @example
108
+ # @client.submit_pull_request_review('octokit/octokit.rb', 825, 6505518,
109
+ # 'APPROVE', body: 'LGTM!')
110
+ #
111
+ # @return [Sawyer::Resource] Hash respresenting the review
112
+ def submit_pull_request_review(repo, number, review, event, options = {})
113
+ options = options.merge(event: event)
114
+ post "#{Repository.path repo}/pulls/#{number}/reviews/#{review}/events", options
115
+ end
116
+
117
+ # Dismiss a pull request review
118
+ #
119
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
120
+ # @param number [Integer] Number ID of the pull request
121
+ # @param review [Integer] The id of the review
122
+ # @param message [String] The message for the pull request review dismissal
123
+ # @see https://developer.github.com/v3/pulls/reviews/#dismiss-a-pull-request-review
124
+ #
125
+ # @example
126
+ # @client.dismiss_pull_request_review('octokit/octokit.rb', 825, 6505518, 'The message.')
127
+ #
128
+ # @return [Sawyer::Resource] Hash representing the dismissed review
129
+ def dismiss_pull_request_review(repo, number, review, message, options = {})
130
+ options = options.merge(message: message)
131
+ put "#{Repository.path repo}/pulls/#{number}/reviews/#{review}/dismissals", options
132
+ end
133
+
134
+ # List review requests
135
+ #
136
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
137
+ # @param number [Integer] Number ID of the pull request
138
+ # @see https://developer.github.com/v3/pulls/review_requests/#list-review-requests
139
+ #
140
+ # @example
141
+ # @client.pull_request_review_requests('octokit/octokit.rb', 2)
142
+ #
143
+ # @return [Array<Sawyer::Resource>] Array of Hashes representing the review requests
144
+ def pull_request_review_requests(repo, number, options = {})
145
+ paginate "#{Repository.path repo}/pulls/#{number}/requested_reviewers", options
146
+ end
147
+
148
+ # Create a review request
149
+ #
150
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
151
+ # @param number [Integer] Number ID of the pull request
152
+ # @param reviewers [Hash] :reviewers [Array<String>] An array of user logins
153
+ # @param options [Hash] :team_reviewers [Array<String>] An array of team slugs
154
+ # @see https://developer.github.com/v3/pulls/review_requests/#create-a-review-request
155
+ #
156
+ # @example
157
+ # @client.request_pull_request_review('octokit/octokit.rb', 2, reviewers: ['soudy'])
158
+ #
159
+ # @return [Sawyer::Resource>] Hash respresenting the pull request
160
+ def request_pull_request_review(repo, number, reviewers = {}, options = {})
161
+ # TODO(5.0): remove deprecated behavior
162
+ if reviewers.is_a?(Array)
163
+ octokit_warn(
164
+ "Deprecated: Octokit::Client#request_pull_request_review "\
165
+ "no longer takes a separate :reviewers argument.\n" \
166
+ "Please update your call to pass :reviewers and :team_reviewers as part of the options hash."
167
+ )
168
+ options = options.merge(reviewers: reviewers)
169
+ else
170
+ options = options.merge(reviewers)
171
+ end
172
+
173
+ post "#{Repository.path repo}/pulls/#{number}/requested_reviewers", options
174
+ end
175
+
176
+ # Delete a review request
177
+ #
178
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
179
+ # @param id [Integer] The id of the pull request
180
+ # @param reviewers [Hash] :reviewers [Array] An array of user logins
181
+ # @param options [Hash] :team_reviewers [Array] An array of team slugs
182
+ #
183
+ # @see https://developer.github.com/v3/pulls/review_requests/#delete-a-review-request
184
+ #
185
+ # @example
186
+ # options = {
187
+ # "reviewers" => [ "octocat", "hubot", "other_user" ],
188
+ # "team_reviewers" => [ "justice-league" ]
189
+ # }
190
+ # @client.delete_pull_request_review_request('octokit/octokit.rb', 2, options)
191
+ #
192
+ # @return [Sawyer::Resource>] Hash representing the pull request
193
+ def delete_pull_request_review_request(repo, id, reviewers={}, options = {})
194
+ # TODO(5.0): remove deprecated behavior
195
+ if !reviewers.empty? && !options.empty?
196
+ octokit_warn(
197
+ "Deprecated: Octokit::Client#delete_pull_request_review_request "\
198
+ "no longer takes a separate :reviewers argument.\n" \
199
+ "Please update your call to pass :reviewers and :team_reviewers as part of the options hash."
200
+ )
201
+ end
202
+ # For backwards compatibility, this endpoint can be called with a separate reviewers hash.
203
+ # If not called with a separate hash, then 'reviewers' is, in fact, 'options'.
204
+ options = options.merge(reviewers)
205
+ delete "#{Repository.path repo}/pulls/#{id}/requested_reviewers", options
206
+ end
207
+
208
+ # Update a review request comment
209
+ #
210
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
211
+ # @param number [Integer] Number ID of the pull request
212
+ # @param review [Integer] The id of the review
213
+ # @param body [String] body text of the pull request review.
214
+ # @param options [Hash] Method options
215
+ # @see https://developer.github.com/v3/pulls/reviews/#update-a-pull-request-review
216
+ #
217
+ # @example
218
+ # @client.update_pull_request_review('octokit/octokit.rb', 825, 6505518, 'This is close to perfect! Please address the suggested inline change. And add more about this.')
219
+ #
220
+ # @return [Sawyer::Resource] Hash representing the review comment
221
+ def update_pull_request_review(repo, number, review, body, options = {})
222
+ options[:body] = body
223
+ put "#{Repository.path repo}/pulls/#{number}/reviews/#{review}", options
224
+ end
225
+ end
226
+ end
227
+ end
@@ -12,24 +12,39 @@ module Octokit
12
12
  # @param options [Hash] Sort and pagination options
13
13
  # @option options [String] :sort Sort field
14
14
  # @option options [String] :order Sort order (asc or desc)
15
- # @option options [Fixnum] :page Page of paginated results
16
- # @option options [Fixnum] :per_page Number of items per page
15
+ # @option options [Integer] :page Page of paginated results
16
+ # @option options [Integer] :per_page Number of items per page
17
17
  # @return [Sawyer::Resource] Search results object
18
18
  # @see https://developer.github.com/v3/search/#search-code
19
19
  def search_code(query, options = {})
20
20
  search "search/code", query, options
21
21
  end
22
22
 
23
+ # Search commits
24
+ #
25
+ # @param query [String] Search terms and qualifiers
26
+ # @param options [Hash] Sort and pagination options
27
+ # @option options [String] :sort Sort field
28
+ # @option options [String] :order Sort order (asc or desc)
29
+ # @option options [Integer] :page Page of paginated results
30
+ # @option options [Integer] :per_page Number of items per page
31
+ # @return [Sawyer::Resource] Search results object
32
+ # @see https://developer.github.com/v3/search/#search-commits
33
+ def search_commits(query, options = {})
34
+ options = ensure_api_media_type(:commit_search, options)
35
+ search "search/commits", query, options
36
+ end
37
+
23
38
  # Search issues
24
39
  #
25
40
  # @param query [String] Search term and qualifiers
26
41
  # @param options [Hash] Sort and pagination options
27
42
  # @option options [String] :sort Sort field
28
43
  # @option options [String] :order Sort order (asc or desc)
29
- # @option options [Fixnum] :page Page of paginated results
30
- # @option options [Fixnum] :per_page Number of items per page
44
+ # @option options [Integer] :page Page of paginated results
45
+ # @option options [Integer] :per_page Number of items per page
31
46
  # @return [Sawyer::Resource] Search results object
32
- # @see https://developer.github.com/v3/search/#search-issues
47
+ # @see https://developer.github.com/v3/search/#search-issues-and-pull-requests
33
48
  def search_issues(query, options = {})
34
49
  search "search/issues", query, options
35
50
  end
@@ -40,8 +55,8 @@ module Octokit
40
55
  # @param options [Hash] Sort and pagination options
41
56
  # @option options [String] :sort Sort field
42
57
  # @option options [String] :order Sort order (asc or desc)
43
- # @option options [Fixnum] :page Page of paginated results
44
- # @option options [Fixnum] :per_page Number of items per page
58
+ # @option options [Integer] :page Page of paginated results
59
+ # @option options [Integer] :per_page Number of items per page
45
60
  # @return [Sawyer::Resource] Search results object
46
61
  # @see https://developer.github.com/v3/search/#search-repositories
47
62
  def search_repositories(query, options = {})
@@ -55,8 +70,8 @@ module Octokit
55
70
  # @param options [Hash] Sort and pagination options
56
71
  # @option options [String] :sort Sort field
57
72
  # @option options [String] :order Sort order (asc or desc)
58
- # @option options [Fixnum] :page Page of paginated results
59
- # @option options [Fixnum] :per_page Number of items per page
73
+ # @option options [Integer] :page Page of paginated results
74
+ # @option options [Integer] :per_page Number of items per page
60
75
  # @return [Sawyer::Resource] Search results object
61
76
  # @see https://developer.github.com/v3/search/#search-users
62
77
  def search_users(query, options = {})
@@ -132,7 +132,7 @@ module Octokit
132
132
  #
133
133
  # @param repo [Integer, String, Hash, Repository] A GitHub repository.
134
134
  # @param options [Hash]
135
- # @option options [Fixnum] :page Page of paginated results
135
+ # @option options [Integer] :page Page of paginated results
136
136
  # @return [Array<Sawyer::Resource>] Array of hashes representing files over 100MB.
137
137
  # @see https://developer.github.com/v3/migration/source_imports/#get-large-files
138
138
  #
@@ -88,6 +88,7 @@ module Octokit
88
88
  # @return [Array<Sawyer::Resource> or nil] Stats in metric-specific format, or nil if not yet calculated.
89
89
  # @see https://developer.github.com/v3/repos/statistics/
90
90
  def get_stats(repo, metric, options = {})
91
+ options = options.dup
91
92
  if retry_timeout = options.delete(:retry_timeout)
92
93
  retry_wait = options.delete(:retry_wait) || 0.5
93
94
  timeout = Time.now + retry_timeout
@@ -95,6 +96,7 @@ module Octokit
95
96
  loop do
96
97
  data = get("#{Repository.path repo}/stats/#{metric}", options)
97
98
  return data if last_response.status == 200
99
+ return [] if last_response.status == 204
98
100
  return nil unless retry_timeout
99
101
  return nil if Time.now >= timeout
100
102
  sleep retry_wait if retry_wait
@@ -13,7 +13,7 @@ module Octokit
13
13
  # @return [Array<Sawyer::Resource>] A list of statuses
14
14
  # @see https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
15
15
  def statuses(repo, sha, options = {})
16
- get "#{Repository.path repo}/statuses/#{sha}", options
16
+ paginate "#{Repository.path repo}/statuses/#{sha}", options
17
17
  end
18
18
  alias :list_statuses :statuses
19
19
 
@@ -39,7 +39,7 @@ module Octokit
39
39
  # @return [Sawyer::Resource] A status
40
40
  # @see https://developer.github.com/v3/repos/statuses/#create-a-status
41
41
  def create_status(repo, sha, state, options = {})
42
- options.merge!(:state => state)
42
+ options = options.merge(:state => state)
43
43
  post "#{Repository.path repo}/statuses/#{sha}", options
44
44
  end
45
45
  end