octokit 4.15.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +2 -4
  3. data/README.md +104 -80
  4. data/Rakefile +5 -3
  5. data/lib/ext/sawyer/relation.rb +4 -2
  6. data/lib/octokit/arguments.rb +2 -2
  7. data/lib/octokit/authentication.rb +12 -14
  8. data/lib/octokit/client/actions_artifacts.rb +71 -0
  9. data/lib/octokit/client/actions_secrets.rb +59 -0
  10. data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
  11. data/lib/octokit/client/actions_workflow_runs.rb +125 -0
  12. data/lib/octokit/client/actions_workflows.rb +68 -0
  13. data/lib/octokit/client/apps.rb +53 -53
  14. data/lib/octokit/client/checks.rb +18 -29
  15. data/lib/octokit/client/commit_branches.rb +20 -0
  16. data/lib/octokit/client/commit_comments.rb +8 -8
  17. data/lib/octokit/client/commit_pulls.rb +2 -2
  18. data/lib/octokit/client/commits.rb +31 -34
  19. data/lib/octokit/client/community_profile.rb +2 -3
  20. data/lib/octokit/client/contents.rb +24 -21
  21. data/lib/octokit/client/deployments.rb +16 -6
  22. data/lib/octokit/client/downloads.rb +5 -6
  23. data/lib/octokit/client/emojis.rb +3 -3
  24. data/lib/octokit/client/events.rb +4 -4
  25. data/lib/octokit/client/feeds.rb +4 -5
  26. data/lib/octokit/client/gists.rb +6 -6
  27. data/lib/octokit/client/gitignore.rb +3 -3
  28. data/lib/octokit/client/hooks.rb +9 -19
  29. data/lib/octokit/client/issues.rb +14 -15
  30. data/lib/octokit/client/labels.rb +10 -10
  31. data/lib/octokit/client/legacy_search.rb +3 -3
  32. data/lib/octokit/client/licenses.rb +3 -6
  33. data/lib/octokit/client/markdown.rb +3 -3
  34. data/lib/octokit/client/marketplace.rb +4 -4
  35. data/lib/octokit/client/meta.rb +4 -5
  36. data/lib/octokit/client/milestones.rb +5 -5
  37. data/lib/octokit/client/notifications.rb +6 -6
  38. data/lib/octokit/client/oauth_applications.rb +116 -0
  39. data/lib/octokit/client/objects.rb +14 -14
  40. data/lib/octokit/client/organizations.rb +112 -70
  41. data/lib/octokit/client/pages.rb +5 -7
  42. data/lib/octokit/client/projects.rb +44 -64
  43. data/lib/octokit/client/pub_sub_hubbub.rb +16 -16
  44. data/lib/octokit/client/pull_requests.rb +52 -42
  45. data/lib/octokit/client/rate_limit.rb +9 -11
  46. data/lib/octokit/client/reactions.rb +6 -11
  47. data/lib/octokit/client/refs.rb +32 -19
  48. data/lib/octokit/client/releases.rb +13 -13
  49. data/lib/octokit/client/repositories.rb +123 -69
  50. data/lib/octokit/client/repository_invitations.rb +3 -3
  51. data/lib/octokit/client/reviews.rb +7 -7
  52. data/lib/octokit/client/say.rb +4 -5
  53. data/lib/octokit/client/search.rb +24 -11
  54. data/lib/octokit/client/service_status.rb +19 -9
  55. data/lib/octokit/client/source_import.rb +7 -12
  56. data/lib/octokit/client/stats.rb +10 -9
  57. data/lib/octokit/client/statuses.rb +5 -5
  58. data/lib/octokit/client/tokens.rb +31 -0
  59. data/lib/octokit/client/traffic.rb +6 -11
  60. data/lib/octokit/client/users.rb +104 -24
  61. data/lib/octokit/client.rb +44 -18
  62. data/lib/octokit/configurable.rb +34 -30
  63. data/lib/octokit/connection.rb +28 -26
  64. data/lib/octokit/default.rb +46 -35
  65. data/lib/octokit/enterprise_admin_client/admin_stats.rb +13 -14
  66. data/lib/octokit/enterprise_admin_client/license.rb +3 -4
  67. data/lib/octokit/enterprise_admin_client/orgs.rb +3 -4
  68. data/lib/octokit/enterprise_admin_client/search_indexing.rb +7 -8
  69. data/lib/octokit/enterprise_admin_client/users.rb +5 -4
  70. data/lib/octokit/enterprise_admin_client.rb +9 -3
  71. data/lib/octokit/enterprise_management_console_client/management_console.rb +32 -32
  72. data/lib/octokit/enterprise_management_console_client.rb +8 -2
  73. data/lib/octokit/error.rb +72 -27
  74. data/lib/octokit/gist.rb +2 -3
  75. data/lib/octokit/middleware/follow_redirects.rb +15 -11
  76. data/lib/octokit/organization.rb +3 -1
  77. data/lib/octokit/rate_limit.rb +3 -3
  78. data/lib/octokit/repo_arguments.rb +2 -3
  79. data/lib/octokit/repository.rb +24 -24
  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 +4 -2
  85. data/lib/octokit/warnable.rb +4 -5
  86. data/lib/octokit.rb +15 -8
  87. data/octokit.gemspec +12 -10
  88. metadata +25 -17
  89. data/lib/octokit/client/authorizations.rb +0 -250
  90. data/lib/octokit/preview.rb +0 -46
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the OauthApplications API
6
+ #
7
+ # @see https://developer.github.com/v3/apps/oauth_applications
8
+ module OauthApplications
9
+ # Check if a token is valid.
10
+ #
11
+ # Applications can check if a token is valid without rate limits.
12
+ #
13
+ # @param access_token [String] 40 character GitHub OAuth access token
14
+ #
15
+ # @return [Sawyer::Resource] A single authorization for the authenticated user
16
+ # @see https://developer.github.com/v3/apps/oauth_applications/#check-a-token
17
+ #
18
+ # @example
19
+ # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
20
+ # client.check_token('deadbeef1234567890deadbeef987654321')
21
+ def check_token(access_token, options = {})
22
+ options[:access_token] = access_token
23
+
24
+ key = options.delete(:client_id) || client_id
25
+ secret = options.delete(:client_secret) || client_secret
26
+
27
+ as_app(key, secret) do |app_client|
28
+ app_client.post "applications/#{client_id}/token", options
29
+ end
30
+ end
31
+ alias check_application_authorization check_token
32
+
33
+ # Reset a token
34
+ #
35
+ # Applications can reset a token without requiring a user to re-authorize.
36
+ #
37
+ # @param access_token [String] 40 character GitHub OAuth access token
38
+ #
39
+ # @return [Sawyer::Resource] A single authorization for the authenticated user
40
+ # @see https://developer.github.com/v3/apps/oauth_applications/#reset-a-token
41
+ #
42
+ # @example
43
+ # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
44
+ # client.reset_token('deadbeef1234567890deadbeef987654321')
45
+ def reset_token(access_token, options = {})
46
+ options[:access_token] = access_token
47
+
48
+ key = options.delete(:client_id) || client_id
49
+ secret = options.delete(:client_secret) || client_secret
50
+
51
+ as_app(key, secret) do |app_client|
52
+ app_client.patch "applications/#{client_id}/token", options
53
+ end
54
+ end
55
+ alias reset_application_authorization reset_token
56
+
57
+ # Delete an app token
58
+ #
59
+ # Applications can revoke (delete) a token
60
+ #
61
+ # @param access_token [String] 40 character GitHub OAuth access token
62
+ #
63
+ # @return [Boolean] Result
64
+ # @see https://developer.github.com/v3/apps/oauth_applications/#delete-an-app-token
65
+ #
66
+ # @example
67
+ # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
68
+ # client.delete_token('deadbeef1234567890deadbeef987654321')
69
+ def delete_app_token(access_token, options = {})
70
+ options[:access_token] = access_token
71
+
72
+ key = options.delete(:client_id) || client_id
73
+ secret = options.delete(:client_secret) || client_secret
74
+
75
+ begin
76
+ as_app(key, secret) do |app_client|
77
+ app_client.delete "applications/#{client_id}/token", options
78
+ app_client.last_response.status == 204
79
+ end
80
+ rescue Octokit::NotFound
81
+ false
82
+ end
83
+ end
84
+ alias delete_application_authorization delete_app_token
85
+ alias revoke_application_authorization delete_app_token
86
+
87
+ # Delete an app authorization
88
+ #
89
+ # OAuth application owners can revoke a grant for their OAuth application and a specific user.
90
+ #
91
+ # @param access_token [String] 40 character GitHub OAuth access token
92
+ #
93
+ # @return [Boolean] Result
94
+ # @see https://developer.github.com/v3/apps/oauth_applications/#delete-an-app-token
95
+ #
96
+ # @example
97
+ # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
98
+ # client.delete_app_authorization('deadbeef1234567890deadbeef987654321')
99
+ def delete_app_authorization(access_token, options = {})
100
+ options[:access_token] = access_token
101
+
102
+ key = options.delete(:client_id) || client_id
103
+ secret = options.delete(:client_secret) || client_secret
104
+
105
+ begin
106
+ as_app(key, secret) do |app_client|
107
+ app_client.delete "applications/#{client_id}/grant", options
108
+ app_client.last_response.status == 204
109
+ end
110
+ rescue Octokit::NotFound
111
+ false
112
+ end
113
+ end
114
+ end
115
+ end
116
+ 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 Git Data API
5
6
  #
6
7
  # @see https://developer.github.com/v3/git/
7
8
  module Objects
8
-
9
9
  # Get a single tree, fetching information about its root-level objects
10
10
  #
11
11
  # Pass <tt>:recursive => true</tt> in <tt>options</tt> to fetch information about all of the tree's objects, including those in subdirectories.
@@ -38,7 +38,7 @@ module Octokit
38
38
  # tree.sha # => "cd8274d15fa3ae2ab983129fb037999f264ba9a7"
39
39
  # tree.tree.first.path # => "file.rb"
40
40
  def create_tree(repo, tree, options = {})
41
- parameters = { :tree => tree }
41
+ parameters = { tree: tree }
42
42
  post "#{Repository.path repo}/git/trees", options.merge(parameters)
43
43
  end
44
44
 
@@ -74,10 +74,10 @@ module Octokit
74
74
  # @example Create a blob containing <tt>foo bar baz</tt>, encoded using base64
75
75
  # require "base64"
76
76
  # Octokit.create_blob("octocat/Hello-World", Base64.encode64("foo bar baz"), "base64")
77
- def create_blob(repo, content, encoding="utf-8", options = {})
77
+ def create_blob(repo, content, encoding = 'utf-8', options = {})
78
78
  parameters = {
79
- :content => content,
80
- :encoding => encoding
79
+ content: content,
80
+ encoding: encoding
81
81
  }
82
82
  blob = post "#{Repository.path repo}/git/blobs", options.merge(parameters)
83
83
 
@@ -124,14 +124,14 @@ module Octokit
124
124
  # )
125
125
  def create_tag(repo, tag, message, object_sha, type, tagger_name, tagger_email, tagger_date, options = {})
126
126
  options.merge!(
127
- :tag => tag,
128
- :message => message,
129
- :object => object_sha,
130
- :type => type,
131
- :tagger => {
132
- :name => tagger_name,
133
- :email => tagger_email,
134
- :date => tagger_date
127
+ tag: tag,
128
+ message: message,
129
+ object: object_sha,
130
+ type: type,
131
+ tagger: {
132
+ name: tagger_name,
133
+ email: tagger_email,
134
+ date: tagger_date
135
135
  }
136
136
  )
137
137
  post "#{Repository.path repo}/git/tags", options
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the Organizations API
5
6
  #
6
7
  # @see https://developer.github.com/v3/orgs/
7
8
  module Organizations
8
-
9
9
  # Get an organization
10
10
  #
11
11
  # @param org [String, Integer] Organization GitHub login or id.
@@ -18,7 +18,7 @@ module Octokit
18
18
  def organization(org, options = {})
19
19
  get Organization.path(org), options
20
20
  end
21
- alias :org :organization
21
+ alias org organization
22
22
 
23
23
  # Update an organization.
24
24
  #
@@ -48,7 +48,7 @@ module Octokit
48
48
  def update_organization(org, values, options = {})
49
49
  patch Organization.path(org), options.merge(values)
50
50
  end
51
- alias :update_org :update_organization
51
+ alias update_org update_organization
52
52
 
53
53
  # Get organizations for a user.
54
54
  #
@@ -78,12 +78,12 @@ module Octokit
78
78
  # Octokit.list_orgs('pengwynn')
79
79
  # @example
80
80
  # @client.organizations
81
- def organizations(user=nil, options = {})
81
+ def organizations(user = nil, options = {})
82
82
  paginate "#{User.path user}/orgs", options
83
83
  end
84
- alias :list_organizations :organizations
85
- alias :list_orgs :organizations
86
- alias :orgs :organizations
84
+ alias list_organizations organizations
85
+ alias list_orgs organizations
86
+ alias orgs organizations
87
87
 
88
88
  # List all GitHub organizations
89
89
  #
@@ -98,9 +98,9 @@ module Octokit
98
98
  #
99
99
  # @return [Array<Sawyer::Resource>] List of GitHub organizations.
100
100
  def all_organizations(options = {})
101
- paginate "organizations", options
101
+ paginate 'organizations', options
102
102
  end
103
- alias :all_orgs :all_organizations
103
+ alias all_orgs all_organizations
104
104
 
105
105
  # List organization repositories
106
106
  #
@@ -125,8 +125,8 @@ module Octokit
125
125
  def organization_repositories(org, options = {})
126
126
  paginate "#{Organization.path org}/repos", options
127
127
  end
128
- alias :org_repositories :organization_repositories
129
- alias :org_repos :organization_repositories
128
+ alias org_repositories organization_repositories
129
+ alias org_repos organization_repositories
130
130
 
131
131
  # Get organization members
132
132
  #
@@ -143,10 +143,10 @@ module Octokit
143
143
  # Octokit.org_members('github')
144
144
  def organization_members(org, options = {})
145
145
  options = options.dup
146
- path = "public_" if options.delete(:public)
146
+ path = 'public_' if options.delete(:public)
147
147
  paginate "#{Organization.path org}/#{path}members", options
148
148
  end
149
- alias :org_members :organization_members
149
+ alias org_members organization_members
150
150
 
151
151
  # Get organization public members
152
152
  #
@@ -160,9 +160,9 @@ module Octokit
160
160
  # @example
161
161
  # Octokit.org_public_members('github')
162
162
  def organization_public_members(org, options = {})
163
- organization_members org, options.merge(:public => true)
163
+ organization_members org, options.merge(public: true)
164
164
  end
165
- alias :org_public_members :organization_public_members
165
+ alias org_public_members organization_public_members
166
166
 
167
167
  # Check if a user is a member of an organization.
168
168
  #
@@ -188,7 +188,7 @@ module Octokit
188
188
  result
189
189
  end
190
190
  end
191
- alias :org_member? :organization_member?
191
+ alias org_member? organization_member?
192
192
 
193
193
  # Check if a user is a public member of an organization.
194
194
  #
@@ -208,7 +208,7 @@ module Octokit
208
208
  def organization_public_member?(org, user, options = {})
209
209
  boolean_from_response :get, "#{Organization.path org}/public_members/#{user}", options
210
210
  end
211
- alias :org_public_member? :organization_public_member?
211
+ alias org_public_member? organization_public_member?
212
212
 
213
213
  # List pending organization invitations
214
214
  #
@@ -223,7 +223,7 @@ module Octokit
223
223
  def organization_invitations(org, options = {})
224
224
  get "#{Organization.path org}/invitations", options
225
225
  end
226
- alias :org_invitations :organization_invitations
226
+ alias org_invitations organization_invitations
227
227
 
228
228
  # List outside collaborators for an organization
229
229
  #
@@ -235,8 +235,8 @@ module Octokit
235
235
  #
236
236
  # @example
237
237
  # @client.outside_collaborators('github')
238
- def outside_collaborators(org, options={})
239
- get "#{Organization.path org}/outside_collaborators", options
238
+ def outside_collaborators(org, options = {})
239
+ paginate "#{Organization.path org}/outside_collaborators", options
240
240
  end
241
241
 
242
242
  # Remove outside collaborator from an organization
@@ -250,7 +250,7 @@ module Octokit
250
250
  #
251
251
  # @example
252
252
  # @client.remove_outside_collaborator('github', 'lizzhale')
253
- def remove_outside_collaborator(org, user, options={})
253
+ def remove_outside_collaborator(org, user, options = {})
254
254
  boolean_from_response :delete, "#{Organization.path org}/outside_collaborators/#{user}", options
255
255
  end
256
256
 
@@ -265,7 +265,7 @@ module Octokit
265
265
  #
266
266
  # @example
267
267
  # @client.convert_to_outside_collaborator('github', 'lizzhale')
268
- def convert_to_outside_collaborator(org, user, options={})
268
+ def convert_to_outside_collaborator(org, user, options = {})
269
269
  boolean_from_response :put, "#{Organization.path org}/outside_collaborators/#{user}", options
270
270
  end
271
271
 
@@ -283,7 +283,7 @@ module Octokit
283
283
  def organization_teams(org, options = {})
284
284
  paginate "#{Organization.path org}/teams", options
285
285
  end
286
- alias :org_teams :organization_teams
286
+ alias org_teams organization_teams
287
287
 
288
288
  # Create team
289
289
  #
@@ -303,10 +303,7 @@ module Octokit
303
303
  # })
304
304
  def create_team(org, options = {})
305
305
  if options.key?(:permission)
306
- octokit_warn "Deprecated: Passing :permission option to #create_team. Assign team repository permission by passing :permission to #add_team_repository instead."
307
- end
308
- if options.key?(:parent_team_id)
309
- options = ensure_api_media_type(:nested_teams, options)
306
+ octokit_warn 'Deprecated: Passing :permission option to #create_team. Assign team repository permission by passing :permission to #add_team_repository instead.'
310
307
  end
311
308
  post "#{Organization.path org}/teams", options
312
309
  end
@@ -333,11 +330,32 @@ module Octokit
333
330
  # @return [Sawyer::Resource] Hash representing team.
334
331
  # @see https://developer.github.com/v3/teams/#get-team-by-name
335
332
  # @example
336
- # @client.team("github", "justice-league")
333
+ # @client.team_by_name("github", "justice-league")
337
334
  def team_by_name(org, team_slug, options = {})
338
335
  get "#{Organization.path(org)}/teams/#{team_slug}", options
339
336
  end
340
337
 
338
+ # Check team permissions for a repository
339
+ #
340
+ # Requires authenticated organization member.
341
+ #
342
+ # @param org [String, Integer] Organization GitHub login or id.
343
+ # @param team_slug_or_id [String, Integer] Team slug or Team ID.
344
+ # @param owner [String] Owner name for the repository.
345
+ # @param repo [String] Name of the repo to check permissions against.
346
+ # @return [String, Sawyer::Resource] Depending on options it may be an empty string or a resource.
347
+ # @example
348
+ # # Check whether the team has any permissions with the repository
349
+ # @client.team_permissions_for_repo("github", "justice-league", "octocat", "hello-world")
350
+ #
351
+ # @example
352
+ # # Get the full repository object including the permissions level and role for the team
353
+ # @client.team_permissions_for_repo("github", "justice-league", "octocat", "hello-world", :accept => 'application/vnd.github.v3.repository+json')
354
+ # @see https://docs.github.com/en/rest/teams/teams#check-team-permissions-for-a-repository
355
+ def team_permissions_for_repo(org, team_slug_or_id, owner, repo, options = {})
356
+ get "#{Organization.path(org)}/teams/#{team_slug_or_id}/repos/#{owner}/#{repo}", options
357
+ end
358
+
341
359
  # List child teams
342
360
  #
343
361
  # Requires authenticated organization member.
@@ -348,7 +366,6 @@ module Octokit
348
366
  # @example
349
367
  # @client.child_teams(100000, :accept => "application/vnd.github.hellcat-preview+json")
350
368
  def child_teams(team_id, options = {})
351
- options = ensure_api_media_type(:nested_teams, options)
352
369
  paginate "teams/#{team_id}/teams", options
353
370
  end
354
371
 
@@ -372,9 +389,6 @@ module Octokit
372
389
  # :permission => 'push'
373
390
  # })
374
391
  def update_team(team_id, options = {})
375
- if options.key?(:parent_team_id)
376
- options = ensure_api_media_type(:nested_teams, options)
377
- end
378
392
  patch "teams/#{team_id}", options
379
393
  end
380
394
 
@@ -429,7 +443,7 @@ module Octokit
429
443
  # There's a bug in this API call. The docs say to leave the body blank,
430
444
  # but it fails if the body is both blank and the content-length header
431
445
  # is not 0.
432
- boolean_from_response :put, "teams/#{team_id}/members/#{user}", options.merge({:name => user})
446
+ boolean_from_response :put, "teams/#{team_id}/members/#{user}", options.merge({ name: user })
433
447
  end
434
448
 
435
449
  # Remove team member
@@ -494,7 +508,7 @@ module Octokit
494
508
  def team_repositories(team_id, options = {})
495
509
  paginate "teams/#{team_id}/repos", options
496
510
  end
497
- alias :team_repos :team_repositories
511
+ alias team_repos team_repositories
498
512
 
499
513
  # Check if a repo is managed by a specific team
500
514
  #
@@ -508,10 +522,10 @@ module Octokit
508
522
  # @client.team_repository?(8675309, 'octokit/octokit.rb')
509
523
  # @example
510
524
  # @client.team_repo?(8675309, 'octokit/octokit.rb')
511
- def team_repository?(team_id, repo, options = {})
525
+ def team_repository?(team_id, repo, _options = {})
512
526
  boolean_from_response :get, "teams/#{team_id}/repos/#{Repository.new(repo)}"
513
527
  end
514
- alias :team_repo? :team_repository?
528
+ alias team_repo? team_repository?
515
529
 
516
530
  # Add team repository
517
531
  #
@@ -540,7 +554,7 @@ module Octokit
540
554
  def add_team_repository(team_id, repo, options = {})
541
555
  boolean_from_response :put, "teams/#{team_id}/repos/#{Repository.new(repo)}", options
542
556
  end
543
- alias :add_team_repo :add_team_repository
557
+ alias add_team_repo add_team_repository
544
558
 
545
559
  # Remove team repository
546
560
  #
@@ -557,10 +571,10 @@ module Octokit
557
571
  # @client.remove_team_repository(100000, 'github/developer.github.com')
558
572
  # @example
559
573
  # @client.remove_team_repo(100000, 'github/developer.github.com')
560
- def remove_team_repository(team_id, repo, options = {})
574
+ def remove_team_repository(team_id, repo, _options = {})
561
575
  boolean_from_response :delete, "teams/#{team_id}/repos/#{Repository.new(repo)}"
562
576
  end
563
- alias :remove_team_repo :remove_team_repository
577
+ alias remove_team_repo remove_team_repository
564
578
 
565
579
  # Remove organization member
566
580
  #
@@ -579,7 +593,7 @@ module Octokit
579
593
  # provided in the GH API v3
580
594
  boolean_from_response :delete, "#{Organization.path org}/members/#{user}", options
581
595
  end
582
- alias :remove_org_member :remove_organization_member
596
+ alias remove_org_member remove_organization_member
583
597
 
584
598
  # Publicize a user's membership of an organization
585
599
  #
@@ -610,14 +624,14 @@ module Octokit
610
624
  def unpublicize_membership(org, user, options = {})
611
625
  boolean_from_response :delete, "#{Organization.path org}/public_members/#{user}", options
612
626
  end
613
- alias :conceal_membership :unpublicize_membership
627
+ alias conceal_membership unpublicize_membership
614
628
 
615
629
  # List all teams for the authenticated user across all their orgs
616
630
  #
617
631
  # @return [Array<Sawyer::Resource>] Array of team resources.
618
632
  # @see https://developer.github.com/v3/orgs/teams/#list-user-teams
619
633
  def user_teams(options = {})
620
- paginate "user/teams", options
634
+ paginate 'user/teams', options
621
635
  end
622
636
 
623
637
  # Check if a user has a team membership.
@@ -667,9 +681,9 @@ module Octokit
667
681
  # @return [Array<Sawyer::Resource>] Array of organizations memberships.
668
682
  # @see https://developer.github.com/v3/orgs/members/#list-your-organization-memberships
669
683
  def organization_memberships(options = {})
670
- paginate "user/memberships/orgs", options
684
+ paginate 'user/memberships/orgs', options
671
685
  end
672
- alias :org_memberships :organization_memberships
686
+ alias org_memberships organization_memberships
673
687
 
674
688
  # Get an organization membership
675
689
  #
@@ -686,11 +700,11 @@ module Octokit
686
700
  get "user/memberships/orgs/#{org}", options
687
701
  end
688
702
  end
689
- alias :org_membership :organization_membership
703
+ alias org_membership organization_membership
690
704
 
691
705
  # Edit an organization membership
692
706
  #
693
- # @param org [String] Organization GitHub login.
707
+ # @param org [String, Integer] Organization GitHub login or id.
694
708
  # @option options [String] :role The role of the user in the organization.
695
709
  # @option options [String] :state The state that the membership should be in.
696
710
  # @option options [String] :user The login of the user, otherwise authenticated user.
@@ -701,25 +715,25 @@ module Octokit
701
715
  options = options.dup
702
716
  if user = options.delete(:user)
703
717
  options.delete(:state)
704
- put "orgs/#{org}/memberships/#{user}", options
718
+ put "#{Organization.path(org)}/memberships/#{user}", options
705
719
  else
706
720
  options.delete(:role)
707
721
  patch "user/memberships/orgs/#{org}", options
708
722
  end
709
723
  end
710
- alias :update_org_membership :update_organization_membership
724
+ alias update_org_membership update_organization_membership
711
725
 
712
726
  # Remove an organization membership
713
727
  #
714
- # @param org [String] Organization GitHub login.
728
+ # @param org [String, Integer] Organization GitHub login or id.
715
729
  # @return [Boolean] Success
716
730
  # @see https://developer.github.com/v3/orgs/members/#remove-organization-membership
717
731
  def remove_organization_membership(org, options = {})
718
732
  options = options.dup
719
733
  user = options.delete(:user)
720
- user && boolean_from_response(:delete, "orgs/#{org}/memberships/#{user}", options)
734
+ user && boolean_from_response(:delete, "#{Organization.path(org)}/memberships/#{user}", options)
721
735
  end
722
- alias :remove_org_membership :remove_organization_membership
736
+ alias remove_org_membership remove_organization_membership
723
737
 
724
738
  # Initiates the generation of a migration archive.
725
739
  #
@@ -731,11 +745,10 @@ module Octokit
731
745
  # @return [Sawyer::Resource] Hash representing the new migration.
732
746
  # @example
733
747
  # @client.start_migration('github', ['github/dotfiles'])
734
- # @see https://developer.github.com/v3/orgs/migrations/#start-a-migration
748
+ # @see https://docs.github.com/en/rest/reference/migrations#start-an-organization-migration
735
749
  def start_migration(org, repositories, options = {})
736
- options = ensure_api_media_type(:migrations, options)
737
750
  options[:repositories] = repositories
738
- post "orgs/#{org}/migrations", options
751
+ post "#{Organization.path(org)}/migrations", options
739
752
  end
740
753
 
741
754
  # Lists the most recent migrations.
@@ -744,10 +757,9 @@ module Octokit
744
757
  #
745
758
  # @param org [String, Integer] Organization GitHub login or id.
746
759
  # @return [Array<Sawyer::Resource>] Array of migration resources.
747
- # @see https://developer.github.com/v3/orgs/migrations/#get-a-list-of-migrations
760
+ # @see https://docs.github.com/en/rest/reference/migrations#list-organization-migrations
748
761
  def migrations(org, options = {})
749
- options = ensure_api_media_type(:migrations, options)
750
- paginate "orgs/#{org}/migrations", options
762
+ paginate "#{Organization.path(org)}/migrations", options
751
763
  end
752
764
 
753
765
  # Fetches the status of a migration.
@@ -756,10 +768,9 @@ module Octokit
756
768
  #
757
769
  # @param org [String, Integer] Organization GitHub login or id.
758
770
  # @param id [Integer] ID number of the migration.
759
- # @see https://developer.github.com/v3/orgs/migrations/#get-the-status-of-a-migration
771
+ # @see https://docs.github.com/en/rest/reference/migrations#get-an-organization-migration-status
760
772
  def migration_status(org, id, options = {})
761
- options = ensure_api_media_type(:migrations, options)
762
- get "orgs/#{org}/migrations/#{id}", options
773
+ get "#{Organization.path(org)}/migrations/#{id}", options
763
774
  end
764
775
 
765
776
  # Fetches the URL to a migration archive.
@@ -768,10 +779,9 @@ module Octokit
768
779
  #
769
780
  # @param org [String, Integer] Organization GitHub login or id.
770
781
  # @param id [Integer] ID number of the migration.
771
- # @see https://developer.github.com/v3/orgs/migrations/#download-a-migration-archive
782
+ # @see https://docs.github.com/en/rest/reference/migrations#download-an-organization-migration-archive
772
783
  def migration_archive_url(org, id, options = {})
773
- options = ensure_api_media_type(:migrations, options)
774
- url = "orgs/#{org}/migrations/#{id}/archive"
784
+ url = "#{Organization.path(org)}/migrations/#{id}/archive"
775
785
 
776
786
  response = client_without_redirects(options).get(url)
777
787
  response.headers['location']
@@ -783,10 +793,9 @@ module Octokit
783
793
  #
784
794
  # @param org [String, Integer] Organization GitHub login or id.
785
795
  # @param id [Integer] ID number of the migration.
786
- # @see https://developer.github.com/v3/orgs/migrations/#delete-a-migration-archive
796
+ # @see https://docs.github.com/en/rest/reference/migrations#delete-an-organization-migration-archive
787
797
  def delete_migration_archive(org, id, options = {})
788
- options = ensure_api_media_type(:migrations, options)
789
- delete "orgs/#{org}/migrations/#{id}/archive", options
798
+ delete "#{Organization.path(org)}/migrations/#{id}/archive", options
790
799
  end
791
800
 
792
801
  # Unlock a previous migration archive.
@@ -796,10 +805,43 @@ module Octokit
796
805
  # @param org [String, Integer] Organization GitHub login or id.
797
806
  # @param id [Integer] ID number of the migration.
798
807
  # @param repo [String] Name of the repository.
799
- # @see https://developer.github.com/v3/orgs/migrations/#unlock-a-repository
808
+ # @see https://docs.github.com/en/rest/reference/migrations#unlock-an-organization-repository
800
809
  def unlock_repository(org, id, repo, options = {})
801
- options = ensure_api_media_type(:migrations, options)
802
- delete "orgs/#{org}/migrations/#{id}/repos/#{repo}/lock", options
810
+ delete "#{Organization.path(org)}/migrations/#{id}/repos/#{repo}/lock", options
811
+ end
812
+
813
+ # Get GitHub Actions billing for an organization
814
+ #
815
+ # Requires authenticated organization owner.
816
+ #
817
+ # @param org [String, Integer] Organization GitHub login or id.
818
+ # @return [Sawyer::Resource] Hash representing GitHub Actions billing for an organization.
819
+ # @see https://docs.github.com/en/rest/reference/billing#get-github-actions-billing-for-an-organization
820
+ #
821
+ # @example
822
+ # @client.billing_actions('github')
823
+ def billing_actions(org)
824
+ get "#{Organization.path(org)}/settings/billing/actions"
825
+ end
826
+
827
+ # Get organization audit log.
828
+ #
829
+ # Gets the audit log for an organization.
830
+ #
831
+ # @param org [String, Integer] Organization GitHub login or id for which
832
+ # to retrieve the audit log.
833
+ # @option options [String] :include ('all') Filter by event type.
834
+ # `all`, `git` or `web`.
835
+ # @option options [String] :phrase A search phrase.
836
+ # @option options [String] :order ('desc') The order of audit log events. To list newest events first, specify desc.
837
+ # To list oldest events first, specify asc.
838
+ #
839
+ # @return [Array<Sawyer::Resource>] List of events
840
+ # @see https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs#get-the-audit-log-for-an-organization
841
+ # @example
842
+ # Octokit.organization_audit_log('github', {include: 'all', phrase: 'action:org.add_member created:>2022-08-29 user:octocat'})
843
+ def organization_audit_log(org, options = {})
844
+ paginate "#{Organization.path org}/audit-log", options
803
845
  end
804
846
  end
805
847
  end