gitlab-org--gitlab-foss/app/services/create_commit_builds_service.rb

44 lines
1 KiB
Ruby
Raw Normal View History

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]
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)
# Skip branch removal
2015-12-11 11:57:04 -05:00
if sha == Gitlab::Git::BLANK_SHA
return false
end
2016-03-31 13:51:28 -04:00
commit = project.ci_commit(sha, ref)
unless commit
2016-03-31 13:51:28 -04:00
commit = project.ci_commits.new(sha: sha, ref: ref, before_sha: before_sha, tag: tag)
# 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]
unless commit.skip_ci?
# Create builds for commit
2016-03-31 13:51:28 -04:00
commit.create_builds(user)
end
2016-04-11 10:55:40 -04:00
commit.touch
commit
end
end