2015-12-10 11:44:06 -05:00
|
|
|
class CreateCommitBuildsService
|
|
|
|
def execute(project, user, params)
|
2016-06-02 15:02:52 -04:00
|
|
|
return unless project.builds_enabled?
|
2015-12-10 11:44:06 -05:00
|
|
|
|
2016-03-31 13:51:28 -04:00
|
|
|
before_sha = params[:checkout_sha] || params[:before]
|
2015-12-10 11:44:06 -05:00
|
|
|
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)
|
2015-12-10 11:44:06 -05:00
|
|
|
|
|
|
|
# Skip branch removal
|
2015-12-11 11:57:04 -05:00
|
|
|
if sha == Gitlab::Git::BLANK_SHA
|
2015-12-10 11:44:06 -05:00
|
|
|
return false
|
2015-12-17 10:21:36 -05:00
|
|
|
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)
|
2015-12-17 10:21:36 -05:00
|
|
|
|
2016-06-14 08:09:07 -04:00
|
|
|
##
|
|
|
|
# Skip creating pipeline if no gitlab-ci.yml is found
|
|
|
|
#
|
|
|
|
unless @pipeline.ci_yaml_file
|
|
|
|
return false
|
2016-06-02 15:02:52 -04:00
|
|
|
end
|
2016-05-19 14:48:57 -04:00
|
|
|
|
2016-06-14 08:09:07 -04:00
|
|
|
##
|
2015-12-17 10:21:36 -05:00
|
|
|
# Skip creating builds for commits that have [ci skip]
|
2016-06-14 08:09:07 -04:00
|
|
|
# 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.
|
|
|
|
#
|
2016-06-15 08:03:43 -04:00
|
|
|
unless @pipeline.create_builds(user)
|
2016-06-14 08:09:07 -04:00
|
|
|
@pipeline.errors.add(:base, 'No builds created')
|
|
|
|
return false
|
2015-12-10 11:44:06 -05:00
|
|
|
end
|
|
|
|
|
2016-06-14 08:09:07 -04:00
|
|
|
save_pipeline!
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-06-14 07:44:03 -04:00
|
|
|
|
2016-06-14 08:09:07 -04:00
|
|
|
##
|
|
|
|
# Create a new pipeline and touch object to calculate status
|
|
|
|
#
|
|
|
|
def save_pipeline!
|
|
|
|
@pipeline.save!
|
|
|
|
@pipeline.touch
|
|
|
|
@pipeline
|
2015-12-10 11:44:06 -05:00
|
|
|
end
|
|
|
|
end
|