2015-09-25 12:07:36 +05:30
|
|
|
module Ci
|
|
|
|
class CreateTriggerRequestService
|
|
|
|
def execute(project, trigger, ref, variables = nil)
|
2015-12-23 02:04:40 +05:30
|
|
|
commit = project.commit(ref)
|
2015-09-25 12:07:36 +05:30
|
|
|
return unless commit
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
# check if ref is tag
|
2015-12-23 02:04:40 +05:30
|
|
|
tag = project.repository.find_tag(ref).present?
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
pipeline = project.pipelines.create(sha: commit.sha, ref: ref, tag: tag)
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
trigger_request = trigger.trigger_requests.create!(
|
2015-10-24 18:46:33 +05:30
|
|
|
variables: variables,
|
2016-06-16 23:09:34 +05:30
|
|
|
pipeline: pipeline,
|
2015-09-25 12:07:36 +05:30
|
|
|
)
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
if pipeline.create_builds(nil, trigger_request)
|
2015-09-25 12:07:36 +05:30
|
|
|
trigger_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|