2015-12-10 11:44:06 -05:00
|
|
|
class CreateCommitBuildsService
|
|
|
|
def execute(project, user, params)
|
|
|
|
return false unless project.builds_enabled?
|
|
|
|
|
2016-03-31 13:51:28 -04:00
|
|
|
before_sha = params[:checkout_sha] || params[:before]
|
2015-12-10 11:44:06 -05:00
|
|
|
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)
|
2016-03-31 13:51:28 -04:00
|
|
|
tag = Gitlab::Git.tag_ref?(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
|
|
|
|
|
2016-05-19 14:48:57 -04:00
|
|
|
commit = Ci::Commit.new(project: project, sha: sha, ref: ref, before_sha: before_sha, tag: tag)
|
2015-12-17 10:21:36 -05:00
|
|
|
|
2016-05-19 14:48:57 -04:00
|
|
|
# Skip creating ci_commit when no gitlab-ci.yml is found
|
|
|
|
unless commit.ci_yaml_file
|
|
|
|
return false
|
2015-12-17 10:21:36 -05:00
|
|
|
end
|
|
|
|
|
2016-05-19 14:48:57 -04:00
|
|
|
# Create a new ci_commit
|
|
|
|
commit.save!
|
|
|
|
|
2015-12-17 10:21:36 -05:00
|
|
|
# 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
|
2016-03-31 13:51:28 -04:00
|
|
|
commit.create_builds(user)
|
2015-12-10 11:44:06 -05:00
|
|
|
end
|
|
|
|
|
2016-04-11 10:55:40 -04:00
|
|
|
commit.touch
|
2015-12-10 11:44:06 -05:00
|
|
|
commit
|
|
|
|
end
|
|
|
|
end
|