2015-08-25 21:42:46 -04:00
|
|
|
module Ci
|
|
|
|
class CreateTriggerRequestService
|
|
|
|
def execute(project, trigger, ref, variables = nil)
|
2015-12-04 06:55:23 -05:00
|
|
|
commit = project.commit(ref)
|
2015-10-05 08:31:51 -04:00
|
|
|
return unless commit
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2015-10-05 07:37:50 -04:00
|
|
|
# check if ref is tag
|
2015-12-04 06:55:23 -05:00
|
|
|
tag = project.repository.find_tag(ref).present?
|
2015-10-05 08:31:51 -04:00
|
|
|
|
2016-06-03 10:27:50 -04:00
|
|
|
pipeline = project.pipelines.create(sha: commit.sha, ref: ref, tag: tag)
|
2015-10-05 07:37:50 -04:00
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
trigger_request = trigger.trigger_requests.create!(
|
2015-10-05 10:21:18 -04:00
|
|
|
variables: variables,
|
2016-06-07 08:51:00 -04:00
|
|
|
pipeline: pipeline,
|
2015-08-25 21:42:46 -04:00
|
|
|
)
|
|
|
|
|
2016-06-03 10:27:50 -04:00
|
|
|
if pipeline.create_builds(nil, trigger_request)
|
2015-08-25 21:42:46 -04:00
|
|
|
trigger_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|