debian-mirror-gitlab/app/services/test_hooks/system_service.rb

31 lines
815 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module TestHooks
class SystemService < TestHooks::BaseService
2020-06-23 00:09:42 +05:30
include Gitlab::Utils::StrongMemoize
2017-09-10 17:25:29 +05:30
2020-06-23 00:09:42 +05:30
private
2017-09-10 17:25:29 +05:30
2020-06-23 00:09:42 +05:30
def data
strong_memoize(:data) do
case trigger
when 'push_events', 'tag_push_events'
Gitlab::DataBuilder::Push.sample_data
when 'repository_update_events'
Gitlab::DataBuilder::Repository.sample_data
when 'merge_requests_events'
merge_requests_events_data
end
end
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
def merge_requests_events_data
2021-03-11 19:13:27 +05:30
merge_request = MergeRequest.of_projects(current_user.projects.select(:id)).last
2020-06-23 00:09:42 +05:30
return { error: s_('TestHooks|Ensure one of your projects has merge requests.') } unless merge_request.present?
2018-03-17 18:26:18 +05:30
merge_request.to_hook_data(current_user)
end
2017-09-10 17:25:29 +05:30
end
end