2015-12-23 02:04:40 +05:30
|
|
|
class CreateCommitBuildsService
|
|
|
|
def execute(project, user, params)
|
|
|
|
return false unless project.builds_enabled?
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
unless origin_ref && sha.present?
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
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-06-16 23:09:34 +05:30
|
|
|
pipeline = Ci::Pipeline.new(project: project, sha: sha, ref: ref, before_sha: before_sha, tag: tag)
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
# Skip creating pipeline when 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-16 23:09:34 +05:30
|
|
|
# Create a new pipeline
|
|
|
|
pipeline.save!
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
# Skip creating builds for commits that have [ci skip]
|
2016-06-16 23:09:34 +05:30
|
|
|
unless pipeline.skip_ci?
|
2015-12-23 02:04:40 +05:30
|
|
|
# Create builds for commit
|
2016-06-16 23:09:34 +05:30
|
|
|
pipeline.create_builds(user)
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
pipeline.touch
|
|
|
|
pipeline
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
end
|