Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_commit_builds_service.rb « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 70a7d4bef4d2d52cb8bb16ddb1ec8b08efa62e87 (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
29
30
31
32
33
34
35
36
37
38
39
40
class CreateCommitBuildsService
  def execute(project, user, params)
    return false unless project.builds_enabled?

    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

    ref = Gitlab::Git.ref_name(origin_ref)
    tag = Gitlab::Git.tag_ref?(origin_ref)

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

    commit = Ci::Pipeline.new(project: project, 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!

    # Skip creating builds for commits that have [ci skip]
    unless commit.skip_ci?
      # Create builds for commit
      commit.create_builds(user)
    end

    commit.touch
    commit
  end
end