gitlab-customer-support-operations_gitlab 1.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 (35) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_ops_gitlab/gitlab/badges.rb +229 -0
  3. data/lib/support_ops_gitlab/gitlab/base.rb +552 -0
  4. data/lib/support_ops_gitlab/gitlab/client.rb +51 -0
  5. data/lib/support_ops_gitlab/gitlab/commits.rb +198 -0
  6. data/lib/support_ops_gitlab/gitlab/configuration.rb +86 -0
  7. data/lib/support_ops_gitlab/gitlab/epics.rb +325 -0
  8. data/lib/support_ops_gitlab/gitlab/events.rb +167 -0
  9. data/lib/support_ops_gitlab/gitlab/gpg_keys.rb +64 -0
  10. data/lib/support_ops_gitlab/gitlab/group_memberships.rb +33 -0
  11. data/lib/support_ops_gitlab/gitlab/groups.rb +431 -0
  12. data/lib/support_ops_gitlab/gitlab/invitations.rb +72 -0
  13. data/lib/support_ops_gitlab/gitlab/issues.rb +606 -0
  14. data/lib/support_ops_gitlab/gitlab/jobs.rb +61 -0
  15. data/lib/support_ops_gitlab/gitlab/markdown.rb +54 -0
  16. data/lib/support_ops_gitlab/gitlab/merge_requests.rb +411 -0
  17. data/lib/support_ops_gitlab/gitlab/milestones.rb +195 -0
  18. data/lib/support_ops_gitlab/gitlab/namespaces.rb +184 -0
  19. data/lib/support_ops_gitlab/gitlab/notes.rb +182 -0
  20. data/lib/support_ops_gitlab/gitlab/pipelines.rb +258 -0
  21. data/lib/support_ops_gitlab/gitlab/project_access_tokens.rb +245 -0
  22. data/lib/support_ops_gitlab/gitlab/project_memberships.rb +33 -0
  23. data/lib/support_ops_gitlab/gitlab/project_webhook_events.rb +33 -0
  24. data/lib/support_ops_gitlab/gitlab/project_webhooks.rb +218 -0
  25. data/lib/support_ops_gitlab/gitlab/projects.rb +741 -0
  26. data/lib/support_ops_gitlab/gitlab/repository_files.rb +102 -0
  27. data/lib/support_ops_gitlab/gitlab/repository_submodules.rb +78 -0
  28. data/lib/support_ops_gitlab/gitlab/ssh_keys.rb +67 -0
  29. data/lib/support_ops_gitlab/gitlab/user_emails.rb +147 -0
  30. data/lib/support_ops_gitlab/gitlab/user_memberships.rb +21 -0
  31. data/lib/support_ops_gitlab/gitlab/user_tokens.rb +344 -0
  32. data/lib/support_ops_gitlab/gitlab/users.rb +1059 -0
  33. data/lib/support_ops_gitlab/gitlab.rb +45 -0
  34. data/lib/support_ops_gitlab.rb +28 -0
  35. metadata +251 -0
@@ -0,0 +1,741 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class Projects within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Boolean] allow_merge_on_skipped_pipeline
13
+ # @attr [Boolean] allow_pipeline_trigger_approve_deployment
14
+ # @attr [String] analytics_access_level
15
+ # @attr [Boolean] archived
16
+ # @attr [String] auto_cancel_pending_pipelines
17
+ # @attr [Boolean] autoclose_referenced_issues
18
+ # @attr [String] auto_devops_deploy_strategy
19
+ # @attr [Boolean] auto_devops_enabled
20
+ # @attr [String] avatar_url
21
+ # @attr [String] build_git_strategy
22
+ # @attr [String] builds_access_level
23
+ # @attr [Integer] build_timeout
24
+ # @attr [Boolean] can_create_merge_request_in
25
+ # @attr [Boolean] ci_allow_fork_pipelines_to_run_in_parent_project
26
+ # @attr [String] ci_config_path
27
+ # @attr [Integer] ci_default_git_depth
28
+ # @attr [Boolean] ci_forward_deployment_enabled
29
+ # @attr [Boolean] ci_forward_deployment_rollback_allowed
30
+ # @attr [Array] ci_id_token_sub_claim_components
31
+ # @attr [String] ci_pipeline_variables_minimum_override_role
32
+ # @attr [Boolean] ci_push_repository_for_job_token_allowed
33
+ # @attr [String] ci_restrict_pipeline_cancellation_role
34
+ # @attr [Boolean] ci_separated_caches
35
+ # @attr [Array] compliance_frameworks
36
+ # @attr [Hash] container_expiration_policy
37
+ # @attr [Hash] container_expiration_policy_attributes
38
+ # @attr [String] container_registry_access_level
39
+ # @attr [Boolean] container_registry_enabled
40
+ # @attr [String] container_registry_image_prefix
41
+ # @attr [String] created_at
42
+ # @attr [Integer] creator_id
43
+ # @attr [String] default_branch
44
+ # @attr [String] description
45
+ # @attr [String] description_html
46
+ # @attr [Boolean] emails_enabled
47
+ # @attr [Boolean] enforce_auth_checks_on_uploads
48
+ # @attr [String] environments_access_level
49
+ # @attr [String] external_authorization_classification_label
50
+ # @attr [String] feature_flags_access_level
51
+ # @attr [Hash] forked_from_project
52
+ # @attr [String] forking_access_level
53
+ # @attr [Integer] forks_count
54
+ # @attr [Boolean] group_runners_enabled
55
+ # @attr [Integer] group_with_project_templates_id
56
+ # @attr [String] http_url_to_repo
57
+ # @attr [Integer] id
58
+ # @attr [String] import_error
59
+ # @attr [String] import_status
60
+ # @attr [String] import_type
61
+ # @attr [String] import_url
62
+ # @attr [String] infrastructure_access_level
63
+ # @attr [Boolean] initialize_with_readme
64
+ # @attr [String] issue_branch_template
65
+ # @attr [String] issues_access_level
66
+ # @attr [Boolean] issues_enabled
67
+ # @attr [String] issues_template
68
+ # @attr [Boolean] jobs_enabled
69
+ # @attr [String] last_activity_at
70
+ # @attr [Boolean] lfs_enabled
71
+ # @attr [Hash] license
72
+ # @attr [String] license_url
73
+ # @attr [Hash] _links
74
+ # @attr [String] marked_for_deletion_on
75
+ # @attr [String] merge_commit_template
76
+ # @attr [String] merge_method
77
+ # @attr [Boolean] merge_pipelines_enabled
78
+ # @attr [String] merge_requests_access_level
79
+ # @attr [Boolean] merge_requests_enabled
80
+ # @attr [String] merge_requests_template
81
+ # @attr [Boolean] merge_trains_enabled
82
+ # @attr [Boolean] merge_trains_skip_train_allowed
83
+ # @attr [Boolean] mirror
84
+ # @attr [Boolean] mirror_overwrites_diverged_branches
85
+ # @attr [Boolean] mirror_trigger_builds
86
+ # @attr [Integer] mirror_user_id
87
+ # @attr [String] model_experiments_access_level
88
+ # @attr [String] model_registry_access_level
89
+ # @attr [String] monitor_access_level
90
+ # @attr [Boolean] mr_default_target_self
91
+ # @attr [String] name
92
+ # @attr [String] namespace
93
+ # @attr [Integer] namespace_id
94
+ # @attr [String] name_with_namespace
95
+ # @attr [Boolean] only_allow_merge_if_all_discussions_are_resolved
96
+ # @attr [Boolean] only_allow_merge_if_all_status_checks_passed
97
+ # @attr [Boolean] only_allow_merge_if_pipeline_succeeds
98
+ # @attr [Boolean] only_mirror_protected_branches
99
+ # @attr [Integer] open_issues_count
100
+ # @attr [Hash] owner
101
+ # @attr [Boolean] packages_enabled
102
+ # @attr [String] pages_access_level
103
+ # @attr [String] path
104
+ # @attr [String] path_with_namespace
105
+ # @attr [Hash] permissions
106
+ # @attr [Boolean] printing_merge_request_link_enabled
107
+ # @attr [Boolean] printing_merge_requests_link_enabled
108
+ # @attr [Boolean] public_builds
109
+ # @attr [Boolean] public_jobs
110
+ # @attr [String] readme_url
111
+ # @attr [String] releases_access_level
112
+ # @attr [Boolean] remove_source_branch_after_merge
113
+ # @attr [String] repository_access_level
114
+ # @attr [String] repository_object_format
115
+ # @attr [String] repository_storage
116
+ # @attr [Boolean] request_access_enabled
117
+ # @attr [String] requirements_access_level
118
+ # @attr [Boolean] resolve_outdated_diff_discussions
119
+ # @attr [Boolean] restrict_user_defined_variables
120
+ # @attr [String] runners_token
121
+ # @attr [Boolean] secret_push_protection_enabled
122
+ # @attr [String] security_and_compliance_access_level
123
+ # @attr [String] service_desk_address
124
+ # @attr [Boolean] service_desk_enabled
125
+ # @attr [Boolean] shared_runners_enabled
126
+ # @attr [Array] shared_with_groups
127
+ # @attr [Boolean] show_default_award_emojis
128
+ # @attr [String] snippets_access_level
129
+ # @attr [Boolean] snippets_enabled
130
+ # @attr [String] squash_commit_template
131
+ # @attr [String] squash_option
132
+ # @attr [String] ssh_url_to_repo
133
+ # @attr [Integer] star_count
134
+ # @attr [Hash] statistics
135
+ # @attr [String] suggestion_commit_message
136
+ # @attr [String] template_name
137
+ # @attr [Integer] template_project_id
138
+ # @attr [Array] topics
139
+ # @attr [String] updated_at
140
+ # @attr [Boolean] use_custom_template
141
+ # @attr [String] visibility
142
+ # @attr [Boolean] warn_about_potentially_unwanted_characters
143
+ # @attr [String] web_url
144
+ # @attr [String] wiki_access_level
145
+ # @attr [Boolean] wiki_enabled
146
+ # @todo Add create/update example
147
+ # @todo Document members
148
+ # https://docs.gitlab.com/api/members/#list-all-members-of-a-group-or-project
149
+ # https://docs.gitlab.com/api/members/#list-all-members-of-a-group-or-project-including-inherited-and-invited-members
150
+ # @todo Document encoded_path
151
+ # @todo Document tokens
152
+ # @todo Document issues
153
+ # @todo Document merge_requests
154
+ # @todo Document pipelines
155
+ # @todo Document latest pipeline
156
+ # @todo Document latest jobs
157
+ # @todo Document webhooks
158
+ # @todo Document commits
159
+ # @todo Filters on #contributors
160
+ class Projects < SupportOps::GitLab::Base
161
+ # @!parse
162
+ # # Creates/updates a project
163
+ # #
164
+ # # @author Jason Colyer
165
+ # # @since 1.0.0
166
+ # # @return [Object] Instance of {SupportOps::GitLab::Projects}
167
+ # # @note This is inherited from {SupportOps::GitLab::Base#save!}
168
+ # # @see
169
+ # # https://docs.gitlab.com/api/projects/#create-a-project
170
+ # # GitLab API > Projects > Create a project
171
+ # # @see
172
+ # # https://docs.gitlab.com/api/projects/#edit-a-project
173
+ # # GitLab API > Projects > Edit a project
174
+ # def save!; end
175
+ # @!parse
176
+ # # List events for a project
177
+ # #
178
+ # # @author Jason Colyer
179
+ # # @since 1.0.0
180
+ # # @return [Boolean]
181
+ # # @note This is inherited from {SupportOps::GitLab::Base#events}
182
+ # # @see
183
+ # # https://docs.gitlab.com/api/events/#list-all-visible-events-for-a-project
184
+ # # GitLab API > Events > List all visible events for a project
185
+ # # @see SupportOps::GitLab::Configuration Setting up a client
186
+ # # @example
187
+ # # require 'support_ops_gitlab'
188
+ # #
189
+ # # SupportOps::GitLab::Configuration.configure do |config|
190
+ # # config.url = 'https://gitlab.example.com/api/v4'
191
+ # # config.token = 'abc123'
192
+ # # end
193
+ # #
194
+ # # project = SupportOps::GitLab::Projects.get!(123456)
195
+ # # events = project.events
196
+ # # pp events.count
197
+ # # # => 482
198
+ # def events; end
199
+ # @!parse
200
+ # # Get contributor list
201
+ # #
202
+ # # @author Jason Colyer
203
+ # # @since 1.0.0
204
+ # # @return [Boolean]
205
+ # # @note This is inherited from {SupportOps::GitLab::Base#contributors}
206
+ # # @see
207
+ # # https://docs.gitlab.com/api/repositories/#get-contributor-list
208
+ # # GitLab API > Repositories > Get contributor list
209
+ # # @see SupportOps::GitLab::Configuration Setting up a client
210
+ # # @example
211
+ # # require 'support_ops_gitlab'
212
+ # #
213
+ # # SupportOps::GitLab::Configuration.configure do |config|
214
+ # # config.url = 'https://gitlab.example.com/api/v4'
215
+ # # config.token = 'abc123'
216
+ # # end
217
+ # #
218
+ # # project = SupportOps::GitLab::Projects.get!(123456)
219
+ # # contributors = project.contributors
220
+ # # pp contributors.count
221
+ # # # => 13
222
+ # # pp contributors.first['commits']
223
+ # # # => 2
224
+ # def contributors; end
225
+ define_attributes :allow_merge_on_skipped_pipeline,
226
+ :allow_pipeline_trigger_approve_deployment,
227
+ :analytics_access_level, :archived,
228
+ :auto_cancel_pending_pipelines,
229
+ :autoclose_referenced_issues,
230
+ :auto_devops_deploy_strategy, :auto_devops_enabled,
231
+ :avatar_url, :build_git_strategy, :builds_access_level,
232
+ :build_timeout, :can_create_merge_request_in,
233
+ :ci_allow_fork_pipelines_to_run_in_parent_project,
234
+ :ci_config_path, :ci_default_git_depth,
235
+ :ci_forward_deployment_enabled,
236
+ :ci_forward_deployment_rollback_allowed,
237
+ :ci_id_token_sub_claim_components,
238
+ :ci_pipeline_variables_minimum_override_role,
239
+ :ci_push_repository_for_job_token_allowed,
240
+ :ci_restrict_pipeline_cancellation_role,
241
+ :ci_separated_caches, :compliance_frameworks,
242
+ :container_expiration_policy,
243
+ :container_expiration_policy_attributes,
244
+ :container_registry_access_level,
245
+ :container_registry_enabled,
246
+ :container_registry_image_prefix, :created_at,
247
+ :creator_id, :default_branch, :description,
248
+ :description_html, :emails_enabled,
249
+ :enforce_auth_checks_on_uploads,
250
+ :environments_access_level,
251
+ :external_authorization_classification_label,
252
+ :feature_flags_access_level, :forked_from_project,
253
+ :forking_access_level, :forks_count,
254
+ :group_runners_enabled,
255
+ :group_with_project_templates_id, :http_url_to_repo,
256
+ :id, :import_error, :import_status, :import_type,
257
+ :import_url, :infrastructure_access_level,
258
+ :initialize_with_readme, :issue_branch_template,
259
+ :issues_access_level, :issues_enabled, :issues_template,
260
+ :jobs_enabled, :last_activity_at, :lfs_enabled,
261
+ :license, :license_url, :_links,
262
+ :marked_for_deletion_on, :merge_commit_template,
263
+ :merge_method, :merge_pipelines_enabled,
264
+ :merge_requests_access_level, :merge_requests_enabled,
265
+ :merge_requests_template, :merge_trains_enabled,
266
+ :merge_trains_skip_train_allowed, :mirror,
267
+ :mirror_overwrites_diverged_branches,
268
+ :mirror_trigger_builds, :mirror_user_id,
269
+ :model_experiments_access_level,
270
+ :model_registry_access_level, :monitor_access_level,
271
+ :mr_default_target_self, :name, :namespace,
272
+ :namespace_id, :name_with_namespace,
273
+ :only_allow_merge_if_all_discussions_are_resolved,
274
+ :only_allow_merge_if_all_status_checks_passed,
275
+ :only_allow_merge_if_pipeline_succeeds,
276
+ :only_mirror_protected_branches, :open_issues_count,
277
+ :owner, :packages_enabled, :pages_access_level, :path,
278
+ :path_with_namespace, :permissions,
279
+ :printing_merge_request_link_enabled,
280
+ :printing_merge_requests_link_enabled, :public_builds,
281
+ :public_jobs, :readme_url, :releases_access_level,
282
+ :remove_source_branch_after_merge,
283
+ :repository_access_level, :repository_object_format,
284
+ :repository_storage, :request_access_enabled,
285
+ :requirements_access_level,
286
+ :resolve_outdated_diff_discussions,
287
+ :restrict_user_defined_variables, :runners_token,
288
+ :secret_push_protection_enabled,
289
+ :security_and_compliance_access_level,
290
+ :service_desk_address, :service_desk_enabled,
291
+ :shared_runners_enabled, :shared_with_groups,
292
+ :show_default_award_emojis, :snippets_access_level,
293
+ :snippets_enabled, :squash_commit_template,
294
+ :squash_option, :ssh_url_to_repo, :star_count,
295
+ :statistics, :suggestion_commit_message, :template_name,
296
+ :template_project_id, :topics, :updated_at,
297
+ :use_custom_template, :visibility,
298
+ :warn_about_potentially_unwanted_characters, :web_url,
299
+ :wiki_access_level, :wiki_enabled
300
+ readonly_attributes :allow_pipeline_trigger_approve_deployment, :archived,
301
+ :avatar_url, :can_create_merge_request_in,
302
+ :ci_allow_fork_pipelines_to_run_in_parent_project,
303
+ :ci_default_git_depth, :ci_forward_deployment_enabled,
304
+ :ci_forward_deployment_rollback_allowed,
305
+ :ci_id_token_sub_claim_components,
306
+ :ci_pipeline_variables_minimum_override_role,
307
+ :ci_push_repository_for_job_token_allowed,
308
+ :ci_restrict_pipeline_cancellation_role,
309
+ :ci_separated_caches, :compliance_frameworks,
310
+ :container_expiration_policy,
311
+ :container_registry_enabled,
312
+ :container_registry_image_prefix, :created_at,
313
+ :creator_id, :description_html,
314
+ :enforce_auth_checks_on_uploads, :forked_from_project,
315
+ :forks_count, :http_url_to_repo, :id, :import_error,
316
+ :import_status, :import_type, :issue_branch_template,
317
+ :issues_enabled, :issues_template, :jobs_enabled,
318
+ :last_activity_at, :license, :license_url, :_links,
319
+ :marked_for_deletion_on, :merge_commit_template,
320
+ :merge_requests_enabled, :merge_requests_template,
321
+ :mirror_overwrites_diverged_branches, :mirror_user_id,
322
+ :mr_default_target_self, :namespace,
323
+ :name_with_namespace, :only_mirror_protected_branches,
324
+ :open_issues_count, :owner, :pages_access_level,
325
+ :path_with_namespace, :permissions,
326
+ :printing_merge_requests_link_enabled, :public_builds,
327
+ :readme_url, :runners_token,
328
+ :secret_push_protection_enabled,
329
+ :service_desk_address, :service_desk_enabled,
330
+ :shared_with_groups, :snippets_enabled,
331
+ :squash_commit_template, :ssh_url_to_repo,
332
+ :star_count, :statistics, :suggestion_commit_message,
333
+ :updated_at, :web_url, :wiki_enabled
334
+
335
+ ##
336
+ # Lists projects in the GitLab system
337
+ #
338
+ # @author Jason Colyer
339
+ # @since 1.0.0
340
+ # @overload list(key: value)
341
+ # @param active [Boolean optional] Limit by projects that are not archived and not marked for deletion.
342
+ # @param archived [Boolean optional] Limit by archived status.
343
+ # @param id_after [Integer optional] Limit results to projects with IDs greater than the specified ID.
344
+ # @param id_before [Integer optional] Limit results to projects with IDs less than the specified ID.
345
+ # @param imported [Boolean optional] Limit results to projects which were imported from external systems by current user.
346
+ # @param include_hidden [Boolean optional] Include hidden projects. (administrators only) Premium and Ultimate only.
347
+ # @param include_pending_delete [Boolean optional] Include projects pending deletion. (administrators only)
348
+ # @param last_activity_after [String optional] Limit results to projects with last activity after specified time. Format: ISO 8601 (YYYY-MM-DDTHH:MM:SSZ)
349
+ # @param last_activity_before [String optional] Limit results to projects with last activity before specified time. Format: ISO 8601 (YYYY-MM-DDTHH:MM:SSZ)
350
+ # @param marked_for_deletion_on [Boolean optional] Filter by date when project was marked for deletion. Introduced in GitLab 17.1. Premium and Ultimate only.
351
+ # @param membership [Boolean optional] Limit by projects that the current user is a member of.
352
+ # @param min_access_level [Integer optional] Limit by current user minimal role (access_level).
353
+ # @param order_by [String optional] Return projects ordered by id, name, path, created_at, updated_at, star_count, last_activity_at, or similarity fields. repository_size, storage_size, packages_size or wiki_size fields are only allowed for administrators. similarity is only available when searching and is limited to projects that the current user is a member of. Default is created_at.
354
+ # @param owned [Boolean optional] Limit by projects explicitly owned by the current user.
355
+ # @param repository_checksum_failed [Boolean optional] Limit projects where the repository checksum calculation has failed. Premium and Ultimate only.
356
+ # @param repository_storage [String optional] Limit results to projects stored on repository_storage. (administrators only)
357
+ # @param search_namespaces [Boolean optional] Include ancestor namespaces when matching search criteria. Default is false.
358
+ # @param sort [String optional] Return projects sorted in asc or desc order. Default is desc.
359
+ # @param starred [Boolean optional] Limit by projects starred by the current user.
360
+ # @param statistics [Boolean optional] Include project statistics. Available only to users with at least the Reporter role.
361
+ # @param topic [String optional] Comma-separated topic names. Limit results to projects that match all of given topics. See topics attribute.
362
+ # @param topic_id [Integer optional] Limit results to projects with the assigned topic given by the topic ID.
363
+ # @param updated_after [String optional] Limit results to projects last updated after the specified time. Format: ISO 8601 (YYYY-MM-DDTHH:MM:SSZ). Introduced in GitLab 15.10. For this filter to work, you must also provide updated_at as the order_by attribute.
364
+ # @param updated_before [String optional] Limit results to projects last updated before the specified time. Format: ISO 8601 (YYYY-MM-DDTHH:MM:SSZ). Introduced in GitLab 15.10. For this filter to work, you must also provide updated_at as the order_by attribute.
365
+ # @param visibility [String optional] Limit by visibility public, internal, or private.
366
+ # @param wiki_checksum_failed [Boolean optional] Limit projects where the wiki checksum calculation has failed. Premium and Ultimate only.
367
+ # @param with_custom_attributes [Boolean optional] Include custom attributes in response. (administrator only)
368
+ # @param with_issues_enabled [Boolean optional] Limit by enabled issues feature.
369
+ # @param with_merge_requests_enabled [Boolean optional] Limit by enabled merge requests feature.
370
+ # @param with_programming_language [String optional] Limit by projects which use the given programming language.
371
+ # @param limit [Integer optional] The limit to the number of users
372
+ # returned. Default to 0 (i.e. no limit)
373
+ # @return [Array]
374
+ # @see
375
+ # https://docs.gitlab.com/api/projects/#list-projects
376
+ # GitLab API > Projects > List all projects
377
+ # @see SupportOps::GitLab::Configuration Setting up a client
378
+ # @example
379
+ # require 'support_ops_gitlab'
380
+ #
381
+ # SupportOps::GitLab::Configuration.configure do |config|
382
+ # config.url = 'https://gitlab.example.com/api/v4'
383
+ # config.token = 'abc123'
384
+ # end
385
+ #
386
+ # projects = SupportOps::GitLab::Projects.list(limit: 250)
387
+ # pp projects.count
388
+ # # => 250
389
+ # pp projects.last.star_count
390
+ # # => 4
391
+ def self.list(**args)
392
+ args[:active] = nil unless args[:active]
393
+ args[:archived] = nil unless args[:archived]
394
+ args[:id_after] = nil unless args[:id_after]
395
+ args[:id_before] = nil unless args[:id_before]
396
+ args[:imported] = nil unless args[:imported]
397
+ args[:include_hidden] = nil unless args[:include_hidden]
398
+ args[:include_pending_delete] = nil unless args[:include_pending_delete]
399
+ args[:last_activity_after] = nil unless args[:last_activity_after]
400
+ args[:last_activity_before] = nil unless args[:last_activity_before]
401
+ args[:marked_for_deletion_on] = nil unless args[:marked_for_deletion_on]
402
+ args[:membership] = nil unless args[:membership]
403
+ args[:min_access_level] = nil unless args[:min_access_level]
404
+ args[:order_by] = nil unless args[:order_by]
405
+ args[:owned] = nil unless args[:owned]
406
+ args[:repository_checksum_failed] = nil unless args[:repository_checksum_failed]
407
+ args[:repository_storage] = nil unless args[:repository_storage]
408
+ args[:search_namespaces] = nil unless args[:search_namespaces]
409
+ args[:sort] = nil unless args[:sort]
410
+ args[:starred] = nil unless args[:starred]
411
+ args[:statistics] = nil unless args[:statistics]
412
+ args[:topic] = nil unless args[:topic]
413
+ args[:topic_id] = nil unless args[:topic_id]
414
+ args[:updated_after] = nil unless args[:updated_after]
415
+ args[:updated_before] = nil unless args[:updated_before]
416
+ args[:visibility] = nil unless args[:visibility]
417
+ args[:wiki_checksum_failed] = nil unless args[:wiki_checksum_failed]
418
+ args[:with_custom_attributes] = nil unless args[:with_custom_attributes]
419
+ args[:with_issues_enabled] = nil unless args[:with_issues_enabled]
420
+ args[:with_merge_requests_enabled] = nil unless args[:with_merge_requests_enabled]
421
+ args[:with_programming_language] = nil unless args[:with_programming_language]
422
+ args[:limit] = 0 unless args[:limit]
423
+ params = ''
424
+ params += "active=#{args[:active]}&" unless args[:active].nil?
425
+ params += "archived=#{args[:archived]}&" unless args[:archived].nil?
426
+ params += "id_after=#{args[:id_after]}&" unless args[:id_after].nil?
427
+ params += "id_before=#{args[:id_before]}&" unless args[:id_before].nil?
428
+ params += "imported=#{args[:imported]}&" unless args[:imported].nil?
429
+ params += "include_hidden=#{args[:include_hidden]}&" unless args[:include_hidden].nil?
430
+ params += "include_pending_delete=#{args[:include_pending_delete]}&" unless args[:include_pending_delete].nil?
431
+ params += "last_activity_after=#{args[:last_activity_after]}&" unless args[:last_activity_after].nil?
432
+ params += "last_activity_before=#{args[:last_activity_before]}&" unless args[:last_activity_before].nil?
433
+ params += "marked_for_deletion_on=#{args[:marked_for_deletion_on]}&" unless args[:marked_for_deletion_on].nil?
434
+ params += "membership=#{args[:membership]}&" unless args[:membership].nil?
435
+ params += "min_access_level=#{args[:min_access_level]}&" unless args[:min_access_level].nil?
436
+ params += "order_by=#{args[:order_by]}&" unless args[:order_by].nil?
437
+ params += "owned=#{args[:owned]}&" unless args[:owned].nil?
438
+ params += "repository_checksum_failed=#{args[:repository_checksum_failed]}&" unless args[:repository_checksum_failed].nil?
439
+ params += "repository_storage=#{args[:repository_storage]}&" unless args[:repository_storage].nil?
440
+ params += "search_namespaces=#{args[:search_namespaces]}&" unless args[:search_namespaces].nil?
441
+ params += "sort=#{args[:sort]}&" unless args[:sort].nil?
442
+ params += "starred=#{args[:starred]}&" unless args[:starred].nil?
443
+ params += "statistics=#{args[:statistics]}&" unless args[:statistics].nil?
444
+ params += "topic=#{args[:topic]}&" unless args[:topic].nil?
445
+ params += "topic_id=#{args[:topic_id]}&" unless args[:topic_id].nil?
446
+ params += "updated_after=#{args[:updated_after]}&" unless args[:updated_after].nil?
447
+ params += "updated_before=#{args[:updated_before]}&" unless args[:updated_before].nil?
448
+ params += "visibility=#{args[:visibility]}&" unless args[:visibility].nil?
449
+ params += "wiki_checksum_failed=#{args[:wiki_checksum_failed]}&" unless args[:wiki_checksum_failed].nil?
450
+ params += "with_custom_attributes=#{args[:with_custom_attributes]}&" unless args[:with_custom_attributes].nil?
451
+ params += "with_issues_enabled=#{args[:with_issues_enabled]}&" unless args[:with_issues_enabled].nil?
452
+ params += "with_merge_requests_enabled=#{args[:with_merge_requests_enabled]}&" unless args[:with_merge_requests_enabled].nil?
453
+ params += "with_programming_language=#{args[:with_programming_language]}&" unless args[:with_programming_language].nil?
454
+ array = []
455
+ page = 1
456
+ loop do
457
+ response = client.connection.get("projects?#{params}&page=#{page}&per_page=100")
458
+ body = Oj.load(response.body)
459
+ array += body.map { |p| Projects.new(p) }
460
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
461
+ break if body.count < 100
462
+
463
+ page += 1
464
+ end
465
+ return array if args[:limit].to_i.zero?
466
+
467
+ array.first(args[:limit].to_i)
468
+ end
469
+
470
+ ##
471
+ # Search for projects by name
472
+ #
473
+ # @author Jason Colyer
474
+ # @since 1.0.0
475
+ # @overload list(key: value)
476
+ # @param query [String optional] A string contained in the project name
477
+ # @param sort [String optional] Return requests ordered by id, name,
478
+ # created_at, star_count, or last_activity_at fields.
479
+ # @param order_by [String optional] Return requests sorted in asc or
480
+ # desc order
481
+ # @param limit [Integer optional] The limit to the number of users
482
+ # returned. Default to 0 (i.e. no limit)
483
+ # @return [Array]
484
+ # @see
485
+ # https://docs.gitlab.com/api/projects/#search-for-projects-by-name
486
+ # GitLab API > Projects > Search for projects by name
487
+ # @see SupportOps::GitLab::Configuration Setting up a client
488
+ # @example
489
+ # require 'support_ops_gitlab'
490
+ #
491
+ # SupportOps::GitLab::Configuration.configure do |config|
492
+ # config.url = 'https://gitlab.example.com/api/v4'
493
+ # config.token = 'abc123'
494
+ # end
495
+ #
496
+ # projects = SupportOps::GitLab::Projects.Search(query: 'Awesome', limit: 25)
497
+ # pp projects.count
498
+ # # => 25
499
+ # pp projects.last.name
500
+ # # => "Jason / Awesome project"
501
+ def self.search(**args)
502
+ args[:query] = nil unless args[:query]
503
+ raise 'You have to provide a search query' if args[:query].nil?
504
+
505
+ args[:order_by] = nil unless args[:order_by]
506
+ args[:sort] = nil unless args[:sort]
507
+ args[:limit] = 0 unless args[:limit]
508
+ params = ''
509
+ params += "order_by=#{args[:order_by]}&" unless args[:order_by].nil?
510
+ params += "sort=#{args[:sort]}&" unless args[:sort].nil?
511
+ params += "search=#{args[:query]}"
512
+ array = []
513
+ page = 1
514
+ loop do
515
+ response = client.connection.get("projects?#{params}&page=#{page}&per_page=100")
516
+ body = Oj.load(response.body)
517
+ pp body
518
+ array += body.map { |p| Projects.new(p) }
519
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
520
+ break if body.count < 100
521
+
522
+ page += 1
523
+ end
524
+ return array if args[:limit].to_i.zero?
525
+
526
+ array.first(args[:limit].to_i)
527
+ end
528
+
529
+ ##
530
+ # Locates a specific project in the GitLab system
531
+ #
532
+ # @author Jason Colyer
533
+ # @since 1.0.0
534
+ # @see
535
+ # https://docs.gitlab.com/api/projects/#get-a-single-project
536
+ # GitLab API > Projects > Get a single project
537
+ # @see SupportOps::GitLab::Configuration Setting up a client
538
+ # @example
539
+ # require 'support_ops_gitlab'
540
+ #
541
+ # SupportOps::GitLab::Configuration.configure do |config|
542
+ # config.url = 'https://gitlab.com/api/v4'
543
+ # config.token = 'abc123'
544
+ # end
545
+ #
546
+ # project = SupportOps::GitLab::Projects.get(13983927615772)
547
+ # pp project.name
548
+ # # => "Awesome project"
549
+ def self.get(object)
550
+ if object.is_a? Projects
551
+ Projects.new(id: id).find
552
+ else
553
+ Projects.new(id: object).find
554
+ end
555
+ end
556
+
557
+ ##
558
+ # Locates a specific project in the GitLab system
559
+ #
560
+ # @author Jason Colyer
561
+ # @since 1.0.0
562
+ # @see
563
+ # https://docs.gitlab.com/api/projects/#get-a-single-project
564
+ # GitLab API > Projects > Get a single project
565
+ # @see SupportOps::GitLab::Configuration Setting up a client
566
+ # @example
567
+ # require 'support_ops_gitlab'
568
+ #
569
+ # SupportOps::GitLab::Configuration.configure do |config|
570
+ # config.url = 'https://gitlab.com/api/v4'
571
+ # config.token = 'abc123'
572
+ # end
573
+ #
574
+ # project = SupportOps::GitLab::Projects.get!(13983927615772)
575
+ # pp project.name
576
+ # # => "Awesome project"
577
+ def self.get!(object)
578
+ if object.is_a? Projects
579
+ Projects.new(id: id).find!
580
+ else
581
+ Projects.new(id: object).find!
582
+ end
583
+ end
584
+
585
+ private
586
+
587
+ ##
588
+ # @private
589
+ def get_record
590
+ response = self.client.connection.get("projects/#{self.id}")
591
+ return nil if response.status != 200
592
+
593
+ Oj.load(response.body)
594
+ end
595
+
596
+ ##
597
+ # @private
598
+ def create_record
599
+ response = self.client.connection.post('projects', attributes_for_save.to_json)
600
+ body = Oj.load(response.body)
601
+ raise "Failed to create project => #{body}" if response.status != 201
602
+ body
603
+ end
604
+
605
+ ##
606
+ # @private
607
+ def update_record
608
+ raise "Failed to update project => You didn't change anything in the object" if attributes_for_save.keys == [:id]
609
+ response = self.client.connection.put("projects/#{self.id}", attributes_for_save.to_json)
610
+ body = Oj.load(response.body)
611
+ raise "Failed to update project #{self.id} => #{body}" if response.status != 200
612
+ body
613
+ end
614
+
615
+ ##
616
+ # @private
617
+ def members_record(**args)
618
+ args[:all] = false unless args[:all]
619
+ args[:query] = nil unless args[:query]
620
+ args[:user_ids] = nil unless args[:user_ids]
621
+ args[:skip_users] = nil unless args[:skip_users]
622
+ args[:show_seat_info] = nil unless args[:show_seat_info]
623
+ params = ''
624
+ params += "query&" unless args[:query].nil?
625
+ params += "user_ids&" unless args[:user_ids].nil?
626
+ params += "skip_users&" unless args[:skip_users].nil?
627
+ params += "show_seat_info&" unless args[:show_seat_info].nil?
628
+ base_url = if args[:all]
629
+ "projects/#{self.id}/members/all"
630
+ else
631
+ "projects/#{self.id}/members"
632
+ end
633
+ array = []
634
+ page = 1
635
+ loop do
636
+ response = self.client.connection.get("#{base_url}?#{params}&page=#{page}&per_page=100")
637
+ pp "#{base_url}?#{params}&page=#{page}&per_page=100"
638
+ body = Oj.load(response.body)
639
+ array += body.map { |p| ProjectMemberships.new(p) }
640
+ break if body.count < 100
641
+ page += 1
642
+ end
643
+ array
644
+ end
645
+
646
+ ##
647
+ # @private
648
+ def encoded_path_record
649
+ ERB::Util.url_encode(self.path_with_namespace)
650
+ end
651
+
652
+ ##
653
+ # @private
654
+ def tokens_record
655
+ ProjectAccessTokens.list(project_id: self.id)
656
+ end
657
+
658
+ ##
659
+ # @private
660
+ def badges_record
661
+ Badges.list(project_id: self.id)
662
+ end
663
+
664
+ ##
665
+ # @private
666
+ def issues_record
667
+ Issues.list(project_id: self.id)
668
+ end
669
+
670
+ ##
671
+ # @private
672
+ def merge_requests_record
673
+ MergeRequests.list(project_id: self.id)
674
+ end
675
+
676
+ ##
677
+ # @private
678
+ def pipelines_record
679
+ Pipelines.list(project_id: self.id)
680
+ end
681
+
682
+ ##
683
+ # @private
684
+ def latest_pipeline_record
685
+ response = self.client.connection.get("projects/#{self.id}/pipelines/latest")
686
+ body = Oj.load(response.body)
687
+ Pipelines.new(body)
688
+ end
689
+
690
+ ##
691
+ # @private
692
+ def jobs_record
693
+ array = []
694
+ page = 1
695
+ loop do
696
+ response = self.client.connection.get("projects/#{self.id}/jobs?per_page=100&page=#{page}")
697
+ body = Oj.load(response.body)
698
+ array += body.map { |j| Jobs.new(j) }
699
+ break if body.count < 100
700
+
701
+ page += 1
702
+ end
703
+ array
704
+ end
705
+
706
+ ##
707
+ # @private
708
+ def webhooks_record
709
+ ProjectWebhooks.list(project_id: self.id)
710
+ end
711
+
712
+ ##
713
+ # @private
714
+ def commits_record
715
+ Commits.list(project_id: self.id)
716
+ end
717
+
718
+ ##
719
+ # @private
720
+ def events_record
721
+ Events.list_project(project_id: self.id)
722
+ end
723
+
724
+ ##
725
+ # @private
726
+ def contributors_record
727
+ array = []
728
+ page = 1
729
+ loop do
730
+ response = self.client.connection.get("projects/#{self.id}/repository/contributors?per_page=100&page=#{page}")
731
+ body = Oj.load(response.body)
732
+ array += body
733
+ break if body.count < 100
734
+
735
+ page += 1
736
+ end
737
+ array
738
+ end
739
+ end
740
+ end
741
+ end