gitabu 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +33 -0
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +10 -0
  6. data/Gemfile.lock +65 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +42 -0
  9. data/Rakefile +12 -0
  10. data/gitabu.gemspec +41 -0
  11. data/lib/gitabu/api/v3/actions.rb +3724 -0
  12. data/lib/gitabu/api/v3/activity.rb +835 -0
  13. data/lib/gitabu/api/v3/apps.rb +961 -0
  14. data/lib/gitabu/api/v3/billing.rb +217 -0
  15. data/lib/gitabu/api/v3/branches.rb +1098 -0
  16. data/lib/gitabu/api/v3/checks.rb +384 -0
  17. data/lib/gitabu/api/v3/code_scanning.rb +315 -0
  18. data/lib/gitabu/api/v3/codes_of_conduct.rb +92 -0
  19. data/lib/gitabu/api/v3/codespaces.rb +650 -0
  20. data/lib/gitabu/api/v3/collaborators.rb +341 -0
  21. data/lib/gitabu/api/v3/commits.rb +428 -0
  22. data/lib/gitabu/api/v3/dependabot.rb +419 -0
  23. data/lib/gitabu/api/v3/deploy_keys.rb +152 -0
  24. data/lib/gitabu/api/v3/deployments.rb +356 -0
  25. data/lib/gitabu/api/v3/emojis.rb +67 -0
  26. data/lib/gitabu/api/v3/enterprise_admin.rb +495 -0
  27. data/lib/gitabu/api/v3/gists.rb +552 -0
  28. data/lib/gitabu/api/v3/git.rb +409 -0
  29. data/lib/gitabu/api/v3/gitignore.rb +92 -0
  30. data/lib/gitabu/api/v3/interactions.rb +275 -0
  31. data/lib/gitabu/api/v3/issues.rb +1119 -0
  32. data/lib/gitabu/api/v3/licenses.rb +118 -0
  33. data/lib/gitabu/api/v3/markdown.rb +94 -0
  34. data/lib/gitabu/api/v3/meta.rb +142 -0
  35. data/lib/gitabu/api/v3/metrics.rb +302 -0
  36. data/lib/gitabu/api/v3/migrations.rb +631 -0
  37. data/lib/gitabu/api/v3/orgs.rb +1291 -0
  38. data/lib/gitabu/api/v3/packages.rb +686 -0
  39. data/lib/gitabu/api/v3/pages.rb +282 -0
  40. data/lib/gitabu/api/v3/projects.rb +693 -0
  41. data/lib/gitabu/api/v3/pulls.rb +816 -0
  42. data/lib/gitabu/api/v3/rate_limit.rb +67 -0
  43. data/lib/gitabu/api/v3/reactions.rb +734 -0
  44. data/lib/gitabu/api/v3/releases.rb +411 -0
  45. data/lib/gitabu/api/v3/repos.rb +1136 -0
  46. data/lib/gitabu/api/v3/scim.rb +214 -0
  47. data/lib/gitabu/api/v3/search.rb +217 -0
  48. data/lib/gitabu/api/v3/secret_scanning.rb +201 -0
  49. data/lib/gitabu/api/v3/teams.rb +1963 -0
  50. data/lib/gitabu/api/v3/users.rb +851 -0
  51. data/lib/gitabu/api/v3/webhooks.rb +379 -0
  52. data/lib/gitabu/builder.rb +37 -0
  53. data/lib/gitabu/client.rb +8 -0
  54. data/lib/gitabu/generator.rb +75 -0
  55. data/lib/gitabu/http_client.rb +96 -0
  56. data/lib/gitabu/items.rb +110 -0
  57. data/lib/gitabu/public/api/v3/actions.json +5779 -0
  58. data/lib/gitabu/public/api/v3/activity.json +1248 -0
  59. data/lib/gitabu/public/api/v3/apps.json +1174 -0
  60. data/lib/gitabu/public/api/v3/billing.json +183 -0
  61. data/lib/gitabu/public/api/v3/branches.json +1886 -0
  62. data/lib/gitabu/public/api/v3/checks.json +856 -0
  63. data/lib/gitabu/public/api/v3/code_scanning.json +666 -0
  64. data/lib/gitabu/public/api/v3/codes_of_conduct.json +41 -0
  65. data/lib/gitabu/public/api/v3/codespaces.json +884 -0
  66. data/lib/gitabu/public/api/v3/collaborators.json +464 -0
  67. data/lib/gitabu/public/api/v3/commits.json +830 -0
  68. data/lib/gitabu/public/api/v3/dependabot.json +596 -0
  69. data/lib/gitabu/public/api/v3/deploy_keys.json +195 -0
  70. data/lib/gitabu/public/api/v3/deployments.json +698 -0
  71. data/lib/gitabu/public/api/v3/emojis.json +18 -0
  72. data/lib/gitabu/public/api/v3/enterprise_admin.json +881 -0
  73. data/lib/gitabu/public/api/v3/gists.json +689 -0
  74. data/lib/gitabu/public/api/v3/git.json +735 -0
  75. data/lib/gitabu/public/api/v3/gitignore.json +41 -0
  76. data/lib/gitabu/public/api/v3/interactions.json +265 -0
  77. data/lib/gitabu/public/api/v3/issues.json +2359 -0
  78. data/lib/gitabu/public/api/v3/licenses.json +100 -0
  79. data/lib/gitabu/public/api/v3/markdown.json +59 -0
  80. data/lib/gitabu/public/api/v3/meta.json +69 -0
  81. data/lib/gitabu/public/api/v3/metrics.json +342 -0
  82. data/lib/gitabu/public/api/v3/migrations.json +960 -0
  83. data/lib/gitabu/public/api/v3/orgs.json +1989 -0
  84. data/lib/gitabu/public/api/v3/packages.json +1078 -0
  85. data/lib/gitabu/public/api/v3/pages.json +373 -0
  86. data/lib/gitabu/public/api/v3/projects.json +966 -0
  87. data/lib/gitabu/public/api/v3/pulls.json +1768 -0
  88. data/lib/gitabu/public/api/v3/rate_limit.json +18 -0
  89. data/lib/gitabu/public/api/v3/reactions.json +1425 -0
  90. data/lib/gitabu/public/api/v3/releases.json +753 -0
  91. data/lib/gitabu/public/api/v3/repos.json +2314 -0
  92. data/lib/gitabu/public/api/v3/scim.json +412 -0
  93. data/lib/gitabu/public/api/v3/search.json +408 -0
  94. data/lib/gitabu/public/api/v3/secret_scanning.json +385 -0
  95. data/lib/gitabu/public/api/v3/teams.json +3126 -0
  96. data/lib/gitabu/public/api/v3/users.json +956 -0
  97. data/lib/gitabu/public/api/v3/webhooks.json +667 -0
  98. data/lib/gitabu/run.rb +237 -0
  99. data/lib/gitabu/scraper.rb +86 -0
  100. data/lib/gitabu/templates/template.rb.erb +70 -0
  101. data/lib/gitabu/version.rb +6 -0
  102. data/lib/gitabu.rb +57 -0
  103. data/sig/gitabu.rbs +4 -0
  104. metadata +177 -0
@@ -0,0 +1,379 @@
1
+ # frozen_string_literal: true
2
+
3
+ # INFO ON GENERATED CODE
4
+ #
5
+ # This file is generated.
6
+ # See the contribution guide on how to improve the code.
7
+ #
8
+ # INFO ON GENERATED CODE
9
+
10
+ # Ruby gem that helps you work with Github API.
11
+ module Gitabu
12
+ # API module
13
+ module Api
14
+ # Github Version 3
15
+ module V3
16
+ # Class to display Webhooks result
17
+ class WebhooksResult
18
+ attr_accessor :result, :message
19
+
20
+ def initialize(result:, message:)
21
+ @result = result
22
+ @message = message
23
+ end
24
+ end
25
+
26
+ # Class to display error result
27
+ class WebhooksErrorResult
28
+ attr_accessor :result, :message
29
+
30
+ def initialize(result:, message:)
31
+ @result = result
32
+ @message = message
33
+ end
34
+ end
35
+
36
+ # Webhooks endpoints.
37
+ class Webhooks
38
+ def self.get_a_webhook_configuration_for_a_repository(owner: nil, repo: nil, hook_id: nil, options: nil)
39
+ new.get_a_webhook_configuration_for_a_repository(owner, repo, hook_id, options)
40
+ end
41
+
42
+ def self.update_a_webhook_configuration_for_a_repository(owner: nil, repo: nil, hook_id: nil, url: nil, content_type: nil, secret: nil, insecure_ssl: nil, options: nil)
43
+ new.update_a_webhook_configuration_for_a_repository(owner, repo, hook_id, url, content_type, secret, insecure_ssl, options)
44
+ end
45
+
46
+ def self.list_deliveries_for_a_repository_webhook(owner: nil, repo: nil, hook_id: nil, options: nil)
47
+ new.list_deliveries_for_a_repository_webhook(owner, repo, hook_id, options)
48
+ end
49
+
50
+ def self.get_a_delivery_for_a_repository_webhook(owner: nil, repo: nil, hook_id: nil, delivery_id: nil, options: nil)
51
+ new.get_a_delivery_for_a_repository_webhook(owner, repo, hook_id, delivery_id, options)
52
+ end
53
+
54
+ def self.redeliver_a_delivery_for_a_repository_webhook(owner: nil, repo: nil, hook_id: nil, delivery_id: nil, options: nil)
55
+ new.redeliver_a_delivery_for_a_repository_webhook(owner, repo, hook_id, delivery_id, options)
56
+ end
57
+
58
+ def self.list_repository_webhooks(owner: nil, repo: nil, options: nil)
59
+ new.list_repository_webhooks(owner, repo, options)
60
+ end
61
+
62
+ def self.create_a_repository_webhook(owner: nil, repo: nil, name: nil, config: nil, events: nil, active: nil, options: nil)
63
+ new.create_a_repository_webhook(owner, repo, name, config, events, active, options)
64
+ end
65
+
66
+ def self.get_a_repository_webhook(owner: nil, repo: nil, hook_id: nil, options: nil)
67
+ new.get_a_repository_webhook(owner, repo, hook_id, options)
68
+ end
69
+
70
+ def self.update_a_repository_webhook(owner: nil, repo: nil, hook_id: nil, config: nil, events: nil, add_events: nil, remove_events: nil, active: nil, options: nil)
71
+ new.update_a_repository_webhook(owner, repo, hook_id, config, events, add_events, remove_events, active, options)
72
+ end
73
+
74
+ def self.delete_a_repository_webhook(owner: nil, repo: nil, hook_id: nil, options: nil)
75
+ new.delete_a_repository_webhook(owner, repo, hook_id, options)
76
+ end
77
+
78
+ def self.ping_a_repository_webhook(owner: nil, repo: nil, hook_id: nil, options: nil)
79
+ new.ping_a_repository_webhook(owner, repo, hook_id, options)
80
+ end
81
+
82
+ def self.test_the_push_repository_webhook(owner: nil, repo: nil, hook_id: nil, options: nil)
83
+ new.test_the_push_repository_webhook(owner, repo, hook_id, options)
84
+ end
85
+
86
+ private
87
+
88
+ # get a webhook configuration for a repository
89
+ #
90
+ # @param owner [String]
91
+ # @param repo [String]
92
+ # @param hook_id [Integer]
93
+ #
94
+ # @return WebhooksResult, WebhooksErrorResult
95
+ def get_a_webhook_configuration_for_a_repository(owner, repo, hook_id, _options)
96
+ auth = nil
97
+ body = nil
98
+ headers = { accept: 'application/vnd.github.v3+json' }
99
+ params = nil
100
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks/#{hook_id}/config"
101
+
102
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :get, params: params, uri: uri)
103
+
104
+ if http_call.successful?
105
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
106
+ else
107
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
108
+ end
109
+ end
110
+
111
+ # update a webhook configuration for a repository
112
+ #
113
+ # @param owner [String]
114
+ # @param repo [String]
115
+ # @param hook_id [Integer]
116
+ # @param url [String] The URL to which the payloads will be delivered.
117
+ # @param content_type [String] The media type used to serialize the payloads. Supported values include json and form. The default is form.
118
+ # @param secret [String] If provided, the secret will be used as the key to generate the HMAC hex digest value for delivery signature headers.
119
+ # @param insecure_ssl [String or number or ] Determines whether the SSL certificate of the host for url will be verified when delivering payloads. Supported values include 0 (verification is performed) and 1 (verification is not performed). The default is 0. We strongly recommend not setting this to 1 as you are subject to man-in-the-middle and other attacks.
120
+ #
121
+ # @return WebhooksResult, WebhooksErrorResult
122
+ def update_a_webhook_configuration_for_a_repository(owner, repo, hook_id, url, content_type, secret, insecure_ssl, _options)
123
+ auth = nil
124
+ body = { url: url, content_type: content_type, secret: secret, insecure_ssl: insecure_ssl }
125
+ headers = { accept: 'application/vnd.github.v3+json' }
126
+ params = nil
127
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks/#{hook_id}/config"
128
+
129
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :patch, params: params, uri: uri)
130
+
131
+ if http_call.successful?
132
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
133
+ else
134
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
135
+ end
136
+ end
137
+
138
+ # list deliveries for a repository webhook
139
+ #
140
+ # @param owner [String]
141
+ # @param repo [String]
142
+ # @param hook_id [Integer]
143
+ #
144
+ # @return WebhooksResult, WebhooksErrorResult
145
+ def list_deliveries_for_a_repository_webhook(owner, repo, hook_id, options)
146
+ auth = nil
147
+ body = nil
148
+ headers = { accept: 'application/vnd.github.v3+json' }
149
+ params = { per_page: options[:per_page], cursor: options[:cursor] }
150
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks/#{hook_id}/deliveries"
151
+
152
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :get, params: params, uri: uri)
153
+
154
+ if http_call.successful?
155
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
156
+ else
157
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
158
+ end
159
+ end
160
+
161
+ # get a delivery for a repository webhook
162
+ #
163
+ # @param owner [String]
164
+ # @param repo [String]
165
+ # @param hook_id [Integer]
166
+ # @param delivery_id [Integer]
167
+ #
168
+ # @return WebhooksResult, WebhooksErrorResult
169
+ def get_a_delivery_for_a_repository_webhook(owner, repo, hook_id, delivery_id, _options)
170
+ auth = nil
171
+ body = nil
172
+ headers = { accept: 'application/vnd.github.v3+json' }
173
+ params = nil
174
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks/#{hook_id}/deliveries/#{delivery_id}"
175
+
176
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :get, params: params, uri: uri)
177
+
178
+ if http_call.successful?
179
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
180
+ else
181
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
182
+ end
183
+ end
184
+
185
+ # redeliver a delivery for a repository webhook
186
+ #
187
+ # @param owner [String]
188
+ # @param repo [String]
189
+ # @param hook_id [Integer]
190
+ # @param delivery_id [Integer]
191
+ #
192
+ # @return WebhooksResult, WebhooksErrorResult
193
+ def redeliver_a_delivery_for_a_repository_webhook(owner, repo, hook_id, delivery_id, _options)
194
+ auth = nil
195
+ body = nil
196
+ headers = { accept: 'application/vnd.github.v3+json' }
197
+ params = nil
198
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks/#{hook_id}/deliveries/#{delivery_id}/attempts"
199
+
200
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :post, params: params, uri: uri)
201
+
202
+ if http_call.successful?
203
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
204
+ else
205
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
206
+ end
207
+ end
208
+
209
+ # list repository webhooks
210
+ #
211
+ # @param owner [String]
212
+ # @param repo [String]
213
+ #
214
+ # @return WebhooksResult, WebhooksErrorResult
215
+ def list_repository_webhooks(owner, repo, options)
216
+ auth = nil
217
+ body = nil
218
+ headers = { accept: 'application/vnd.github.v3+json' }
219
+ params = { per_page: options[:per_page], page: options[:page] }
220
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks"
221
+
222
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :get, params: params, uri: uri)
223
+
224
+ if http_call.successful?
225
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
226
+ else
227
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
228
+ end
229
+ end
230
+
231
+ # create a repository webhook
232
+ #
233
+ # @param owner [String]
234
+ # @param repo [String]
235
+ # @param name [String] Use web to create a webhook. Default: web. This parameter only accepts the value web.
236
+ # @param config [Object] Key/value pairs to provide settings for this webhook. These are defined below.
237
+ # @param events [Array of strings] Determines what events the hook is triggered for.Default: push
238
+ # @param active [Boolean] Determines if notifications are sent when the webhook is triggered. Set to true to send notifications.Default:
239
+ #
240
+ # @return WebhooksResult, WebhooksErrorResult
241
+ def create_a_repository_webhook(owner, repo, name, config, events, active, _options)
242
+ auth = nil
243
+ body = { name: name, config: config, events: events, active: active }
244
+ headers = { accept: 'application/vnd.github.v3+json' }
245
+ params = nil
246
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks"
247
+
248
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :post, params: params, uri: uri)
249
+
250
+ if http_call.successful?
251
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
252
+ else
253
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
254
+ end
255
+ end
256
+
257
+ # get a repository webhook
258
+ #
259
+ # @param owner [String]
260
+ # @param repo [String]
261
+ # @param hook_id [Integer]
262
+ #
263
+ # @return WebhooksResult, WebhooksErrorResult
264
+ def get_a_repository_webhook(owner, repo, hook_id, _options)
265
+ auth = nil
266
+ body = nil
267
+ headers = { accept: 'application/vnd.github.v3+json' }
268
+ params = nil
269
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks/#{hook_id}"
270
+
271
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :get, params: params, uri: uri)
272
+
273
+ if http_call.successful?
274
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
275
+ else
276
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
277
+ end
278
+ end
279
+
280
+ # update a repository webhook
281
+ #
282
+ # @param owner [String]
283
+ # @param repo [String]
284
+ # @param hook_id [Integer]
285
+ # @param config [Object] Key/value pairs to provide settings for this webhook. These are defined below.
286
+ # @param events [Array of strings] Determines what events the hook is triggered for. This replaces the entire array of events.Default: push
287
+ # @param add_events [Array of strings] Determines a list of events to be added to the list of events that the Hook triggers for.
288
+ # @param remove_events [Array of strings] Determines a list of events to be removed from the list of events that the Hook triggers for.
289
+ # @param active [Boolean] Determines if notifications are sent when the webhook is triggered. Set to true to send notifications.Default:
290
+ #
291
+ # @return WebhooksResult, WebhooksErrorResult
292
+ def update_a_repository_webhook(owner, repo, hook_id, config, events, add_events, remove_events, active, _options)
293
+ auth = nil
294
+ body = { config: config, events: events, add_events: add_events, remove_events: remove_events, active: active }
295
+ headers = { accept: 'application/vnd.github.v3+json' }
296
+ params = nil
297
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks/#{hook_id}"
298
+
299
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :patch, params: params, uri: uri)
300
+
301
+ if http_call.successful?
302
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
303
+ else
304
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
305
+ end
306
+ end
307
+
308
+ # delete a repository webhook
309
+ #
310
+ # @param owner [String]
311
+ # @param repo [String]
312
+ # @param hook_id [Integer]
313
+ #
314
+ # @return WebhooksResult, WebhooksErrorResult
315
+ def delete_a_repository_webhook(owner, repo, hook_id, _options)
316
+ auth = nil
317
+ body = nil
318
+ headers = { accept: 'application/vnd.github.v3+json' }
319
+ params = nil
320
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks/#{hook_id}"
321
+
322
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :delete, params: params, uri: uri)
323
+
324
+ if http_call.successful?
325
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
326
+ else
327
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
328
+ end
329
+ end
330
+
331
+ # ping a repository webhook
332
+ #
333
+ # @param owner [String]
334
+ # @param repo [String]
335
+ # @param hook_id [Integer]
336
+ #
337
+ # @return WebhooksResult, WebhooksErrorResult
338
+ def ping_a_repository_webhook(owner, repo, hook_id, _options)
339
+ auth = nil
340
+ body = nil
341
+ headers = { accept: 'application/vnd.github.v3+json' }
342
+ params = nil
343
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks/#{hook_id}/pings"
344
+
345
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :post, params: params, uri: uri)
346
+
347
+ if http_call.successful?
348
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
349
+ else
350
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
351
+ end
352
+ end
353
+
354
+ # test the push repository webhook
355
+ #
356
+ # @param owner [String]
357
+ # @param repo [String]
358
+ # @param hook_id [Integer]
359
+ #
360
+ # @return WebhooksResult, WebhooksErrorResult
361
+ def test_the_push_repository_webhook(owner, repo, hook_id, _options)
362
+ auth = nil
363
+ body = nil
364
+ headers = { accept: 'application/vnd.github.v3+json' }
365
+ params = nil
366
+ uri = "#{Gitabu::BASE_URL}/repos/#{owner}/#{repo}/hooks/#{hook_id}/tests"
367
+
368
+ http_call = Gitabu::HttpClient.call(auth: auth, body: body, headers: headers, method: :post, params: params, uri: uri)
369
+
370
+ if http_call.successful?
371
+ WebhooksResult.new(result: http_call, message: "Successful call to endpoint. #{http_call.result.message}")
372
+ else
373
+ WebhooksErrorResult.new(result: http_call, message: "Failure while calling endpoint. #{http_call.result.message}")
374
+ end
375
+ end
376
+ end
377
+ end
378
+ end
379
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+
5
+ # Ruby gem that helps you work with Github API.
6
+ module Gitabu
7
+ # Builder class for files given target and template.
8
+ class Builder
9
+ include ERB::Util
10
+
11
+ attr_accessor :class_name, :items, :target, :template, :version
12
+
13
+ def self.save(class_name:, items:, target:, template:, version:)
14
+ new(class_name, items, target, template, version).save
15
+ end
16
+
17
+ def initialize(class_name, items, target, template, version)
18
+ @class_name = class_name
19
+ @items = items
20
+ @target = target
21
+ @template = template
22
+ @version = version
23
+ end
24
+
25
+ def save
26
+ File.open(target, "w+") do |f|
27
+ f.write(render)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def render
34
+ ERB.new(template).result(binding)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ruby gem that helps you work with Github API.
4
+ module Gitabu
5
+ # Client that acts as a middleman to the API.
6
+ class Client
7
+ end
8
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "fileutils"
5
+
6
+ require_relative "builder"
7
+ require_relative "items"
8
+ require_relative "scraper"
9
+
10
+ # Ruby gem that helps you work with Github API.
11
+ module Gitabu
12
+ # Http client that acts as a middleman to the API.
13
+ class Generator
14
+ attr_accessor :link, :name, :version
15
+
16
+ def self.generate(link:, name:, version:)
17
+ new(link, name, version).generate
18
+ end
19
+
20
+ def initialize(link, name, version)
21
+ @link = link
22
+ @name = name
23
+ @version = version
24
+ end
25
+
26
+ def generate
27
+ generate_json_spec
28
+ generate_api_class
29
+ end
30
+
31
+ private
32
+
33
+ def generate_json_spec
34
+ Gitabu::Scraper.scrape(link: link, name: name, version: version)
35
+ end
36
+
37
+ def generate_api_class
38
+ Gitabu::Builder.save(
39
+ class_name: name.capitalize, items: items, target: ruby_file, template: template, version: version
40
+ )
41
+ end
42
+
43
+ def items
44
+ Gitabu::Items.items(json_spec_result: json_spec_result, version: version)
45
+ end
46
+
47
+ def ruby_file
48
+ dir = "/#{spec.gem_dir}/lib/gitabu/api/v#{version}"
49
+ path = "#{dir}/#{name}.rb"
50
+ FileUtils.mkdir_p(dir)
51
+ path
52
+ end
53
+
54
+ def template
55
+ File.read(erb_file)
56
+ end
57
+
58
+ def json_spec_result
59
+ data = JSON.parse(File.read(json_spec))
60
+ data["result"]
61
+ end
62
+
63
+ def erb_file
64
+ "/#{spec.gem_dir}/lib/gitabu/templates/template.rb.erb"
65
+ end
66
+
67
+ def json_spec
68
+ "/#{spec.gem_dir}/lib/gitabu/public/api/v#{version}/#{name}.json"
69
+ end
70
+
71
+ def spec
72
+ Gem::Specification.find_by_name("gitabu")
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "net/http"
5
+ require "openssl"
6
+ require "ostruct"
7
+ require "json"
8
+
9
+ # Ruby gem that helps you work with Github API.
10
+ module Gitabu
11
+ # Http client that acts as a middleman to the API.
12
+ class HttpClient
13
+ NET_HTTP_ERRORS = [
14
+ Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError,
15
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
16
+ JSON::ParserError, SocketError
17
+ ].freeze
18
+
19
+ def self.call(method:, uri:, body: nil, params: nil, headers: nil, auth: nil, expect: nil)
20
+ new(method, uri, body, params, headers, auth, expect).call
21
+ end
22
+
23
+ def initialize(method, uri, body, params, headers, auth, expect)
24
+ @method = method
25
+ @body = body
26
+ @headers = headers
27
+ @auth = auth
28
+ @url = prepare_uri(uri, params)
29
+ @expect = expect.nil? ? :json : expect
30
+ @http = prepare_http
31
+ @request = prepare_request
32
+ end
33
+
34
+ def call
35
+ response
36
+ end
37
+
38
+ private
39
+
40
+ attr_accessor :auth, :body, :expect, :headers, :http, :method, :request, :url
41
+
42
+ def response
43
+ http_response = http.request(request)
44
+
45
+ if http_response.is_a?(Net::HTTPSuccess)
46
+ result = Gitabu.to_ostruct(JSON.parse(http_response.read_body)) if expect == :json
47
+ result = http_response.read_body if expect == :html
48
+ result_struct(result, http_response, true)
49
+ else
50
+ result_struct(nil, http_response, false)
51
+ end
52
+ rescue *NET_HTTP_ERRORS => e
53
+ result_struct(e, http_response, false)
54
+ end
55
+
56
+ def result_struct(result, response, success)
57
+ OpenStruct.new(
58
+ result: result,
59
+ headers: Gitabu.to_ostruct(response.to_hash),
60
+ code: response.code,
61
+ message: response.message,
62
+ class: response.class.name,
63
+ successful?: success
64
+ )
65
+ end
66
+
67
+ def prepare_uri(uri, params)
68
+ build_url = URI(uri)
69
+ build_url.query = URI.encode_www_form(params) unless params.nil?
70
+ build_url
71
+ end
72
+
73
+ def prepare_http
74
+ protocol = Net::HTTP.new(url.host, url.port)
75
+ protocol.use_ssl = true
76
+ protocol.verify_mode = OpenSSL::SSL::VERIFY_NONE
77
+ protocol
78
+ end
79
+
80
+ def prepare_request
81
+ req = build_request
82
+ req.basic_auth(auth[:user], auth[:password]) unless auth.nil?
83
+ req.body = JSON.dump(body) unless body.nil?
84
+ req
85
+ end
86
+
87
+ def build_request
88
+ return Net::HTTP::Get.new(url, headers) if method == :get
89
+ return Net::HTTP::Post.new(url, headers) if method == :post
90
+ return Net::HTTP::Put.new(url, headers) if method == :put
91
+ return Net::HTTP::Patch.new(url, headers) if method == :patch
92
+ return Net::HTTP::Delete.new(url, headers) if method == :delete
93
+ return Net::HTTP::Options.new(url, headers) if method == :options
94
+ end
95
+ end
96
+ end