2018-07-18 12:03:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-20 11:12:06 -04:00
|
|
|
module TestHooks
|
|
|
|
class SystemService < TestHooks::BaseService
|
2020-06-09 08:08:55 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
2017-07-20 11:12:06 -04:00
|
|
|
|
2020-06-09 08:08:55 -04:00
|
|
|
private
|
2017-07-20 11:12:06 -04:00
|
|
|
|
2020-06-09 08:08:55 -04:00
|
|
|
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-07-20 11:12:06 -04:00
|
|
|
end
|
2017-09-20 04:41:43 -04:00
|
|
|
|
|
|
|
def merge_requests_events_data
|
2021-02-16 01:09:07 -05:00
|
|
|
merge_request = MergeRequest.of_projects(current_user.projects.select(:id)).last
|
2021-02-11 04:09:18 -05:00
|
|
|
|
2020-06-09 08:08:55 -04:00
|
|
|
return { error: s_('TestHooks|Ensure one of your projects has merge requests.') } unless merge_request.present?
|
2017-09-20 04:41:43 -04:00
|
|
|
|
|
|
|
merge_request.to_hook_data(current_user)
|
|
|
|
end
|
2017-07-20 11:12:06 -04:00
|
|
|
end
|
|
|
|
end
|