octokit 4.21.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +120 -96
  3. data/Rakefile +20 -14
  4. data/lib/ext/sawyer/relation.rb +4 -2
  5. data/lib/octokit/arguments.rb +3 -3
  6. data/lib/octokit/authentication.rb +10 -3
  7. data/lib/octokit/client/actions_artifacts.rb +71 -0
  8. data/lib/octokit/client/actions_secrets.rb +111 -8
  9. data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
  10. data/lib/octokit/client/actions_workflow_runs.rb +23 -3
  11. data/lib/octokit/client/actions_workflows.rb +27 -2
  12. data/lib/octokit/client/apps.rb +63 -74
  13. data/lib/octokit/client/checks.rb +18 -9
  14. data/lib/octokit/client/code_scanning.rb +190 -0
  15. data/lib/octokit/client/codespaces_secrets.rb +108 -0
  16. data/lib/octokit/client/commit_branches.rb +2 -2
  17. data/lib/octokit/client/commit_comments.rb +8 -8
  18. data/lib/octokit/client/commit_pulls.rb +2 -2
  19. data/lib/octokit/client/commits.rb +31 -34
  20. data/lib/octokit/client/community_profile.rb +2 -3
  21. data/lib/octokit/client/contents.rb +19 -22
  22. data/lib/octokit/client/dependabot_secrets.rb +108 -0
  23. data/lib/octokit/client/deployments.rb +8 -8
  24. data/lib/octokit/client/downloads.rb +5 -6
  25. data/lib/octokit/client/emojis.rb +3 -3
  26. data/lib/octokit/client/environments.rb +58 -0
  27. data/lib/octokit/client/events.rb +4 -5
  28. data/lib/octokit/client/feeds.rb +4 -5
  29. data/lib/octokit/client/gists.rb +6 -6
  30. data/lib/octokit/client/gitignore.rb +3 -3
  31. data/lib/octokit/client/hooks.rb +9 -19
  32. data/lib/octokit/client/issues.rb +14 -15
  33. data/lib/octokit/client/labels.rb +10 -10
  34. data/lib/octokit/client/legacy_search.rb +3 -3
  35. data/lib/octokit/client/licenses.rb +3 -6
  36. data/lib/octokit/client/markdown.rb +3 -3
  37. data/lib/octokit/client/marketplace.rb +4 -4
  38. data/lib/octokit/client/meta.rb +4 -5
  39. data/lib/octokit/client/milestones.rb +5 -5
  40. data/lib/octokit/client/notifications.rb +6 -6
  41. data/lib/octokit/client/oauth_applications.rb +1 -7
  42. data/lib/octokit/client/objects.rb +14 -14
  43. data/lib/octokit/client/organizations.rb +106 -62
  44. data/lib/octokit/client/pages.rb +5 -7
  45. data/lib/octokit/client/projects.rb +44 -64
  46. data/lib/octokit/client/pull_requests.rb +66 -45
  47. data/lib/octokit/client/rate_limit.rb +9 -11
  48. data/lib/octokit/client/reactions.rb +78 -16
  49. data/lib/octokit/client/refs.rb +15 -18
  50. data/lib/octokit/client/releases.rb +13 -13
  51. data/lib/octokit/client/repositories.rb +92 -69
  52. data/lib/octokit/client/repository_invitations.rb +3 -3
  53. data/lib/octokit/client/reviews.rb +8 -8
  54. data/lib/octokit/client/say.rb +4 -5
  55. data/lib/octokit/client/search.rb +24 -10
  56. data/lib/octokit/client/service_status.rb +19 -9
  57. data/lib/octokit/client/source_import.rb +7 -12
  58. data/lib/octokit/client/stats.rb +10 -9
  59. data/lib/octokit/client/statuses.rb +5 -5
  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 +54 -33
  63. data/lib/octokit/client.rb +44 -20
  64. data/lib/octokit/configurable.rb +51 -31
  65. data/lib/octokit/connection.rb +33 -24
  66. data/lib/octokit/default.rb +66 -35
  67. data/lib/octokit/enterprise_admin_client/admin_stats.rb +13 -14
  68. data/lib/octokit/enterprise_admin_client/license.rb +3 -4
  69. data/lib/octokit/enterprise_admin_client/orgs.rb +3 -4
  70. data/lib/octokit/enterprise_admin_client/search_indexing.rb +7 -8
  71. data/lib/octokit/enterprise_admin_client/users.rb +5 -4
  72. data/lib/octokit/enterprise_admin_client.rb +9 -3
  73. data/lib/octokit/enterprise_management_console_client/management_console.rb +51 -33
  74. data/lib/octokit/enterprise_management_console_client.rb +8 -2
  75. data/lib/octokit/error.rb +53 -34
  76. data/lib/octokit/gist.rb +3 -4
  77. data/lib/octokit/manage_ghes_client/manage_ghes.rb +178 -0
  78. data/lib/octokit/manage_ghes_client.rb +64 -0
  79. data/lib/octokit/middleware/follow_redirects.rb +16 -12
  80. data/lib/octokit/organization.rb +3 -1
  81. data/lib/octokit/rate_limit.rb +8 -6
  82. data/lib/octokit/repo_arguments.rb +3 -4
  83. data/lib/octokit/repository.rb +32 -25
  84. data/lib/octokit/response/base_middleware.rb +10 -0
  85. data/lib/octokit/response/feed_parser.rb +5 -7
  86. data/lib/octokit/response/raise_error.rb +4 -4
  87. data/lib/octokit/user.rb +4 -2
  88. data/lib/octokit/version.rb +4 -2
  89. data/lib/octokit/warnable.rb +4 -5
  90. data/lib/octokit.rb +30 -8
  91. data/octokit.gemspec +12 -11
  92. metadata +22 -34
  93. data/lib/octokit/client/authorizations.rb +0 -182
  94. data/lib/octokit/client/pub_sub_hubbub.rb +0 -111
  95. data/lib/octokit/preview.rb +0 -46
@@ -1,60 +1,52 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the Apps API
5
6
  module Apps
6
-
7
7
  # Get the authenticated App
8
8
  #
9
9
  # @param options [Hash] A customizable set of options
10
10
  #
11
- # @see https://developer.github.com/v3/apps/#get-the-authenticated-app
11
+ # @see https://docs.github.com/en/rest/apps/apps#get-the-authenticated-app
12
12
  #
13
13
  # @return [Sawyer::Resource] App information
14
14
  def app(options = {})
15
- get "app", options
15
+ get 'app', options
16
16
  end
17
17
 
18
- # Find all installations that belong to an App
18
+ # List all installations that belong to an App
19
19
  #
20
20
  # @param options [Hash] A customizable set of options
21
21
  #
22
- # @see https://developer.github.com/v3/apps/#list-installations
22
+ # @see https://docs.github.com/en/rest/apps/apps#list-installations-for-the-authenticated-app
23
23
  #
24
24
  # @return [Array<Sawyer::Resource>] the total_count and an array of installations
25
- def find_app_installations(options = {})
26
- paginate "app/installations", options
27
- end
28
- alias find_installations find_app_installations
29
-
30
- def find_integration_installations(options = {})
31
- octokit_warn(
32
- "Deprecated: Octokit::Client::Apps#find_integration_installations "\
33
- "method is deprecated. Please update your call to use "\
34
- "Octokit::Client::Apps#find_app_installations before the next major "\
35
- "Octokit version update."
36
- )
37
- find_app_installations(options)
25
+ def list_app_installations(options = {})
26
+ paginate 'app/installations', options
38
27
  end
28
+ alias find_installations list_app_installations
29
+ alias find_app_installations list_app_installations
39
30
 
40
- # Find all installations that are accessible to the authenticated user
31
+ # List all installations that are accessible to the authenticated user
41
32
  #
42
33
  # @param options [Hash] A customizable set of options
43
34
  #
44
- # @see https://developer.github.com/v3/apps/installations/#list-installations-for-a-user
35
+ # @see https://docs.github.com/en/rest/apps/installations#list-app-installations-accessible-to-the-user-access-token
45
36
  #
46
37
  # @return [Sawyer::Resource] the total_count and an array of installations
47
- def find_user_installations(options = {})
48
- paginate("user/installations", options) do |data, last_response|
38
+ def list_user_installations(options = {})
39
+ paginate('user/installations', options) do |data, last_response|
49
40
  data.installations.concat last_response.data.installations
50
41
  end
51
42
  end
43
+ alias find_user_installations list_user_installations
52
44
 
53
45
  # Get a single installation
54
46
  #
55
47
  # @param id [Integer] Installation id
56
48
  #
57
- # @see https://developer.github.com/v3/apps/#get-an-installation
49
+ # @see https://docs.github.com/en/rest/apps/apps#get-an-installation-for-the-authenticated-app
58
50
  #
59
51
  # @return [Sawyer::Resource] Installation information
60
52
  def installation(id, options = {})
@@ -66,7 +58,7 @@ module Octokit
66
58
  # @param installation [Integer] The id of a GitHub App Installation
67
59
  # @param options [Hash] A customizable set of options
68
60
  #
69
- # @see https://developer.github.com/v3/apps/#create-a-new-installation-token
61
+ # @see https://docs.github.com/en/rest/apps/apps#create-an-installation-access-token-for-an-app
70
62
  #
71
63
  # @return [<Sawyer::Resource>] An installation token
72
64
  def create_app_installation_access_token(installation, options = {})
@@ -74,22 +66,12 @@ module Octokit
74
66
  end
75
67
  alias create_installation_access_token create_app_installation_access_token
76
68
 
77
- def create_integration_installation_access_token(installation, options = {})
78
- octokit_warn(
79
- "Deprecated: Octokit::Client::Apps#create_integration_installation_access_token "\
80
- "method is deprecated. Please update your call to use "\
81
- "Octokit::Client::Apps#create_app_installation_access_token before the next major "\
82
- "Octokit version update."
83
- )
84
- create_app_installation_access_token(installation, options)
85
- end
86
-
87
69
  # Enables an app to find the organization's installation information.
88
70
  #
89
71
  # @param organization [String] Organization GitHub login
90
72
  # @param options [Hash] A customizable set of options
91
73
  #
92
- # @see https://developer.github.com/v3/apps/#get-an-organization-installation
74
+ # @see https://docs.github.com/en/rest/apps/apps#get-an-organization-installation-for-the-authenticated-app
93
75
  #
94
76
  # @return [Sawyer::Resource] Installation information
95
77
  def find_organization_installation(organization, options = {})
@@ -101,7 +83,7 @@ module Octokit
101
83
  # @param repo [String] A GitHub repository
102
84
  # @param options [Hash] A customizable set of options
103
85
  #
104
- # @see https://developer.github.com/v3/apps/#get-a-repository-installation
86
+ # @see https://docs.github.com/en/rest/apps/apps#get-a-repository-installation-for-the-authenticated-app
105
87
  #
106
88
  # @return [Sawyer::Resource] Installation information
107
89
  def find_repository_installation(repo, options = {})
@@ -113,7 +95,7 @@ module Octokit
113
95
  # @param user [String] GitHub user login
114
96
  # @param options [Hash] A customizable set of options
115
97
  #
116
- # @see https://developer.github.com/v3/apps/#get-a-user-installation
98
+ # @see https://docs.github.com/en/rest/apps/apps#get-a-user-installation-for-the-authenticated-app
117
99
  #
118
100
  # @return [Sawyer::Resource] Installation information
119
101
  def find_user_installation(user, options = {})
@@ -124,33 +106,23 @@ module Octokit
124
106
  #
125
107
  # @param options [Hash] A customizable set of options
126
108
  #
127
- # @see https://developer.github.com/v3/apps/installations/#list-repositories
109
+ # @see https://docs.github.com/en/rest/apps/installations#list-repositories-accessible-to-the-app-installation
128
110
  #
129
111
  # @return [Sawyer::Resource] the total_count and an array of repositories
130
112
  def list_app_installation_repositories(options = {})
131
- paginate("installation/repositories", options) do |data, last_response|
113
+ paginate('installation/repositories', options) do |data, last_response|
132
114
  data.repositories.concat last_response.data.repositories
133
115
  end
134
116
  end
135
117
  alias list_installation_repos list_app_installation_repositories
136
118
 
137
- def list_integration_installation_repositories(options = {})
138
- octokit_warn(
139
- "Deprecated: Octokit::Client::Apps#list_integration_installation_repositories "\
140
- "method is deprecated. Please update your call to use "\
141
- "Octokit::Client::Apps#list_app_installation_repositories before the next major "\
142
- "Octokit version update."
143
- )
144
- list_app_installation_repositories(options)
145
- end
146
-
147
119
  # Add a single repository to an installation
148
120
  #
149
121
  # @param installation [Integer] The id of a GitHub App Installation
150
122
  # @param repo [Integer] The id of the GitHub repository
151
123
  # @param options [Hash] A customizable set of options
152
124
  #
153
- # @see https://developer.github.com/v3/apps/installations/#add-repository-to-installation
125
+ # @see https://docs.github.com/en/rest/apps/installations#add-a-repository-to-an-app-installation
154
126
  #
155
127
  # @return [Boolean] Success
156
128
  def add_repository_to_app_installation(installation, repo, options = {})
@@ -158,23 +130,13 @@ module Octokit
158
130
  end
159
131
  alias add_repo_to_installation add_repository_to_app_installation
160
132
 
161
- def add_repository_to_integration_installation(installation, repo, options = {})
162
- octokit_warn(
163
- "Deprecated: Octokit::Client::Apps#add_repository_to_integration_installation "\
164
- "method is deprecated. Please update your call to use "\
165
- "Octokit::Client::Apps#add_repository_to_app_installation before the next major "\
166
- "Octokit version update."
167
- )
168
- add_repository_to_app_installation(installation, repo, options)
169
- end
170
-
171
133
  # Remove a single repository to an installation
172
134
  #
173
135
  # @param installation [Integer] The id of a GitHub App Installation
174
136
  # @param repo [Integer] The id of the GitHub repository
175
137
  # @param options [Hash] A customizable set of options
176
138
  #
177
- # @see https://developer.github.com/v3/apps/installations/#remove-repository-from-installation
139
+ # @see https://docs.github.com/en/rest/apps/installations#remove-a-repository-from-an-app-installation
178
140
  #
179
141
  # @return [Boolean] Success
180
142
  def remove_repository_from_app_installation(installation, repo, options = {})
@@ -182,22 +144,12 @@ module Octokit
182
144
  end
183
145
  alias remove_repo_from_installation remove_repository_from_app_installation
184
146
 
185
- def remove_repository_from_integration_installation(installation, repo, options = {})
186
- octokit_warn(
187
- "Deprecated: Octokit::Client::Apps#remove_repository_from_integration_installation "\
188
- "method is deprecated. Please update your call to use "\
189
- "Octokit::Client::Apps#remove_repository_from_app_installation before the next major "\
190
- "Octokit version update."
191
- )
192
- remove_repository_from_app_installation(installation, repo, options)
193
- end
194
-
195
147
  # List repositories accessible to the user for an installation
196
148
  #
197
149
  # @param installation [Integer] The id of a GitHub App Installation
198
150
  # @param options [Hash] A customizable set of options
199
151
  #
200
- # @see https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-user-for-an-installation
152
+ # @see https://docs.github.com/en/rest/apps/installations#list-repositories-accessible-to-the-user-access-token
201
153
  #
202
154
  # @return [Sawyer::Resource] the total_count and an array of repositories
203
155
  def find_installation_repositories_for_user(installation, options = {})
@@ -211,12 +163,49 @@ module Octokit
211
163
  # @param installation [Integer] The id of a GitHub App Installation
212
164
  # @param options [Hash] A customizable set of options
213
165
  #
214
- # @see https://developer.github.com/v3/apps/#delete-an-installation
166
+ # @see https://docs.github.com/en/rest/apps/apps#delete-an-installation-for-the-authenticated-app
215
167
  #
216
168
  # @return [Boolean] Success
217
169
  def delete_installation(installation, options = {})
218
170
  boolean_from_response :delete, "app/installations/#{installation}", options
219
171
  end
172
+
173
+ # Returns a list of webhook deliveries for the webhook configured for a GitHub App.
174
+ #
175
+ # @param options [Hash] A customizable set of options
176
+ #
177
+ # @see https://docs.github.com/en/rest/apps/webhooks#list-deliveries-for-an-app-webhook
178
+ #
179
+ # @return [Array<Hash>] an array of hook deliveries
180
+ def list_app_hook_deliveries(options = {})
181
+ paginate('app/hook/deliveries', options) do |data, last_response|
182
+ data.concat last_response.data
183
+ end
184
+ end
185
+
186
+ # Returns a delivery for the webhook configured for a GitHub App.
187
+ #
188
+ # @param delivery_id [String] The id of a GitHub App Hook Delivery
189
+ # @param options [Hash] A customizable set of options
190
+ #
191
+ # @see https://docs.github.com/en/rest/apps/webhooks#get-a-delivery-for-an-app-webhook
192
+ #
193
+ # @return [<Sawyer::Resource>] The webhook delivery
194
+ def app_hook_delivery(delivery_id, options = {})
195
+ get "/app/hook/deliveries/#{delivery_id}", options
196
+ end
197
+
198
+ # Redeliver a delivery for the webhook configured for a GitHub App.
199
+ #
200
+ # @param delivery_id [Integer] The id of a GitHub App Hook Delivery
201
+ # @param options [Hash] A customizable set of options
202
+ #
203
+ # @see https://docs.github.com/en/rest/apps/webhooks#redeliver-a-delivery-for-an-app-webhook
204
+ #
205
+ # @return [Boolean] Success
206
+ def deliver_app_hook(delivery_id, options = {})
207
+ boolean_from_response :post, "app/hook/deliveries/#{delivery_id}/attempts", options
208
+ end
220
209
  end
221
210
  end
222
211
  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 Checks API
5
6
  #
6
7
  # @see https://developer.github.com/v3/checks/
7
8
  module Checks
8
-
9
9
  # Methods for Check Runs
10
10
  #
11
11
  # @see https://developer.github.com/v3/checks/runs/
@@ -60,9 +60,12 @@ module Octokit
60
60
  # result.check_runs[0].id # => 51295429
61
61
  # result.check_runs[0].status # => "in_progress"
62
62
  def check_runs_for_ref(repo, ref, options = {})
63
- get "#{Repository.path repo}/commits/#{ref}/check-runs", options
63
+ paginate "#{Repository.path repo}/commits/#{ref}/check-runs", options do |data, last_response|
64
+ data.check_runs.concat last_response.data.check_runs
65
+ data.total_count += last_response.data.total_count
66
+ end
64
67
  end
65
- alias :list_check_runs_for_ref :check_runs_for_ref
68
+ alias list_check_runs_for_ref check_runs_for_ref
66
69
 
67
70
  # List check runs in a check suite
68
71
  #
@@ -81,9 +84,12 @@ module Octokit
81
84
  # result.check_runs[0].check_suite.id # => 50440400
82
85
  # result.check_runs[0].status # => "in_progress"
83
86
  def check_runs_for_check_suite(repo, id, options = {})
84
- get "#{Repository.path repo}/check-suites/#{id}/check-runs", options
87
+ paginate "#{Repository.path repo}/check-suites/#{id}/check-runs", options do |data, last_response|
88
+ data.check_runs.concat last_response.data.check_runs
89
+ data.total_count += last_response.data.total_count
90
+ end
85
91
  end
86
- alias :list_check_runs_for_check_suite :check_runs_for_check_suite
92
+ alias list_check_runs_for_check_suite check_runs_for_check_suite
87
93
 
88
94
  # Get a single check run
89
95
  #
@@ -107,7 +113,7 @@ module Octokit
107
113
  # annotations[0].path # => "README.md"
108
114
  # annotations[0].message # => "Looks good!"
109
115
  def check_run_annotations(repo, id, options = {})
110
- get "#{Repository.path repo}/check-runs/#{id}/annotations", options
116
+ paginate "#{Repository.path repo}/check-runs/#{id}/annotations", options
111
117
  end
112
118
 
113
119
  # Methods for Check Suites
@@ -140,9 +146,12 @@ module Octokit
140
146
  # result.check_suites[0].id # => 50440400
141
147
  # result.check_suites[0].app.id # => 76765
142
148
  def check_suites_for_ref(repo, ref, options = {})
143
- get "#{Repository.path repo}/commits/#{ref}/check-suites", options
149
+ paginate "#{Repository.path repo}/commits/#{ref}/check-suites", options do |data, last_response|
150
+ data.check_suites.concat last_response.data.check_suites
151
+ data.total_count += last_response.data.total_count
152
+ end
144
153
  end
145
- alias :list_check_suites_for_ref :check_suites_for_ref
154
+ alias list_check_suites_for_ref check_suites_for_ref
146
155
 
147
156
  # Set preferences for check suites on a repository
148
157
  #
@@ -0,0 +1,190 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+ require 'zlib'
5
+
6
+ module Octokit
7
+ class Client
8
+ # Methods for the code scanning alerts API
9
+ #
10
+ # @see https://docs.github.com/rest/code-scanning
11
+ module CodeScanning
12
+ # Updates a code scanning default setup configuration
13
+ #
14
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
15
+ # @param state [String] The desired state of code scanning default setup
16
+ # @param query_suite [String] CodeQL query suite to be used
17
+ # @param languages [Array] List of CodeQL languages to be analyzed
18
+ #
19
+ # @return [Sawyer::Resource] Action Run information
20
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#update-a-code-scanning-default-setup-configuration
21
+ def update_code_scanning_default_config(repo, state, query_suite = nil, languages = nil, options = {})
22
+ options[:state] = state
23
+ options[:query_suite] = query_suite if query_suite
24
+ options[:languages] = languages if languages
25
+
26
+ patch "#{Repository.path repo}/code-scanning/default-setup", options
27
+ end
28
+
29
+ # Get Code Scanning Default Configuration
30
+ #
31
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
32
+ #
33
+ # @return [Sawyer::Resource] CodeQl Default Setup Configuration Information
34
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#get-a-code-scanning-default-setup-configuration
35
+ def get_code_scanning_default_config(repo, options = {})
36
+ get "#{Repository.path repo}/code-scanning/default-setup", options
37
+ end
38
+
39
+ # Gets a CodeQL database for a language in a repository
40
+ #
41
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
42
+ # @param language [String]
43
+ #
44
+ # @return [Sawyer::Resource] CodeQl Default Setup Configuration Information
45
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#get-a-codeql-database-for-a-repository
46
+ def get_codeql_database_for_repo(repo, language, options = {})
47
+ get "#{Repository.path repo}/code-scanning/codeql/databases/#{language}", options
48
+ end
49
+
50
+ # Lists the CodeQL databases that are available in a repository
51
+ #
52
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
53
+ #
54
+ # @return [Array] List of CodeQL Databases
55
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#list-codeql-databases-for-a-repository
56
+ def list_codeql_database_for_repo(repo, options = {})
57
+ get "#{Repository.path repo}/code-scanning/codeql/databases", options
58
+ end
59
+
60
+ # Delete a specified code scanning analysis from a repository
61
+ #
62
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
63
+ # @param analysis_id [Integer] ID of the code scanning analysis
64
+ #
65
+ # @return [Sawyer::Resource] Next Code Scanning Analysis Information
66
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#delete-a-code-scanning-analysis-from-a-repository
67
+ def delete_code_scanning_analysis(repo, analysis_id, options = {})
68
+ delete "#{Repository.path repo}/code-scanning/analyses/#{analysis_id}", options
69
+ end
70
+
71
+ # Get a code scanning analysis for a repository
72
+ #
73
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
74
+ # @param analysis_id [Integer] ID of the code scanning analysis
75
+ #
76
+ # @return [Sawyer::Resource] Code Scanning Analysis
77
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#get-a-code-scanning-analysis-for-a-repository
78
+ def get_code_scanning_analysis(repo, analysis_id, options = {})
79
+ get "#{Repository.path repo}/code-scanning/analyses/#{analysis_id}", options
80
+ end
81
+
82
+ # List code scanning analyses for a repository
83
+ #
84
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
85
+ #
86
+ # @return [Array] List of Code Scanning Analyses
87
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#list-code-scanning-analyses-for-a-repository
88
+ def list_code_scanning_analysis(repo, options = {})
89
+ paginate "#{Repository.path repo}/code-scanning/analyses", options
90
+ end
91
+
92
+ # List instances of a code scanning alert
93
+ #
94
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
95
+ # @param alert_number [Integer] The number that identifies an alert
96
+ #
97
+ # @return [Array] List of Code Scanning Alerts
98
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#list-instances-of-a-code-scanning-alert
99
+ def list_instances_of_code_scanning_alert(repo, alert_number, options = {})
100
+ paginate "#{Repository.path repo}/code-scanning/alerts/#{alert_number}/instances", options
101
+ end
102
+
103
+ # Update a code scanning alert
104
+ #
105
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
106
+ # @param alert_number [Integer] The number that identifies an alert
107
+ # @param state [String] The reason for dismissing or closing the alert. Required when the state is dismissed
108
+ #
109
+ # @return [Sawyer::Resource] Code Scanning Alert information
110
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#update-a-code-scanning-alert
111
+ def update_code_scanning_alert(repo, alert_number, state, reason, comment = nil, options = {})
112
+ options[:state] = state
113
+ options[:dismissed_reason] = reason
114
+ options[:dismissed_comment] = comment if comment
115
+
116
+ patch "#{Repository.path repo}/code-scanning/alerts/#{alert_number}", options
117
+ end
118
+
119
+ # Gets a single code scanning alert
120
+ #
121
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
122
+ # @param alert_number [Integer] The number that identifies an alert
123
+ #
124
+ # @return [Sawyer::Resource] Code Scanning Alert
125
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#get-a-code-scanning-alert
126
+ def get_code_scanning_alert(repo, alert_number, options = {})
127
+ get "#{Repository.path repo}/code-scanning/alerts/#{alert_number}", options
128
+ end
129
+
130
+ # List code scanning alerts for a repository
131
+ #
132
+ # @param org [String] A GitHub organization
133
+ #
134
+ # @return [Array] Code Scanning Alert information
135
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#list-code-scanning-alerts-for-a-repository
136
+ def list_code_scanning_alerts_for_repo(repo, options = {})
137
+ paginate "#{Repository.path repo}/code-scanning/alerts", options
138
+ end
139
+
140
+ # List code scanning alerts for an organization
141
+ #
142
+ # @param org [String] A GitHub organization
143
+ #
144
+ # @return [Array] Code Scanning Alert information
145
+ # @see https://docs.github.com/en/rest/code-scanning/code-scanning#list-code-scanning-alerts-for-an-organization
146
+ def list_code_scanning_alerts_for_org(org, options = {})
147
+ paginate "orgs/#{org}/code-scanning/alerts", options
148
+ end
149
+
150
+ # Uploads SARIF data containing the results of a code scanning analysis
151
+ #
152
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
153
+ # @param file [String] Path to the SARIF file to upload
154
+ # @param sha [String] The SHA of the commit to which the analysis you are uploading relates
155
+ # @param ref [String] The full Git reference, formatted as `refs/heads/<branch name>`, `refs/pull/<number>/merge`, or `refs/pull/<number>/head`
156
+ #
157
+ # @return [Sawyer::Resource] SARIF upload information
158
+ # @see https://docs.github.com/rest/code-scanning#upload-an-analysis-as-sarif-data
159
+ def upload_sarif_data(repo, file, sha, ref, options = {})
160
+ options[:sarif] = compress_sarif_data(file)
161
+ options[:commit_sha] = sha
162
+ options[:ref] = ref
163
+
164
+ post "#{Repository.path repo}/code-scanning/sarifs", options
165
+ end
166
+
167
+ # Gets information about a SARIF upload
168
+ #
169
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
170
+ # @param sarif_id [String] The SARIF ID obtained after uploading
171
+ #
172
+ # @return [Sawyer::Resource] SARIF upload information
173
+ # @see https://docs.github.com/rest/code-scanning#get-information-about-a-sarif-upload
174
+ def get_sarif_upload_information(repo, sarif_id, options = {})
175
+ get "#{Repository.path repo}/code-scanning/sarifs/#{sarif_id}", options
176
+ end
177
+
178
+ private
179
+
180
+ def compress_sarif_data(file)
181
+ Tempfile.create('sarif.gz') do |tempfile|
182
+ Zlib::GzipWriter.open(tempfile) do |gz_file|
183
+ gz_file.write File.binread(file)
184
+ end
185
+ [tempfile.read].pack('m0') # Base64.strict_encode64
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the Codespaces Secrets API
6
+ #
7
+ # @see https://docs.github.com/en/rest/codespaces/
8
+ module CodespacesSecrets
9
+ # Get public key for secrets encryption
10
+ #
11
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
12
+ # @return [Hash] key_id and key
13
+ # @see https://docs.github.com/en/rest/codespaces/repository-secrets#get-a-repository-public-key
14
+ def get_codespaces_public_key(repo)
15
+ get "#{Repository.path repo}/codespaces/secrets/public-key"
16
+ end
17
+
18
+ # Get public key for secrets encryption
19
+ #
20
+ # @param org [String] A GitHub organization
21
+ # @return [Hash] key_id and key
22
+ # @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#get-an-organization-public-key
23
+ def get_org_codespaces_public_key(org)
24
+ get "#{Organization.path org}/codespaces/secrets/public-key"
25
+ end
26
+
27
+ # List secrets
28
+ #
29
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
30
+ # @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
31
+ # @see https://docs.github.com/en/rest/codespaces/repository-secrets?apiVersion=2022-11-28#list-repository-secrets
32
+ def list_codespaces_secrets(repo)
33
+ paginate "#{Repository.path repo}/codespaces/secrets" do |data, last_response|
34
+ data.secrets.concat last_response.data.secrets
35
+ end
36
+ end
37
+
38
+ # List org secrets
39
+ #
40
+ # @param org [String] A GitHub organization
41
+ # @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
42
+ # @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#list-organization-secrets
43
+ def list_org_codespaces_secrets(org)
44
+ paginate "#{Organization.path org}/codespaces/secrets" do |data, last_response|
45
+ data.secrets.concat last_response.data.secrets
46
+ end
47
+ end
48
+
49
+ # Get a secret
50
+ #
51
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
52
+ # @param name [String] Name of secret
53
+ # @return [Hash] name, created_at, updated_at, and visibility
54
+ # @see https://docs.github.com/en/rest/codespaces/repository-secrets?apiVersion=2022-11-28#get-a-repository-secret
55
+ def get_codespaces_secret(repo, name)
56
+ get "#{Repository.path repo}/codespaces/secrets/#{name}"
57
+ end
58
+
59
+ # Get an org secret
60
+ #
61
+ # @param org [String] A GitHub organization
62
+ # @param name [String] Name of secret
63
+ # @return [Hash] name, created_at, updated_at, and visibility
64
+ # @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#get-an-organization-secret
65
+ def get_org_codespaces_secret(org, name)
66
+ get "#{Organization.path org}/codespaces/secrets/#{name}"
67
+ end
68
+
69
+ # Create or update secrets
70
+ #
71
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
72
+ # @param name [String] Name of secret
73
+ # @param options [Hash] encrypted_value and key_id
74
+ # @see https://docs.github.com/en/rest/codespaces/repository-secrets?apiVersion=2022-11-28#create-or-update-a-repository-secret
75
+ def create_or_update_codespaces_secret(repo, name, options)
76
+ put "#{Repository.path repo}/codespaces/secrets/#{name}", options
77
+ end
78
+
79
+ # Create or update org secrets
80
+ #
81
+ # @param org [String] A GitHub organization
82
+ # @param name [String] Name of secret
83
+ # @param options [Hash] encrypted_value and key_id
84
+ # @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
85
+ def create_or_update_org_codespaces_secret(org, name, options)
86
+ put "#{Organization.path org}/codespaces/secrets/#{name}", options
87
+ end
88
+
89
+ # Delete a secret
90
+ #
91
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
92
+ # @param name [String] Name of secret
93
+ # @see https://docs.github.com/en/rest/codespaces/repository-secrets?apiVersion=2022-11-28#delete-a-repository-secret
94
+ def delete_codespaces_secret(repo, name)
95
+ boolean_from_response :delete, "#{Repository.path repo}/codespaces/secrets/#{name}"
96
+ end
97
+
98
+ # Delete an org secret
99
+ #
100
+ # @param org [String] A GitHub organization
101
+ # @param name [String] Name of secret
102
+ # @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#delete-an-organization-secret
103
+ def delete_org_codespaces_secret(org, name)
104
+ boolean_from_response :delete, "#{Organization.path org}/codespaces/secrets/#{name}"
105
+ end
106
+ end
107
+ end
108
+ 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 Branches for HEAD API
5
6
  #
6
7
  # @see https://developer.github.com/v3/repos/commits/
7
8
  module CommitBranches
8
-
9
9
  # List branches for a single HEAD commit
10
10
  #
11
11
  # @param repo [Integer, String, Hash, Repository] A GitHub repository