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

41 lines
982 B
Ruby
Raw Normal View History

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
pipeline = Ci::Pipeline.new(project: project, sha: sha, ref: ref, before_sha: before_sha, tag: tag)
2015-12-23 02:04:40 +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
# 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]
unless pipeline.skip_ci?
2015-12-23 02:04:40 +05:30
# Create builds for commit
pipeline.create_builds(user)
2015-12-23 02:04:40 +05:30
end
pipeline.touch
pipeline
2015-12-23 02:04:40 +05:30
end
end