gitlab-org--gitlab-foss/app/services/create_commit_builds_service.rb

70 lines
1.4 KiB
Ruby
Raw Normal View History

class CreateCommitBuildsService
def execute(project, user, params)
return unless project.builds_enabled?
2016-03-31 13:51:28 -04:00
before_sha = params[:checkout_sha] || params[:before]
sha = params[:checkout_sha] || params[:after]
origin_ref = params[:ref]
2015-12-11 11:57:04 -05:00
ref = Gitlab::Git.ref_name(origin_ref)
2016-03-31 13:51:28 -04:00
tag = Gitlab::Git.tag_ref?(origin_ref)
# Skip branch removal
2015-12-11 11:57:04 -05:00
if sha == Gitlab::Git::BLANK_SHA
return false
end
2016-07-15 09:42:29 -04:00
@pipeline = Ci::Pipeline.new(
project: project,
sha: sha,
ref: ref,
before_sha: before_sha,
tag: tag,
user: user)
##
# Skip creating pipeline if no gitlab-ci.yml is found
#
unless @pipeline.ci_yaml_file
return false
end
##
# Skip creating builds for commits that have [ci skip]
# but save pipeline object
#
if @pipeline.skip_ci?
return save_pipeline!
end
##
# Skip creating builds when CI config is invalid
# but save pipeline object
#
unless @pipeline.config_processor
return save_pipeline!
end
##
# Skip creating pipeline object if there are no builds for it.
#
unless @pipeline.create_builds(user)
@pipeline.errors.add(:base, 'No builds created')
return false
end
save_pipeline!
end
private
##
# Create a new pipeline and touch object to calculate status
#
def save_pipeline!
@pipeline.save!
@pipeline.touch
@pipeline
end
end