octokit 4.2.0 → 9.2.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.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +14 -13
- data/LICENSE.md +1 -1
- data/README.md +275 -127
- data/Rakefile +20 -14
- data/lib/ext/sawyer/relation.rb +12 -0
- data/lib/octokit/arguments.rb +3 -3
- data/lib/octokit/authentication.rb +20 -14
- data/lib/octokit/client/actions_artifacts.rb +71 -0
- data/lib/octokit/client/actions_secrets.rb +161 -0
- data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
- data/lib/octokit/client/actions_workflow_runs.rb +125 -0
- data/lib/octokit/client/actions_workflows.rb +68 -0
- data/lib/octokit/client/apps.rb +259 -0
- data/lib/octokit/client/checks.rb +200 -0
- data/lib/octokit/client/code_scanning.rb +190 -0
- data/lib/octokit/client/codespaces_secrets.rb +108 -0
- data/lib/octokit/client/commit_branches.rb +20 -0
- data/lib/octokit/client/commit_comments.rb +8 -8
- data/lib/octokit/client/commit_pulls.rb +20 -0
- data/lib/octokit/client/commits.rb +32 -35
- data/lib/octokit/client/community_profile.rb +21 -0
- data/lib/octokit/client/contents.rb +24 -21
- data/lib/octokit/client/dependabot_secrets.rb +108 -0
- data/lib/octokit/client/deployments.rb +29 -7
- data/lib/octokit/client/downloads.rb +5 -6
- data/lib/octokit/client/emojis.rb +3 -3
- data/lib/octokit/client/environments.rb +58 -0
- data/lib/octokit/client/events.rb +4 -4
- data/lib/octokit/client/feeds.rb +4 -5
- data/lib/octokit/client/gists.rb +36 -8
- data/lib/octokit/client/gitignore.rb +3 -3
- data/lib/octokit/client/hooks.rb +34 -30
- data/lib/octokit/client/issues.rb +97 -14
- data/lib/octokit/client/labels.rb +17 -17
- data/lib/octokit/client/legacy_search.rb +3 -3
- data/lib/octokit/client/licenses.rb +5 -8
- data/lib/octokit/client/markdown.rb +3 -3
- data/lib/octokit/client/marketplace.rb +56 -0
- data/lib/octokit/client/meta.rb +4 -5
- data/lib/octokit/client/milestones.rb +14 -14
- data/lib/octokit/client/notifications.rb +7 -11
- data/lib/octokit/client/oauth_applications.rb +116 -0
- data/lib/octokit/client/objects.rb +14 -14
- data/lib/octokit/client/organizations.rb +256 -73
- data/lib/octokit/client/pages.rb +26 -3
- data/lib/octokit/client/projects.rb +294 -0
- data/lib/octokit/client/pull_requests.rb +74 -51
- data/lib/octokit/client/rate_limit.rb +11 -13
- data/lib/octokit/client/reactions.rb +204 -0
- data/lib/octokit/client/refs.rb +34 -20
- data/lib/octokit/client/releases.rb +16 -13
- data/lib/octokit/client/repositories.rb +276 -60
- data/lib/octokit/client/repository_invitations.rb +96 -0
- data/lib/octokit/client/reviews.rb +227 -0
- data/lib/octokit/client/say.rb +4 -5
- data/lib/octokit/client/search.rb +46 -17
- data/lib/octokit/client/service_status.rb +19 -9
- data/lib/octokit/client/source_import.rb +156 -0
- data/lib/octokit/client/stats.rb +39 -17
- data/lib/octokit/client/statuses.rb +6 -6
- data/lib/octokit/client/tokens.rb +31 -0
- data/lib/octokit/client/traffic.rb +64 -0
- data/lib/octokit/client/users.rb +133 -25
- data/lib/octokit/client.rb +85 -19
- data/lib/octokit/configurable.rb +60 -32
- data/lib/octokit/connection.rb +45 -21
- data/lib/octokit/default.rb +82 -35
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +14 -15
- data/lib/octokit/enterprise_admin_client/license.rb +4 -5
- data/lib/octokit/enterprise_admin_client/orgs.rb +7 -6
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +8 -9
- data/lib/octokit/enterprise_admin_client/users.rb +19 -18
- data/lib/octokit/enterprise_admin_client.rb +11 -3
- data/lib/octokit/enterprise_management_console_client/management_console.rb +52 -34
- data/lib/octokit/enterprise_management_console_client.rb +9 -3
- data/lib/octokit/error.rb +144 -26
- data/lib/octokit/gist.rb +4 -5
- data/lib/octokit/manage_ghes_client/manage_ghes.rb +178 -0
- data/lib/octokit/manage_ghes_client.rb +64 -0
- data/lib/octokit/middleware/follow_redirects.rb +18 -14
- data/lib/octokit/organization.rb +3 -1
- data/lib/octokit/rate_limit.rb +11 -9
- data/lib/octokit/repo_arguments.rb +3 -4
- data/lib/octokit/repository.rb +35 -23
- data/lib/octokit/response/base_middleware.rb +10 -0
- data/lib/octokit/response/feed_parser.rb +5 -9
- data/lib/octokit/response/raise_error.rb +4 -6
- data/lib/octokit/user.rb +4 -2
- data/lib/octokit/version.rb +3 -1
- data/lib/octokit/warnable.rb +4 -5
- data/lib/octokit.rb +30 -8
- data/octokit.gemspec +12 -10
- metadata +47 -24
- data/lib/octokit/client/authorizations.rb +0 -256
- data/lib/octokit/client/pub_sub_hubbub.rb +0 -111
- data/lib/octokit/preview.rb +0 -28
@@ -0,0 +1,259 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Octokit
|
4
|
+
class Client
|
5
|
+
# Methods for the Apps API
|
6
|
+
module Apps
|
7
|
+
# Get the authenticated App
|
8
|
+
#
|
9
|
+
# @param options [Hash] A customizable set of options
|
10
|
+
#
|
11
|
+
# @see https://developer.github.com/v3/apps/#get-the-authenticated-app
|
12
|
+
#
|
13
|
+
# @return [Sawyer::Resource] App information
|
14
|
+
def app(options = {})
|
15
|
+
get 'app', options
|
16
|
+
end
|
17
|
+
|
18
|
+
# Find all installations that belong to an App
|
19
|
+
#
|
20
|
+
# @param options [Hash] A customizable set of options
|
21
|
+
#
|
22
|
+
# @see https://developer.github.com/v3/apps/#list-installations
|
23
|
+
#
|
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)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Find all installations that are accessible to the authenticated user
|
41
|
+
#
|
42
|
+
# @param options [Hash] A customizable set of options
|
43
|
+
#
|
44
|
+
# @see https://developer.github.com/v3/apps/installations/#list-installations-for-a-user
|
45
|
+
#
|
46
|
+
# @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|
|
49
|
+
data.installations.concat last_response.data.installations
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Get a single installation
|
54
|
+
#
|
55
|
+
# @param id [Integer] Installation id
|
56
|
+
#
|
57
|
+
# @see https://developer.github.com/v3/apps/#get-an-installation
|
58
|
+
#
|
59
|
+
# @return [Sawyer::Resource] Installation information
|
60
|
+
def installation(id, options = {})
|
61
|
+
get "app/installations/#{id}", options
|
62
|
+
end
|
63
|
+
|
64
|
+
# Create a new installation token
|
65
|
+
#
|
66
|
+
# @param installation [Integer] The id of a GitHub App Installation
|
67
|
+
# @param options [Hash] A customizable set of options
|
68
|
+
#
|
69
|
+
# @see https://developer.github.com/v3/apps/#create-a-new-installation-token
|
70
|
+
#
|
71
|
+
# @return [<Sawyer::Resource>] An installation token
|
72
|
+
def create_app_installation_access_token(installation, options = {})
|
73
|
+
post "app/installations/#{installation}/access_tokens", options
|
74
|
+
end
|
75
|
+
alias create_installation_access_token create_app_installation_access_token
|
76
|
+
|
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
|
+
# Enables an app to find the organization's installation information.
|
88
|
+
#
|
89
|
+
# @param organization [String] Organization GitHub login
|
90
|
+
# @param options [Hash] A customizable set of options
|
91
|
+
#
|
92
|
+
# @see https://developer.github.com/v3/apps/#get-an-organization-installation
|
93
|
+
#
|
94
|
+
# @return [Sawyer::Resource] Installation information
|
95
|
+
def find_organization_installation(organization, options = {})
|
96
|
+
get "#{Organization.path(organization)}/installation", options
|
97
|
+
end
|
98
|
+
|
99
|
+
# Enables an app to find the repository's installation information.
|
100
|
+
#
|
101
|
+
# @param repo [String] A GitHub repository
|
102
|
+
# @param options [Hash] A customizable set of options
|
103
|
+
#
|
104
|
+
# @see https://developer.github.com/v3/apps/#get-a-repository-installation
|
105
|
+
#
|
106
|
+
# @return [Sawyer::Resource] Installation information
|
107
|
+
def find_repository_installation(repo, options = {})
|
108
|
+
get "#{Repository.path(repo)}/installation", options
|
109
|
+
end
|
110
|
+
|
111
|
+
# Enables an app to find the user's installation information.
|
112
|
+
#
|
113
|
+
# @param user [String] GitHub user login
|
114
|
+
# @param options [Hash] A customizable set of options
|
115
|
+
#
|
116
|
+
# @see https://developer.github.com/v3/apps/#get-a-user-installation
|
117
|
+
#
|
118
|
+
# @return [Sawyer::Resource] Installation information
|
119
|
+
def find_user_installation(user, options = {})
|
120
|
+
get "#{User.path(user)}/installation", options
|
121
|
+
end
|
122
|
+
|
123
|
+
# List repositories that are accessible to the authenticated installation
|
124
|
+
#
|
125
|
+
# @param options [Hash] A customizable set of options
|
126
|
+
#
|
127
|
+
# @see https://developer.github.com/v3/apps/installations/#list-repositories
|
128
|
+
#
|
129
|
+
# @return [Sawyer::Resource] the total_count and an array of repositories
|
130
|
+
def list_app_installation_repositories(options = {})
|
131
|
+
paginate('installation/repositories', options) do |data, last_response|
|
132
|
+
data.repositories.concat last_response.data.repositories
|
133
|
+
end
|
134
|
+
end
|
135
|
+
alias list_installation_repos list_app_installation_repositories
|
136
|
+
|
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
|
+
# Add a single repository to an installation
|
148
|
+
#
|
149
|
+
# @param installation [Integer] The id of a GitHub App Installation
|
150
|
+
# @param repo [Integer] The id of the GitHub repository
|
151
|
+
# @param options [Hash] A customizable set of options
|
152
|
+
#
|
153
|
+
# @see https://developer.github.com/v3/apps/installations/#add-repository-to-installation
|
154
|
+
#
|
155
|
+
# @return [Boolean] Success
|
156
|
+
def add_repository_to_app_installation(installation, repo, options = {})
|
157
|
+
boolean_from_response :put, "user/installations/#{installation}/repositories/#{repo}", options
|
158
|
+
end
|
159
|
+
alias add_repo_to_installation add_repository_to_app_installation
|
160
|
+
|
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
|
+
# Remove a single repository to an installation
|
172
|
+
#
|
173
|
+
# @param installation [Integer] The id of a GitHub App Installation
|
174
|
+
# @param repo [Integer] The id of the GitHub repository
|
175
|
+
# @param options [Hash] A customizable set of options
|
176
|
+
#
|
177
|
+
# @see https://developer.github.com/v3/apps/installations/#remove-repository-from-installation
|
178
|
+
#
|
179
|
+
# @return [Boolean] Success
|
180
|
+
def remove_repository_from_app_installation(installation, repo, options = {})
|
181
|
+
boolean_from_response :delete, "user/installations/#{installation}/repositories/#{repo}", options
|
182
|
+
end
|
183
|
+
alias remove_repo_from_installation remove_repository_from_app_installation
|
184
|
+
|
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
|
+
# List repositories accessible to the user for an installation
|
196
|
+
#
|
197
|
+
# @param installation [Integer] The id of a GitHub App Installation
|
198
|
+
# @param options [Hash] A customizable set of options
|
199
|
+
#
|
200
|
+
# @see https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-user-for-an-installation
|
201
|
+
#
|
202
|
+
# @return [Sawyer::Resource] the total_count and an array of repositories
|
203
|
+
def find_installation_repositories_for_user(installation, options = {})
|
204
|
+
paginate("user/installations/#{installation}/repositories", options) do |data, last_response|
|
205
|
+
data.repositories.concat last_response.data.repositories
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
# Delete an installation and uninstall a GitHub App
|
210
|
+
#
|
211
|
+
# @param installation [Integer] The id of a GitHub App Installation
|
212
|
+
# @param options [Hash] A customizable set of options
|
213
|
+
#
|
214
|
+
# @see https://developer.github.com/v3/apps/#delete-an-installation
|
215
|
+
#
|
216
|
+
# @return [Boolean] Success
|
217
|
+
def delete_installation(installation, options = {})
|
218
|
+
boolean_from_response :delete, "app/installations/#{installation}", options
|
219
|
+
end
|
220
|
+
|
221
|
+
# Returns a list of webhook deliveries for the webhook configured for a GitHub App.
|
222
|
+
#
|
223
|
+
# @param options [Hash] A customizable set of options
|
224
|
+
#
|
225
|
+
# @see https://docs.github.com/en/rest/apps/webhooks#list-deliveries-for-an-app-webhook
|
226
|
+
#
|
227
|
+
# @return [Array<Hash>] an array of hook deliveries
|
228
|
+
def list_app_hook_deliveries(options = {})
|
229
|
+
paginate('app/hook/deliveries', options) do |data, last_response|
|
230
|
+
data.concat last_response.data
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
# Returns a delivery for the webhook configured for a GitHub App.
|
235
|
+
#
|
236
|
+
# @param delivery_id [String] The id of a GitHub App Hook Delivery
|
237
|
+
# @param options [Hash] A customizable set of options
|
238
|
+
#
|
239
|
+
# @see https://docs.github.com/en/rest/apps/webhooks#get-a-delivery-for-an-app-webhook
|
240
|
+
#
|
241
|
+
# @return [<Sawyer::Resource>] The webhook delivery
|
242
|
+
def app_hook_delivery(delivery_id, options = {})
|
243
|
+
get "/app/hook/deliveries/#{delivery_id}", options
|
244
|
+
end
|
245
|
+
|
246
|
+
# Redeliver a delivery for the webhook configured for a GitHub App.
|
247
|
+
#
|
248
|
+
# @param delivery_id [Integer] The id of a GitHub App Hook Delivery
|
249
|
+
# @param options [Hash] A customizable set of options
|
250
|
+
#
|
251
|
+
# @see https://developer.github.com/v3/apps/#redeliver-a-delivery-for-an-app-webhook
|
252
|
+
#
|
253
|
+
# @return [Boolean] Success
|
254
|
+
def deliver_app_hook(delivery_id, options = {})
|
255
|
+
boolean_from_response :post, "app/hook/deliveries/#{delivery_id}/attempts", options
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Octokit
|
4
|
+
class Client
|
5
|
+
# Methods for the Checks API
|
6
|
+
#
|
7
|
+
# @see https://developer.github.com/v3/checks/
|
8
|
+
module Checks
|
9
|
+
# Methods for Check Runs
|
10
|
+
#
|
11
|
+
# @see https://developer.github.com/v3/checks/runs/
|
12
|
+
|
13
|
+
# Create a check run
|
14
|
+
#
|
15
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
16
|
+
# @param name [String] The name of the check
|
17
|
+
# @param head_sha [String] The SHA of the commit to check
|
18
|
+
# @return [Sawyer::Resource] A hash representing the new check run
|
19
|
+
# @see https://developer.github.com/v3/checks/runs/#create-a-check-run
|
20
|
+
# @example Create a check run
|
21
|
+
# check_run = @client.create_check_run("octocat/Hello-World", "my-check", "7638417db6d59f3c431d3e1f261cc637155684cd")
|
22
|
+
# check_run.name # => "my-check"
|
23
|
+
# check_run.head_sha # => "7638417db6d59f3c431d3e1f261cc637155684cd"
|
24
|
+
# check_run.status # => "queued"
|
25
|
+
def create_check_run(repo, name, head_sha, options = {})
|
26
|
+
options[:name] = name
|
27
|
+
options[:head_sha] = head_sha
|
28
|
+
|
29
|
+
post "#{Repository.path repo}/check-runs", options
|
30
|
+
end
|
31
|
+
|
32
|
+
# Update a check run
|
33
|
+
#
|
34
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
35
|
+
# @param id [Integer] The ID of the check run
|
36
|
+
# @return [Sawyer::Resource] A hash representing the updated check run
|
37
|
+
# @see https://developer.github.com/v3/checks/runs/#update-a-check-run
|
38
|
+
# @example Update a check run
|
39
|
+
# check_run = @client.update_check_run("octocat/Hello-World", 51295429, status: "in_progress")
|
40
|
+
# check_run.id # => 51295429
|
41
|
+
# check_run.status # => "in_progress"
|
42
|
+
def update_check_run(repo, id, options = {})
|
43
|
+
patch "#{Repository.path repo}/check-runs/#{id}", options
|
44
|
+
end
|
45
|
+
|
46
|
+
# List check runs for a specific ref
|
47
|
+
#
|
48
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
49
|
+
# @param ref [String] A SHA, branch name, or tag name
|
50
|
+
# @param options [Hash] A set of optional filters
|
51
|
+
# @option options [String] :check_name Returns check runs with the specified <tt>name</tt>
|
52
|
+
# @option options [String] :status Returns check runs with the specified <tt>status</tt>
|
53
|
+
# @option options [String] :filter Filters check runs by their <tt>completed_at</tt> timestamp
|
54
|
+
# @return [Sawyer::Resource] A hash representing a collection of check runs
|
55
|
+
# @see https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref
|
56
|
+
# @example List check runs for a specific ref
|
57
|
+
# result = @client.check_runs_for_ref("octocat/Hello-World", "7638417db6d59f3c431d3e1f261cc637155684cd", status: "in_progress")
|
58
|
+
# result.total_count # => 1
|
59
|
+
# result.check_runs.count # => 1
|
60
|
+
# result.check_runs[0].id # => 51295429
|
61
|
+
# result.check_runs[0].status # => "in_progress"
|
62
|
+
def check_runs_for_ref(repo, ref, options = {})
|
63
|
+
paginate "#{Repository.path repo}/commits/#{ref}/check-runs", options do |data, last_response|
|
64
|
+
data.check_runs.concat last_response.data.check_runs
|
65
|
+
data.total_count += last_response.data.total_count
|
66
|
+
end
|
67
|
+
end
|
68
|
+
alias list_check_runs_for_ref check_runs_for_ref
|
69
|
+
|
70
|
+
# List check runs in a check suite
|
71
|
+
#
|
72
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
73
|
+
# @param id [Integer] The ID of the check suite
|
74
|
+
# @param options [Hash] A set of optional filters
|
75
|
+
# @option options [String] :check_name Returns check runs with the specified <tt>name</tt>
|
76
|
+
# @option options [String] :status Returns check runs with the specified <tt>status</tt>
|
77
|
+
# @option options [String] :filter Filters check runs by their <tt>completed_at</tt> timestamp
|
78
|
+
# @return [Sawyer::Resource] A hash representing a collection of check runs
|
79
|
+
# @see https://developer.github.com/v3/checks/runs/#list-check-runs-in-a-check-suite
|
80
|
+
# @example List check runs in a check suite
|
81
|
+
# result = @client.check_runs_for_check_suite("octocat/Hello-World", 50440400, status: "in_progress")
|
82
|
+
# result.total_count # => 1
|
83
|
+
# result.check_runs.count # => 1
|
84
|
+
# result.check_runs[0].check_suite.id # => 50440400
|
85
|
+
# result.check_runs[0].status # => "in_progress"
|
86
|
+
def check_runs_for_check_suite(repo, id, options = {})
|
87
|
+
paginate "#{Repository.path repo}/check-suites/#{id}/check-runs", options do |data, last_response|
|
88
|
+
data.check_runs.concat last_response.data.check_runs
|
89
|
+
data.total_count += last_response.data.total_count
|
90
|
+
end
|
91
|
+
end
|
92
|
+
alias list_check_runs_for_check_suite check_runs_for_check_suite
|
93
|
+
|
94
|
+
# Get a single check run
|
95
|
+
#
|
96
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
97
|
+
# @param id [Integer] The ID of the check run
|
98
|
+
# @return [Sawyer::Resource] A hash representing the check run
|
99
|
+
# @see https://developer.github.com/v3/checks/runs/#get-a-single-check-run
|
100
|
+
def check_run(repo, id, options = {})
|
101
|
+
get "#{Repository.path repo}/check-runs/#{id}", options
|
102
|
+
end
|
103
|
+
|
104
|
+
# List annotations for a check run
|
105
|
+
#
|
106
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
107
|
+
# @param id [Integer] The ID of the check run
|
108
|
+
# @return [Array<Sawyer::Resource>] An array of hashes representing check run annotations
|
109
|
+
# @see https://developer.github.com/v3/checks/runs/#list-annotations-for-a-check-run
|
110
|
+
# @example List annotations for a check run
|
111
|
+
# annotations = @client.check_run_annotations("octocat/Hello-World", 51295429)
|
112
|
+
# annotations.count # => 1
|
113
|
+
# annotations[0].path # => "README.md"
|
114
|
+
# annotations[0].message # => "Looks good!"
|
115
|
+
def check_run_annotations(repo, id, options = {})
|
116
|
+
paginate "#{Repository.path repo}/check-runs/#{id}/annotations", options
|
117
|
+
end
|
118
|
+
|
119
|
+
# Methods for Check Suites
|
120
|
+
#
|
121
|
+
# @see https://developer.github.com/v3/checks/suites/
|
122
|
+
|
123
|
+
# Get a single check suite
|
124
|
+
#
|
125
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
126
|
+
# @param id [Integer] The ID of the check suite
|
127
|
+
# @return [Sawyer::Resource] A hash representing the check suite
|
128
|
+
# @see https://developer.github.com/v3/checks/suites/#get-a-single-check-suite
|
129
|
+
def check_suite(repo, id, options = {})
|
130
|
+
get "#{Repository.path repo}/check-suites/#{id}", options
|
131
|
+
end
|
132
|
+
|
133
|
+
# List check suites for a specific ref
|
134
|
+
#
|
135
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
136
|
+
# @param ref [String] A SHA, branch name, or tag name
|
137
|
+
# @param options [Hash] A set of optional filters
|
138
|
+
# @option options [Integer] :app_id Filters check suites by GitHub App <tt>id</tt>
|
139
|
+
# @option options [String] :check_name Filters checks suites by the <tt>name</tt> of the check run
|
140
|
+
# @return [Sawyer::Resource] A hash representing a collection of check suites
|
141
|
+
# @see https://developer.github.com/v3/checks/suites/#list-check-suites-for-a-specific-ref
|
142
|
+
# @example List check suites for a specific ref
|
143
|
+
# result = @client.check_suites_for_ref("octocat/Hello-World", "7638417db6d59f3c431d3e1f261cc637155684cd", app_id: 76765)
|
144
|
+
# result.total_count # => 1
|
145
|
+
# result.check_suites.count # => 1
|
146
|
+
# result.check_suites[0].id # => 50440400
|
147
|
+
# result.check_suites[0].app.id # => 76765
|
148
|
+
def check_suites_for_ref(repo, ref, options = {})
|
149
|
+
paginate "#{Repository.path repo}/commits/#{ref}/check-suites", options do |data, last_response|
|
150
|
+
data.check_suites.concat last_response.data.check_suites
|
151
|
+
data.total_count += last_response.data.total_count
|
152
|
+
end
|
153
|
+
end
|
154
|
+
alias list_check_suites_for_ref check_suites_for_ref
|
155
|
+
|
156
|
+
# Set preferences for check suites on a repository
|
157
|
+
#
|
158
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
159
|
+
# @param options [Hash] Preferences to set
|
160
|
+
# @return [Sawyer::Resource] A hash representing the repository's check suite preferences
|
161
|
+
# @see https://developer.github.com/v3/checks/suites/#set-preferences-for-check-suites-on-a-repository
|
162
|
+
# @example Set preferences for check suites on a repository
|
163
|
+
# result = @client.set_check_suite_preferences("octocat/Hello-World", auto_trigger_checks: [{ app_id: 76765, setting: false }])
|
164
|
+
# result.preferences.auto_trigger_checks.count # => 1
|
165
|
+
# result.preferences.auto_trigger_checks[0].app_id # => 76765
|
166
|
+
# result.preferences.auto_trigger_checks[0].setting # => false
|
167
|
+
# result.repository.full_name # => "octocat/Hello-World"
|
168
|
+
def set_check_suite_preferences(repo, options = {})
|
169
|
+
patch "#{Repository.path repo}/check-suites/preferences", options
|
170
|
+
end
|
171
|
+
|
172
|
+
# Create a check suite
|
173
|
+
#
|
174
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
175
|
+
# @param head_sha [String] The SHA of the commit to check
|
176
|
+
# @return [Sawyer::Resource] A hash representing the new check suite
|
177
|
+
# @see https://developer.github.com/v3/checks/suites/#create-a-check-suite
|
178
|
+
# @example Create a check suite
|
179
|
+
# check_suite = @client.create_check_suite("octocat/Hello-World", "7638417db6d59f3c431d3e1f261cc637155684cd")
|
180
|
+
# check_suite.head_sha # => "7638417db6d59f3c431d3e1f261cc637155684cd"
|
181
|
+
# check_suite.status # => "queued"
|
182
|
+
def create_check_suite(repo, head_sha, options = {})
|
183
|
+
options[:head_sha] = head_sha
|
184
|
+
|
185
|
+
post "#{Repository.path repo}/check-suites", options
|
186
|
+
end
|
187
|
+
|
188
|
+
# Rerequest check suite
|
189
|
+
#
|
190
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
191
|
+
# @param id [Integer] The ID of the check suite
|
192
|
+
# @return [Boolean] True if successful, raises an error otherwise
|
193
|
+
# @see https://developer.github.com/v3/checks/suites/#rerequest-check-suite
|
194
|
+
def rerequest_check_suite(repo, id, options = {})
|
195
|
+
post "#{Repository.path repo}/check-suites/#{id}/rerequest", options
|
196
|
+
true
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,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
|