summaryrefslogtreecommitdiff
path: root/app/services/create_commit_builds_service.rb
blob: 759c334ebe96dff6b630effa700fb12d0c57376f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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

    ref = Gitlab::Git.ref_name(origin_ref)

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

    tag = Gitlab::Git.tag_ref?(origin_ref)
    commit = project.ensure_ci_commit(sha)
    unless commit.skip_ci?
      commit.update_committed!
      commit.create_builds(ref, tag, user)
    end

    commit
  end
end