summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2016-04-21 08:10:37 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2016-04-21 08:10:37 +0000
commitd2406668003f610139b60c036bc6fd9be982a580 (patch)
tree17cc8f3adf5ee7d5f086b2a3ce668a38ba9c7c4b /app/services
parent2ade37e2534108c72d28605cb131dacf771d27d3 (diff)
parent27e0c7723ca1eb85222210a20fd3fee1d77733f7 (diff)
downloadgitlab-ce-d2406668003f610139b60c036bc6fd9be982a580.tar.gz
Merge branch 'ci-commit-as-pipeline' into 'master'
Ci::Commit becomes a Pipeline object 1. Ci::Commit receives context: ref, :tag. 1. One Ci::Commit describes a one Pipeline 1. Pipeline is created from `.gitlab-ci.yml` 1. Pipeline is a ordered group of builds 1. We test MR against Pipeline 1. Pipelines have a separate view (https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3703) 1. Pipeline can be triggered from UI (https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3703) 1. Later we change `Trigger -> TriggerRequest -> Build` to `Trigger -> Pipeline` (future) 1. We add a Pipeline Hook that will be triggered on Pipeline status change (future) 1. We extend notifications to use `Pipeline Hook` to send summary on pipeline changes (future) After merging that I'll prepare a separate MR that will unify naming, database columns, table names: ``` Ci::Commit -> Pipeline Ci::Build -> Build CommitStatus -> Job GenericCommitStatus -> ExternalJob ci_commits -> pipelines ci_builds -> jobs ``` This MR implements first 5 points. This is made to solve this issue https://gitlab.com/gitlab-org/gitlab-ce/issues/14149. See merge request !3653
Diffstat (limited to 'app/services')
-rw-r--r--app/services/ci/create_builds_service.rb27
-rw-r--r--app/services/ci/create_trigger_request_service.rb4
-rw-r--r--app/services/ci/image_for_build_service.rb11
-rw-r--r--app/services/create_commit_builds_service.rb10
4 files changed, 32 insertions, 20 deletions
diff --git a/app/services/ci/create_builds_service.rb b/app/services/ci/create_builds_service.rb
index 2cd51a7610f..18274ce24e2 100644
--- a/app/services/ci/create_builds_service.rb
+++ b/app/services/ci/create_builds_service.rb
@@ -1,7 +1,11 @@
module Ci
class CreateBuildsService
- def execute(commit, stage, ref, tag, user, trigger_request, status)
- builds_attrs = commit.config_processor.builds_for_stage_and_ref(stage, ref, tag, trigger_request)
+ def initialize(commit)
+ @commit = commit
+ end
+
+ def execute(stage, user, status, trigger_request = nil)
+ builds_attrs = config_processor.builds_for_stage_and_ref(stage, @commit.ref, @commit.tag, trigger_request)
# check when to create next build
builds_attrs = builds_attrs.select do |build_attrs|
@@ -17,7 +21,8 @@ module Ci
builds_attrs.map do |build_attrs|
# don't create the same build twice
- unless commit.builds.find_by(ref: ref, tag: tag, trigger_request: trigger_request, name: build_attrs[:name])
+ unless @commit.builds.find_by(ref: @commit.ref, tag: @commit.tag,
+ trigger_request: trigger_request, name: build_attrs[:name])
build_attrs.slice!(:name,
:commands,
:tag_list,
@@ -26,17 +31,21 @@ module Ci
:stage,
:stage_idx)
- build_attrs.merge!(ref: ref,
- tag: tag,
+ build_attrs.merge!(ref: @commit.ref,
+ tag: @commit.tag,
trigger_request: trigger_request,
user: user,
- project: commit.project)
+ project: @commit.project)
- build = commit.builds.create!(build_attrs)
- build.execute_hooks
- build
+ @commit.builds.create!(build_attrs)
end
end
end
+
+ private
+
+ def config_processor
+ @config_processor ||= @commit.config_processor
+ end
end
end
diff --git a/app/services/ci/create_trigger_request_service.rb b/app/services/ci/create_trigger_request_service.rb
index b3dfc707221..993acf11db9 100644
--- a/app/services/ci/create_trigger_request_service.rb
+++ b/app/services/ci/create_trigger_request_service.rb
@@ -7,14 +7,14 @@ module Ci
# check if ref is tag
tag = project.repository.find_tag(ref).present?
- ci_commit = project.ensure_ci_commit(commit.sha)
+ ci_commit = project.ci_commits.create(sha: commit.sha, ref: ref, tag: tag)
trigger_request = trigger.trigger_requests.create!(
variables: variables,
commit: ci_commit,
)
- if ci_commit.create_builds(ref, tag, nil, trigger_request)
+ if ci_commit.create_builds(nil, trigger_request)
trigger_request
end
end
diff --git a/app/services/ci/image_for_build_service.rb b/app/services/ci/image_for_build_service.rb
index 50c95ced8a7..3018f27ec05 100644
--- a/app/services/ci/image_for_build_service.rb
+++ b/app/services/ci/image_for_build_service.rb
@@ -3,8 +3,9 @@ module Ci
def execute(project, opts)
sha = opts[:sha] || ref_sha(project, opts[:ref])
- commit = project.ci_commits.find_by(sha: sha)
- image_name = image_for_commit(commit)
+ ci_commits = project.ci_commits.where(sha: sha)
+ ci_commits = ci_commits.where(ref: opts[:ref]) if opts[:ref]
+ image_name = image_for_status(ci_commits.status)
image_path = Rails.root.join('public/ci', image_name)
OpenStruct.new(path: image_path, name: image_name)
@@ -16,9 +17,9 @@ module Ci
project.commit(ref).try(:sha) if ref
end
- def image_for_commit(commit)
- return 'build-unknown.svg' unless commit
- 'build-' + commit.status + ".svg"
+ def image_for_status(status)
+ status ||= 'unknown'
+ 'build-' + status + ".svg"
end
end
end
diff --git a/app/services/create_commit_builds_service.rb b/app/services/create_commit_builds_service.rb
index 69d5c42a877..0d2aa1ff03d 100644
--- a/app/services/create_commit_builds_service.rb
+++ b/app/services/create_commit_builds_service.rb
@@ -2,6 +2,7 @@ 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]
@@ -10,15 +11,16 @@ class CreateCommitBuildsService
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 = project.ci_commit(sha)
+ commit = project.ci_commit(sha, ref)
unless commit
- commit = project.ci_commits.new(sha: sha)
+ 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
@@ -32,10 +34,10 @@ class CreateCommitBuildsService
# Skip creating builds for commits that have [ci skip]
unless commit.skip_ci?
# Create builds for commit
- tag = Gitlab::Git.tag_ref?(origin_ref)
- commit.create_builds(ref, tag, user)
+ commit.create_builds(user)
end
+ commit.touch
commit
end
end