diff options
Diffstat (limited to 'app/services/concerns')
-rw-r--r-- | app/services/concerns/exclusive_lease_guard.rb | 2 | ||||
-rw-r--r-- | app/services/concerns/integrations/project_test_data.rb | 62 | ||||
-rw-r--r-- | app/services/concerns/measurable.rb | 2 | ||||
-rw-r--r-- | app/services/concerns/spam_check_methods.rb | 11 |
4 files changed, 70 insertions, 7 deletions
diff --git a/app/services/concerns/exclusive_lease_guard.rb b/app/services/concerns/exclusive_lease_guard.rb index 0c5ecca3a50..4678d051d29 100644 --- a/app/services/concerns/exclusive_lease_guard.rb +++ b/app/services/concerns/exclusive_lease_guard.rb @@ -58,6 +58,6 @@ module ExclusiveLeaseGuard end def log_error(message, extra_args = {}) - Rails.logger.error(message) # rubocop:disable Gitlab/RailsLogger + Gitlab::AppLogger.error(message) end end diff --git a/app/services/concerns/integrations/project_test_data.rb b/app/services/concerns/integrations/project_test_data.rb new file mode 100644 index 00000000000..4d551430315 --- /dev/null +++ b/app/services/concerns/integrations/project_test_data.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +module Integrations + module ProjectTestData + private + + def push_events_data + Gitlab::DataBuilder::Push.build_sample(project, current_user) + end + + def note_events_data + note = project.notes.first + return { error: s_('TestHooks|Ensure the project has notes.') } unless note.present? + + Gitlab::DataBuilder::Note.build(note, current_user) + end + + def issues_events_data + issue = project.issues.first + return { error: s_('TestHooks|Ensure the project has issues.') } unless issue.present? + + issue.to_hook_data(current_user) + end + + def merge_requests_events_data + merge_request = project.merge_requests.first + return { error: s_('TestHooks|Ensure the project has merge requests.') } unless merge_request.present? + + merge_request.to_hook_data(current_user) + end + + def job_events_data + build = project.builds.first + return { error: s_('TestHooks|Ensure the project has CI jobs.') } unless build.present? + + Gitlab::DataBuilder::Build.build(build) + end + + def pipeline_events_data + pipeline = project.ci_pipelines.newest_first.first + return { error: s_('TestHooks|Ensure the project has CI pipelines.') } unless pipeline.present? + + Gitlab::DataBuilder::Pipeline.build(pipeline) + end + + def wiki_page_events_data + page = project.wiki.list_pages(limit: 1).first + if !project.wiki_enabled? || page.blank? + return { error: s_('TestHooks|Ensure the wiki is enabled and has pages.') } + end + + Gitlab::DataBuilder::WikiPage.build(page, current_user, 'create') + end + + def deployment_events_data + deployment = project.deployments.first + return { error: s_('TestHooks|Ensure the project has deployments.') } unless deployment.present? + + Gitlab::DataBuilder::Deployment.build(deployment) + end + end +end diff --git a/app/services/concerns/measurable.rb b/app/services/concerns/measurable.rb index 5a74f15506e..b099a58a9ae 100644 --- a/app/services/concerns/measurable.rb +++ b/app/services/concerns/measurable.rb @@ -4,8 +4,6 @@ # Example: # ``` # class DummyService -# prepend Measurable -# # def execute # # ... # end diff --git a/app/services/concerns/spam_check_methods.rb b/app/services/concerns/spam_check_methods.rb index 53e9e001463..939f8f183ab 100644 --- a/app/services/concerns/spam_check_methods.rb +++ b/app/services/concerns/spam_check_methods.rb @@ -22,15 +22,18 @@ module SpamCheckMethods # a dirty instance, which means it should be already assigned with the new # attribute values. # rubocop:disable Gitlab/ModuleWithInstanceVariables - def spam_check(spammable, user) + def spam_check(spammable, user, action:) + raise ArgumentError.new('Please provide an action, such as :create') unless action + Spam::SpamActionService.new( spammable: spammable, - request: @request + request: @request, + user: user, + context: { action: action } ).execute( api: @api, recaptcha_verified: @recaptcha_verified, - spam_log_id: @spam_log_id, - user: user) + spam_log_id: @spam_log_id) end # rubocop:enable Gitlab/ModuleWithInstanceVariables end |