create_commit_service.rb 640 Bytes
Newer Older
Douwe Maan's avatar
Douwe Maan committed
1
2
module Ci
  class CreateCommitService
3
    def execute(project, params, user)
Douwe Maan's avatar
Douwe Maan committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
      before_sha = params[:before]
      sha = params[:checkout_sha] || params[:after]
      origin_ref = params[:ref]
      
      unless origin_ref && sha.present?
        return false
      end

      ref = origin_ref.gsub(/\Arefs\/(tags|heads)\//, '')

      # Skip branch removal
      if sha == Ci::Git::BLANK_SHA
        return false
      end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
19
20
      tag = origin_ref.start_with?('refs/tags/')
      commit = project.gl_project.ensure_ci_commit(sha)
Douwe Maan's avatar
Douwe Maan committed
21
      commit.update_committed!
22
      commit.create_builds(ref, tag, user)
Douwe Maan's avatar
Douwe Maan committed
23
24
25
26
27

      commit
    end
  end
end