create_commit_service.rb 993 Bytes
Newer Older
Douwe Maan's avatar
Douwe Maan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module Ci
  class CreateCommitService
    def execute(project, params)
      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
21
22
23
24
25
26
27
28
29
30
      tag = origin_ref.start_with?('refs/tags/')
      push_data = {
        before: before_sha,
        after: sha,
        ref: ref,
        user_name: params[:user_name],
        user_email: params[:user_email],
        repository: params[:repository],
        commits: params[:commits],
        total_commits_count: params[:total_commits_count],
        ci_yaml_file: params[:ci_yaml_file]
      }
Douwe Maan's avatar
Douwe Maan committed
31

Kamil Trzcinski's avatar
Kamil Trzcinski committed
32
      commit = project.gl_project.ensure_ci_commit(sha)
Douwe Maan's avatar
Douwe Maan committed
33
      commit.update_committed!
Kamil Trzcinski's avatar
Kamil Trzcinski committed
34
      commit.create_builds(ref, tag, push_data)
Douwe Maan's avatar
Douwe Maan committed
35
36
37
38
39

      commit
    end
  end
end