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

41 lines
968 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
2016-06-02 11:05:42 +05:30
commit = Ci::Commit.new(project: project, sha: sha, ref: ref, before_sha: before_sha, tag: tag)
2015-12-23 02:04:40 +05:30
2016-06-02 11:05:42 +05:30
# Skip creating ci_commit when no gitlab-ci.yml is found
unless commit.ci_yaml_file
return false
2015-12-23 02:04:40 +05:30
end
2016-06-02 11:05:42 +05:30
# Create a new ci_commit
commit.save!
2015-12-23 02:04:40 +05:30
# Skip creating builds for commits that have [ci skip]
unless commit.skip_ci?
# Create builds for commit
2016-06-02 11:05:42 +05:30
commit.create_builds(user)
2015-12-23 02:04:40 +05:30
end
2016-06-02 11:05:42 +05:30
commit.touch
2015-12-23 02:04:40 +05:30
commit
end
end