2015-12-10 11:44:06 -05:00
|
|
|
class CreateCommitBuildsService
|
|
|
|
def execute(project, user, params)
|
|
|
|
return false unless project.builds_enabled?
|
|
|
|
|
|
|
|
sha = params[:checkout_sha] || params[:after]
|
|
|
|
origin_ref = params[:ref]
|
|
|
|
|
|
|
|
unless origin_ref && sha.present?
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2015-12-11 11:57:04 -05:00
|
|
|
ref = Gitlab::Git.ref_name(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
|
|
|
|
end
|
|
|
|
|
2015-12-17 10:21:36 -05:00
|
|
|
commit = project.ci_commit(sha)
|
|
|
|
unless commit
|
|
|
|
commit = project.ci_commits.new(sha: sha)
|
|
|
|
|
|
|
|
# Skip creating ci_commit when no gitlab-ci.yml is found
|
|
|
|
unless commit.ci_yaml_file
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
# Create a new ci_commit
|
|
|
|
commit.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
# Skip creating builds for commits that have [ci skip]
|
2015-12-10 11:44:06 -05:00
|
|
|
unless commit.skip_ci?
|
2015-12-17 10:21:36 -05:00
|
|
|
# Create builds for commit
|
|
|
|
tag = Gitlab::Git.tag_ref?(origin_ref)
|
2015-12-10 11:44:06 -05:00
|
|
|
commit.update_committed!
|
|
|
|
commit.create_builds(ref, tag, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
commit
|
|
|
|
end
|
|
|
|
end
|