octokit 4.6.2 → 6.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +14 -13
  3. data/LICENSE.md +1 -1
  4. data/README.md +239 -118
  5. data/Rakefile +12 -12
  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_artifacts.rb +71 -0
  10. data/lib/octokit/client/actions_secrets.rb +59 -0
  11. data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
  12. data/lib/octokit/client/actions_workflow_runs.rb +125 -0
  13. data/lib/octokit/client/actions_workflows.rb +68 -0
  14. data/lib/octokit/client/apps.rb +222 -0
  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/environments.rb +55 -0
  26. data/lib/octokit/client/events.rb +4 -4
  27. data/lib/octokit/client/feeds.rb +4 -5
  28. data/lib/octokit/client/gists.rb +7 -6
  29. data/lib/octokit/client/gitignore.rb +3 -3
  30. data/lib/octokit/client/hooks.rb +9 -19
  31. data/lib/octokit/client/issues.rb +60 -14
  32. data/lib/octokit/client/labels.rb +17 -17
  33. data/lib/octokit/client/legacy_search.rb +3 -3
  34. data/lib/octokit/client/licenses.rb +4 -7
  35. data/lib/octokit/client/markdown.rb +3 -3
  36. data/lib/octokit/client/marketplace.rb +56 -0
  37. data/lib/octokit/client/meta.rb +4 -5
  38. data/lib/octokit/client/milestones.rb +5 -5
  39. data/lib/octokit/client/notifications.rb +6 -10
  40. data/lib/octokit/client/oauth_applications.rb +116 -0
  41. data/lib/octokit/client/objects.rb +14 -14
  42. data/lib/octokit/client/organizations.rb +238 -61
  43. data/lib/octokit/client/pages.rb +5 -7
  44. data/lib/octokit/client/projects.rb +50 -70
  45. data/lib/octokit/client/pub_sub_hubbub.rb +16 -16
  46. data/lib/octokit/client/pull_requests.rb +58 -46
  47. data/lib/octokit/client/rate_limit.rb +11 -13
  48. data/lib/octokit/client/reactions.rb +6 -11
  49. data/lib/octokit/client/refs.rb +32 -19
  50. data/lib/octokit/client/releases.rb +14 -13
  51. data/lib/octokit/client/repositories.rb +195 -54
  52. data/lib/octokit/client/repository_invitations.rb +4 -11
  53. data/lib/octokit/client/reviews.rb +227 -0
  54. data/lib/octokit/client/say.rb +4 -5
  55. data/lib/octokit/client/search.rb +46 -17
  56. data/lib/octokit/client/service_status.rb +19 -9
  57. data/lib/octokit/client/source_import.rb +8 -13
  58. data/lib/octokit/client/stats.rb +12 -9
  59. data/lib/octokit/client/statuses.rb +6 -6
  60. data/lib/octokit/client/tokens.rb +31 -0
  61. data/lib/octokit/client/traffic.rb +6 -11
  62. data/lib/octokit/client/users.rb +106 -25
  63. data/lib/octokit/client.rb +66 -17
  64. data/lib/octokit/configurable.rb +42 -30
  65. data/lib/octokit/connection.rb +43 -21
  66. data/lib/octokit/default.rb +63 -34
  67. data/lib/octokit/enterprise_admin_client/admin_stats.rb +14 -15
  68. data/lib/octokit/enterprise_admin_client/license.rb +4 -5
  69. data/lib/octokit/enterprise_admin_client/orgs.rb +5 -6
  70. data/lib/octokit/enterprise_admin_client/search_indexing.rb +8 -9
  71. data/lib/octokit/enterprise_admin_client/users.rb +17 -16
  72. data/lib/octokit/enterprise_admin_client.rb +9 -3
  73. data/lib/octokit/enterprise_management_console_client/management_console.rb +33 -33
  74. data/lib/octokit/enterprise_management_console_client.rb +9 -3
  75. data/lib/octokit/error.rb +107 -26
  76. data/lib/octokit/gist.rb +4 -5
  77. data/lib/octokit/middleware/follow_redirects.rb +17 -13
  78. data/lib/octokit/organization.rb +3 -1
  79. data/lib/octokit/rate_limit.rb +11 -9
  80. data/lib/octokit/repo_arguments.rb +2 -3
  81. data/lib/octokit/repository.rb +27 -25
  82. data/lib/octokit/response/base_middleware.rb +10 -0
  83. data/lib/octokit/response/feed_parser.rb +5 -9
  84. data/lib/octokit/response/raise_error.rb +4 -6
  85. data/lib/octokit/user.rb +4 -2
  86. data/lib/octokit/version.rb +5 -3
  87. data/lib/octokit/warnable.rb +4 -5
  88. data/lib/octokit.rb +15 -8
  89. data/octokit.gemspec +13 -10
  90. metadata +55 -22
  91. data/lib/octokit/client/authorizations.rb +0 -244
  92. data/lib/octokit/preview.rb +0 -35
@@ -1,21 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the Repositories API
5
6
  #
6
7
  # @see https://developer.github.com/v3/repos/
7
8
  module Repositories
8
-
9
9
  # Check if a repository exists
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
- rescue Octokit::InvalidRepository
17
- false
18
- rescue Octokit::NotFound
16
+ rescue Octokit::InvalidRepository, Octokit::NotFound
19
17
  false
20
18
  end
21
19
 
@@ -28,11 +26,11 @@ module Octokit
28
26
  def repository(repo, options = {})
29
27
  get Repository.path(repo), options
30
28
  end
31
- alias :repo :repository
29
+ alias repo repository
32
30
 
33
31
  # Edit a repository
34
32
  #
35
- # @see https://developer.github.com/v3/repos/#edit
33
+ # @see https://developer.github.com/v3/repos/#update-a-repository
36
34
  # @param repo [String, Hash, Repository] A GitHub repository
37
35
  # @param options [Hash] Repository information to update
38
36
  # @option options [String] :name Name of the repo
@@ -41,6 +39,7 @@ module Octokit
41
39
  # @option options [String] :private `true` makes the repository private, and `false` makes it public.
42
40
  # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
43
41
  # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
42
+ # @option options [Boolean] :is_template `true` makes the repository a template, `false` makes it not a template.
44
43
  # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
45
44
  # @option options [String] :default_branch Update the default branch for this repository.
46
45
  # @return [Sawyer::Resource] Repository information
@@ -49,9 +48,9 @@ module Octokit
49
48
  options[:name] ||= repo.name
50
49
  patch "repos/#{repo}", options
51
50
  end
52
- alias :edit :edit_repository
53
- alias :update_repository :edit_repository
54
- alias :update :edit_repository
51
+ alias edit edit_repository
52
+ alias update_repository edit_repository
53
+ alias update edit_repository
55
54
 
56
55
  # List user repositories
57
56
  #
@@ -67,12 +66,12 @@ module Octokit
67
66
  # @param user [Integer, String] Optional GitHub user login or id for which
68
67
  # to list repos.
69
68
  # @return [Array<Sawyer::Resource>] List of repositories
70
- def repositories(user=nil, options = {})
69
+ def repositories(user = nil, options = {})
71
70
  paginate "#{User.path user}/repos", options
72
71
  end
73
- alias :list_repositories :repositories
74
- alias :list_repos :repositories
75
- alias :repos :repositories
72
+ alias list_repositories repositories
73
+ alias list_repos repositories
74
+ alias repos repositories
76
75
 
77
76
  # List all repositories
78
77
  #
@@ -144,6 +143,7 @@ module Octokit
144
143
  # @option options [String] :private `true` makes the repository private, and `false` makes it public.
145
144
  # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
146
145
  # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
146
+ # @option options [Boolean] :is_template `true` makes this repo available as a template repository, `false` to prevent it.
147
147
  # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
148
148
  # @option options [String] :organization Short name for the org under which to create the repo.
149
149
  # @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.
@@ -154,7 +154,7 @@ module Octokit
154
154
  def create_repository(name, options = {})
155
155
  opts = options.dup
156
156
  organization = opts.delete :organization
157
- opts.merge! :name => name
157
+ opts.merge! name: name
158
158
 
159
159
  if organization.nil?
160
160
  post 'user/repos', opts
@@ -162,8 +162,8 @@ module Octokit
162
162
  post "#{Organization.path organization}/repos", opts
163
163
  end
164
164
  end
165
- alias :create_repo :create_repository
166
- alias :create :create_repository
165
+ alias create_repo create_repository
166
+ alias create create_repository
167
167
 
168
168
  # Delete repository
169
169
  #
@@ -175,7 +175,36 @@ module Octokit
175
175
  def delete_repository(repo, options = {})
176
176
  boolean_from_response :delete, Repository.path(repo), options
177
177
  end
178
- alias :delete_repo :delete_repository
178
+ alias delete_repo delete_repository
179
+
180
+ # Transfer repository
181
+ #
182
+ # Transfer a repository owned by your organization
183
+ #
184
+ # @see https://developer.github.com/v3/repos/#transfer-a-repository
185
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
186
+ # @param new_owner [String] The username or organization name the repository will be transferred to.
187
+ # @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.
188
+ # @return [Sawyer::Resource] Repository info for the transferred repository
189
+ def transfer_repository(repo, new_owner, options = {})
190
+ post "#{Repository.path repo}/transfer", options.merge({ new_owner: new_owner })
191
+ end
192
+ alias transfer_repo transfer_repository
193
+
194
+ # Create a repository for a user or organization generated from a template repository
195
+ #
196
+ # @param repo [Integer, String, Hash, Repository] A GitHub template repository
197
+ # @param name [String] Name of the new repo
198
+ # @option options [String] :owner Organization or user who the new repository will belong to.
199
+ # @option options [String] :description Description of the repo
200
+ # @option options [String] :private `true` makes the repository private, and `false` makes it public.
201
+ # @option options [Boolean] :include_all_branches `true` copies all branches from the template repository, `false` (default) makes it only copy the master branch.
202
+ # @return [Sawyer::Resource] Repository info for the new repository
203
+ def create_repository_from_template(repo, name, options = {})
204
+ options.merge! name: name
205
+ post "#{Repository.path repo}/generate", options
206
+ end
207
+ alias create_repo_from_template create_repository_from_template
179
208
 
180
209
  # Hide a public repository
181
210
  #
@@ -183,7 +212,7 @@ module Octokit
183
212
  # @return [Sawyer::Resource] Updated repository info
184
213
  def set_private(repo, options = {})
185
214
  # GitHub Api for setting private updated to use private attr, rather than public
186
- update_repository repo, options.merge({ :private => true })
215
+ update_repository repo, options.merge({ private: true })
187
216
  end
188
217
 
189
218
  # Unhide a private repository
@@ -192,7 +221,7 @@ module Octokit
192
221
  # @return [Sawyer::Resource] Updated repository info
193
222
  def set_public(repo, options = {})
194
223
  # GitHub Api for setting private updated to use private attr, rather than public
195
- update_repository repo, options.merge({ :private => false })
224
+ update_repository repo, options.merge({ private: false })
196
225
  end
197
226
 
198
227
  # Get deploy keys on a repo
@@ -209,7 +238,7 @@ module Octokit
209
238
  def deploy_keys(repo, options = {})
210
239
  paginate "#{Repository.path repo}/keys", options
211
240
  end
212
- alias :list_deploy_keys :deploy_keys
241
+ alias list_deploy_keys deploy_keys
213
242
 
214
243
  # Get a single deploy key for a repo
215
244
  #
@@ -219,7 +248,7 @@ module Octokit
219
248
  # @see https://developer.github.com/v3/repos/keys/#get-a-deploy-key
220
249
  # @example
221
250
  # @client.deploy_key('octokit/octokit.rb', 8675309)
222
- def deploy_key(repo, id, options={})
251
+ def deploy_key(repo, id, options = {})
223
252
  get "#{Repository.path repo}/keys/#{id}", options
224
253
  end
225
254
 
@@ -235,7 +264,7 @@ module Octokit
235
264
  # @example
236
265
  # @client.add_deploy_key('octokit/octokit.rb', 'Staging server', 'ssh-rsa AAA...')
237
266
  def add_deploy_key(repo, title, key, options = {})
238
- post "#{Repository.path repo}/keys", options.merge(:title => title, :key => key)
267
+ post "#{Repository.path repo}/keys", options.merge(title: title, key: key)
239
268
  end
240
269
 
241
270
  # Edit a deploy key
@@ -256,7 +285,7 @@ module Octokit
256
285
  def edit_deploy_key(repo, id, options)
257
286
  patch "#{Repository.path repo}/keys/#{id}", options
258
287
  end
259
- alias :update_deploy_key :edit_deploy_key
288
+ alias update_deploy_key edit_deploy_key
260
289
 
261
290
  # Remove deploy key from a repo
262
291
  #
@@ -277,6 +306,9 @@ module Octokit
277
306
  # Requires authenticated client for private repos.
278
307
  #
279
308
  # @param repo [Integer, String, Hash, Repository] A GitHub repository.
309
+ # @option options [String] :affiliation Filters the return array by affiliation.
310
+ # Can be one of: <tt>outside</tt>, <tt>direct</tt>, or <tt>all</tt>.
311
+ # If not specified, defaults to <tt>all</tt>
280
312
  # @return [Array<Sawyer::Resource>] Array of hashes representing collaborating users.
281
313
  # @see https://developer.github.com/v3/repos/collaborators/#list-collaborators
282
314
  # @example
@@ -288,7 +320,7 @@ module Octokit
288
320
  def collaborators(repo, options = {})
289
321
  paginate "#{Repository.path repo}/collaborators", options
290
322
  end
291
- alias :collabs :collaborators
323
+ alias collabs collaborators
292
324
 
293
325
  # Add collaborator to repo
294
326
  #
@@ -313,7 +345,7 @@ module Octokit
313
345
  def add_collaborator(repo, collaborator, options = {})
314
346
  boolean_from_response :put, "#{Repository.path repo}/collaborators/#{collaborator}", options
315
347
  end
316
- alias :add_collab :add_collaborator
348
+ alias add_collab add_collaborator
317
349
 
318
350
  # Remove collaborator from repo.
319
351
  #
@@ -330,7 +362,7 @@ module Octokit
330
362
  def remove_collaborator(repo, collaborator, options = {})
331
363
  boolean_from_response :delete, "#{Repository.path repo}/collaborators/#{collaborator}", options
332
364
  end
333
- alias :remove_collab :remove_collaborator
365
+ alias remove_collab remove_collaborator
334
366
 
335
367
  # Checks if a user is a collaborator for a repo.
336
368
  #
@@ -342,10 +374,22 @@ module Octokit
342
374
  # @see https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator
343
375
  # @example
344
376
  # @client.collaborator?('octokit/octokit.rb', 'holman')
345
- def collaborator?(repo, collaborator, options={})
377
+ def collaborator?(repo, collaborator, options = {})
346
378
  boolean_from_response :get, "#{Repository.path repo}/collaborators/#{collaborator}", options
347
379
  end
348
380
 
381
+ # Get a user's permission level for a repo.
382
+ #
383
+ # Requires authenticated client
384
+ #
385
+ # @return [Sawyer::Resource] Hash representing the user's permission level for the given repository
386
+ # @see https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
387
+ # @example
388
+ # @client.permission_level('octokit/octokit.rb', 'lizzhale')
389
+ def permission_level(repo, collaborator, options = {})
390
+ get "#{Repository.path repo}/collaborators/#{collaborator}/permission", options
391
+ end
392
+
349
393
  # List teams for a repo
350
394
  #
351
395
  # Requires authenticated client that is an owner or collaborator of the repo.
@@ -362,8 +406,39 @@ module Octokit
362
406
  def repository_teams(repo, options = {})
363
407
  paginate "#{Repository.path repo}/teams", options
364
408
  end
365
- alias :repo_teams :repository_teams
366
- alias :teams :repository_teams
409
+ alias repo_teams repository_teams
410
+ alias teams repository_teams
411
+
412
+ # List all topics for a repository
413
+ #
414
+ # Requires authenticated client for private repos.
415
+ #
416
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
417
+ # @return [Sawyer::Resource] representing the topics for given repo
418
+ # @see https://developer.github.com/v3/repos/#list-all-topics-for-a-repository
419
+ # @example List topics for octokit/octokit.rb
420
+ # Octokit.topics('octokit/octokit.rb')
421
+ # @example List topics for octokit/octokit.rb
422
+ # client.topics('octokit/octokit.rb')
423
+ def topics(repo, options = {})
424
+ paginate "#{Repository.path repo}/topics", options
425
+ end
426
+
427
+ # Replace all topics for a repository
428
+ #
429
+ # Requires authenticated client.
430
+ #
431
+ # @param repo [Integer, String, Repository, Hash] A Github repository
432
+ # @param names [Array] An array of topics to add to the repository.
433
+ # @return [Sawyer::Resource] representing the replaced topics for given repo
434
+ # @see https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository
435
+ # @example Replace topics for octokit/octokit.rb
436
+ # client.replace_all_topics('octokit/octokit.rb', ['octocat', 'atom', 'electron', 'API'])
437
+ # @example Clear all topics for octokit/octokit.rb
438
+ # client.replace_all_topics('octokit/octokit.rb', [])
439
+ def replace_all_topics(repo, names, options = {})
440
+ put "#{Repository.path repo}/topics", options.merge(names: names)
441
+ end
367
442
 
368
443
  # List contributors to a repo
369
444
  #
@@ -383,7 +458,7 @@ module Octokit
383
458
  options[:anon] = 1 if anon.to_s[/1|true/]
384
459
  paginate "#{Repository.path repo}/contributors", options
385
460
  end
386
- alias :contribs :contributors
461
+ alias contribs contributors
387
462
 
388
463
  # List stargazers of a repo
389
464
  #
@@ -433,7 +508,7 @@ module Octokit
433
508
  def forks(repo, options = {})
434
509
  paginate "#{Repository.path repo}/forks", options
435
510
  end
436
- alias :network :forks
511
+ alias network forks
437
512
 
438
513
  # List languages of code in the repo.
439
514
  #
@@ -489,9 +564,9 @@ module Octokit
489
564
  # @example Get branch 'master` from octokit/octokit.rb
490
565
  # Octokit.branch("octokit/octokit.rb", "master")
491
566
  def branch(repo, branch, options = {})
492
- get "#{Repository.path repo}/branches/#{branch}", options
567
+ get "#{Repository.path repo}/branches/#{CGI.escape(branch)}", options
493
568
  end
494
- alias :get_branch :branch
569
+ alias get_branch branch
495
570
 
496
571
  # Lock a single branch from a repository
497
572
  #
@@ -499,14 +574,14 @@ module Octokit
499
574
  #
500
575
  # @param repo [Integer, String, Hash, Repository] A GitHub repository.
501
576
  # @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>
577
+ # @option options [Hash] :required_status_checks If not null, the following keys are required:
578
+ # <tt>:enforce_admins [boolean] Enforce required status checks for repository administrators.</tt>
579
+ # <tt>:strict [boolean] Require branches to be up to date before merging.</tt>
580
+ # <tt>:contexts [Array] The list of status checks to require in order to merge into this branch</tt>
506
581
  #
507
582
  # @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>.
583
+ # <tt>:users [Array] The list of user logins with push access</tt>
584
+ # <tt>:teams [Array] The list of team slugs with push access</tt>.
510
585
  #
511
586
  # Teams and users restrictions are only available for organization-owned repositories.
512
587
  # @return [Sawyer::Resource] The protected branch
@@ -514,10 +589,9 @@ module Octokit
514
589
  # @example
515
590
  # @client.protect_branch('octokit/octokit.rb', 'master', foo)
516
591
  def protect_branch(repo, branch, options = {})
517
- opts = ensure_api_media_type(:branch_protection, options)
518
- opts[:restrictions] ||= nil
519
- opts[:required_status_checks] ||= nil
520
- put "#{Repository.path repo}/branches/#{branch}/protection", opts
592
+ options[:restrictions] ||= nil
593
+ options[:required_status_checks] ||= nil
594
+ put "#{Repository.path repo}/branches/#{branch}/protection", options
521
595
  end
522
596
 
523
597
  # Get branch protection summary
@@ -530,12 +604,9 @@ module Octokit
530
604
  # @example
531
605
  # @client.branch_protection('octokit/octokit.rb', 'master')
532
606
  def branch_protection(repo, branch, options = {})
533
- opts = ensure_api_media_type(:branch_protection, options)
534
- begin
535
- get "#{Repository.path repo}/branches/#{branch}/protection", opts
536
- rescue Octokit::BranchNotProtected
537
- nil
538
- end
607
+ get "#{Repository.path repo}/branches/#{branch}/protection", options
608
+ rescue Octokit::BranchNotProtected
609
+ nil
539
610
  end
540
611
 
541
612
  # Unlock a single branch from a repository
@@ -549,8 +620,25 @@ module Octokit
549
620
  # @example
550
621
  # @client.unprotect_branch('octokit/octokit.rb', 'master')
551
622
  def unprotect_branch(repo, branch, options = {})
552
- opts = ensure_api_media_type(:branch_protection, options)
553
- boolean_from_response :delete, "#{Repository.path repo}/branches/#{branch}/protection", opts
623
+ boolean_from_response :delete, "#{Repository.path repo}/branches/#{branch}/protection", options
624
+ end
625
+
626
+ # Rename a single branch from a repository
627
+ #
628
+ # Requires authenticated client
629
+ #
630
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
631
+ # @param branch [String] Current branch name
632
+ # @param new_name [String] New branch name
633
+ # @return [Sawyer::Resource] The renamed branch
634
+ # @see https://developer.github.com/v3/repos/#rename-a-branch
635
+ # @example
636
+ # @client.rename_branch('octokit/octokit.rb', 'master', 'main')
637
+ def rename_branch(repo, branch, new_name, options = {})
638
+ params = {
639
+ new_name: new_name
640
+ }
641
+ post "#{Repository.path repo}/branches/#{branch}/rename", params.merge(options)
554
642
  end
555
643
 
556
644
  # List users available for assigning to issues.
@@ -569,7 +657,7 @@ module Octokit
569
657
  def repository_assignees(repo, options = {})
570
658
  paginate "#{Repository.path repo}/assignees", options
571
659
  end
572
- alias :repo_assignees :repository_assignees
660
+ alias repo_assignees repository_assignees
573
661
 
574
662
  # Check to see if a particular user is an assignee for a repository.
575
663
  #
@@ -633,6 +721,59 @@ module Octokit
633
721
  def delete_subscription(repo, options = {})
634
722
  boolean_from_response :delete, "#{Repository.path repo}/subscription", options
635
723
  end
724
+
725
+ # Create a repository dispatch event
726
+ #
727
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
728
+ # @param event_type [String] A custom webhook event name.
729
+ # @option options [Hash] :client_payload payload with extra information
730
+ # about the webhook event that your action or worklow may use.
731
+ #
732
+ # @return [Boolean] True if event was dispatched, false otherwise.
733
+ # @see https://developer.github.com/v3/repos/#create-a-repository-dispatch-event
734
+ def dispatch_event(repo, event_type, options = {})
735
+ boolean_from_response :post, "#{Repository.path repo}/dispatches", options.merge({ event_type: event_type })
736
+ end
737
+
738
+ # Check to see if vulnerability alerts are enabled for a repository
739
+ #
740
+ # The authenticated user must have admin access to the repository.
741
+ #
742
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
743
+ # @return [Boolean] True if vulnerability alerts are enabled, false otherwise.
744
+ # @see https://docs.github.com/en/rest/reference/repos#check-if-vulnerability-alerts-are-enabled-for-a-repository
745
+ #
746
+ # @example
747
+ # @client.vulnerability_alerts_enabled?("octokit/octokit.rb")
748
+ def vulnerability_alerts_enabled?(repo, options = {})
749
+ boolean_from_response(:get, "#{Repository.path repo}/vulnerability-alerts", options)
750
+ end
751
+
752
+ # Enable vulnerability alerts for a repository
753
+ #
754
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
755
+ # @param options [Hash]
756
+ #
757
+ # @return [Boolean] True if vulnerability alerts enabled, false otherwise.
758
+ # @see https://docs.github.com/en/rest/reference/repos#enable-vulnerability-alerts
759
+ # @example Enable vulnerability alerts for a repository
760
+ # @client.enable_vulnerability_alerts("octokit/octokit.rb")
761
+ def enable_vulnerability_alerts(repo, options = {})
762
+ boolean_from_response(:put, "#{Repository.path repo}/vulnerability-alerts", options)
763
+ end
764
+
765
+ # Disable vulnerability alerts for a repository
766
+ #
767
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
768
+ # @param options [Hash]
769
+ #
770
+ # @return [Boolean] True if vulnerability alerts disabled, false otherwise.
771
+ # @see https://docs.github.com/en/rest/reference/repos#disable-vulnerability-alerts
772
+ # @example Disable vulnerability alerts for a repository
773
+ # @client.disable_vulnerability_alerts("octokit/octokit.rb")
774
+ def disable_vulnerability_alerts(repo, options = {})
775
+ boolean_from_response(:delete, "#{Repository.path repo}/vulnerability-alerts", options)
776
+ end
636
777
  end
637
778
  end
638
779
  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 Repository Invitations API
5
6
  #
6
7
  # @see https://developer.github.com/v3/repos/invitations/
7
8
  module RepositoryInvitations
8
-
9
9
  # Invite a user to a repository
10
10
  #
11
11
  # Requires authenticated client
@@ -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,8 +64,7 @@ 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
- paginate "/user/repository_invitations", options
67
+ paginate '/user/repository_invitations', options
73
68
  end
74
69
  alias user_repo_invitations user_repository_invitations
75
70
 
@@ -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