debian-mirror-gitlab/app/services/create_commit_builds_service.rb

70 lines
1.4 KiB
Ruby
Raw Normal View History

2015-12-23 02:04:40 +05:30
class CreateCommitBuildsService
def execute(project, user, params)
2016-06-22 15:30:34 +05:30
return unless project.builds_enabled?
2015-12-23 02:04:40 +05:30
2016-06-02 11:05:42 +05:30
before_sha = params[:checkout_sha] || params[:before]
2015-12-23 02:04:40 +05:30
sha = params[:checkout_sha] || params[:after]
origin_ref = params[:ref]
ref = Gitlab::Git.ref_name(origin_ref)
2016-06-02 11:05:42 +05:30
tag = Gitlab::Git.tag_ref?(origin_ref)
2015-12-23 02:04:40 +05:30
# Skip branch removal
if sha == Gitlab::Git::BLANK_SHA
return false
end
2016-08-24 12:49:21 +05:30
@pipeline = Ci::Pipeline.new(
project: project,
sha: sha,
ref: ref,
before_sha: before_sha,
tag: tag,
user: user)
2015-12-23 02:04:40 +05:30
2016-06-22 15:30:34 +05:30
##
# Skip creating pipeline if no gitlab-ci.yml is found
#
unless @pipeline.ci_yaml_file
2016-06-02 11:05:42 +05:30
return false
2015-12-23 02:04:40 +05:30
end
2016-06-22 15:30:34 +05:30
##
2015-12-23 02:04:40 +05:30
# Skip creating builds for commits that have [ci skip]
2016-06-22 15:30:34 +05:30
# 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!
2015-12-23 02:04:40 +05:30
end
2016-06-22 15:30:34 +05:30
##
# 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
2015-12-23 02:04:40 +05:30
end
end