2018-07-18 12:03:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-20 11:12:06 -04:00
|
|
|
module TestHooks
|
|
|
|
class ProjectService < TestHooks::BaseService
|
2018-05-21 22:24:37 -04:00
|
|
|
attr_writer :project
|
2017-07-20 11:12:06 -04:00
|
|
|
|
|
|
|
def project
|
|
|
|
@project ||= hook.project
|
|
|
|
end
|
|
|
|
|
2018-05-21 22:24:37 -04:00
|
|
|
private
|
|
|
|
|
2017-07-20 11:12:06 -04:00
|
|
|
def push_events_data
|
2019-04-15 08:25:48 -04:00
|
|
|
throw(:validation_error, s_('TestHooks|Ensure the project has at least one commit.')) if project.empty_repo?
|
2017-07-20 11:12:06 -04:00
|
|
|
|
|
|
|
Gitlab::DataBuilder::Push.build_sample(project, current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :tag_push_events_data, :push_events_data
|
|
|
|
|
|
|
|
def note_events_data
|
|
|
|
note = project.notes.first
|
2019-04-15 08:25:48 -04:00
|
|
|
throw(:validation_error, s_('TestHooks|Ensure the project has notes.')) unless note.present?
|
2017-07-20 11:12:06 -04:00
|
|
|
|
|
|
|
Gitlab::DataBuilder::Note.build(note, current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def issues_events_data
|
|
|
|
issue = project.issues.first
|
2019-04-15 08:25:48 -04:00
|
|
|
throw(:validation_error, s_('TestHooks|Ensure the project has issues.')) unless issue.present?
|
2017-07-20 11:12:06 -04:00
|
|
|
|
|
|
|
issue.to_hook_data(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :confidential_issues_events_data, :issues_events_data
|
|
|
|
|
|
|
|
def merge_requests_events_data
|
|
|
|
merge_request = project.merge_requests.first
|
2019-04-15 08:25:48 -04:00
|
|
|
throw(:validation_error, s_('TestHooks|Ensure the project has merge requests.')) unless merge_request.present?
|
2017-07-20 11:12:06 -04:00
|
|
|
|
|
|
|
merge_request.to_hook_data(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def job_events_data
|
|
|
|
build = project.builds.first
|
2019-04-15 08:25:48 -04:00
|
|
|
throw(:validation_error, s_('TestHooks|Ensure the project has CI jobs.')) unless build.present?
|
2017-07-20 11:12:06 -04:00
|
|
|
|
|
|
|
Gitlab::DataBuilder::Build.build(build)
|
|
|
|
end
|
|
|
|
|
|
|
|
def pipeline_events_data
|
2018-12-05 09:39:15 -05:00
|
|
|
pipeline = project.ci_pipelines.first
|
2019-04-15 08:25:48 -04:00
|
|
|
throw(:validation_error, s_('TestHooks|Ensure the project has CI pipelines.')) unless pipeline.present?
|
2017-07-20 11:12:06 -04:00
|
|
|
|
|
|
|
Gitlab::DataBuilder::Pipeline.build(pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_page_events_data
|
2019-04-25 00:19:07 -04:00
|
|
|
page = project.wiki.list_pages(limit: 1).first
|
2017-07-20 11:12:06 -04:00
|
|
|
if !project.wiki_enabled? || page.blank?
|
2019-04-15 08:25:48 -04:00
|
|
|
throw(:validation_error, s_('TestHooks|Ensure the wiki is enabled and has pages.'))
|
2017-07-20 11:12:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::DataBuilder::WikiPage.build(page, current_user, 'create')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|