Commit 3368afd7 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rename-ci-commit-phase-2' into 'master'

Rename Ci::Commit in specs

This is second iteration of renaming Ci::Commit occurences, this time I try to rename all `let's` and `factories` to match what type of object is created:

1. Rename factories: `ci_[...]_commit_[...]` to `ci_[...]_pipeline_[...]`,
2. Rename all `let's(:[ci_]commit)` to `let(:pipeline)`,
3. Rename all occurrences of `[ci_]commit` to `pipeline` if Pipeline object is created

cc @grzesiek @DouweM 

See merge request !4463
parents 8c5712a4 8988c874
No related merge requests found
...@@ -26,9 +26,9 @@ class Projects::BuildsController < Projects::ApplicationController ...@@ -26,9 +26,9 @@ class Projects::BuildsController < Projects::ApplicationController
end end
def show def show
@builds = @project.ci_commits.find_by_sha(@build.sha).builds.order('id DESC') @builds = @project.pipelines.find_by_sha(@build.sha).builds.order('id DESC')
@builds = @builds.where("id not in (?)", @build.id) @builds = @builds.where("id not in (?)", @build.id)
@commit = @build.commit @pipeline = @build.pipeline
respond_to do |format| respond_to do |format|
format.html format.html
......
...@@ -100,11 +100,11 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -100,11 +100,11 @@ class Projects::CommitController < Projects::ApplicationController
end end
def ci_commits def ci_commits
@ci_commits ||= project.ci_commits.where(sha: commit.sha) @ci_commits ||= project.pipelines.where(sha: commit.sha)
end end
def ci_builds def ci_builds
@ci_builds ||= Ci::Build.where(commit: ci_commits) @ci_builds ||= Ci::Build.where(pipeline: ci_commits)
end end
def define_show_vars def define_show_vars
...@@ -117,8 +117,8 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -117,8 +117,8 @@ class Projects::CommitController < Projects::ApplicationController
@diff_refs = [commit.parent || commit, commit] @diff_refs = [commit.parent || commit, commit]
@notes_count = commit.notes.count @notes_count = commit.notes.count
@statuses = CommitStatus.where(commit: ci_commits) @statuses = CommitStatus.where(pipeline: ci_commits)
@builds = Ci::Build.where(commit: ci_commits) @builds = Ci::Build.where(pipeline: ci_commits)
end end
def assign_change_commit_vars(mr_source_branch) def assign_change_commit_vars(mr_source_branch)
......
...@@ -120,8 +120,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -120,8 +120,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@diffs = @merge_request.compare.diffs(diff_options) if @merge_request.compare @diffs = @merge_request.compare.diffs(diff_options) if @merge_request.compare
@diff_notes_disabled = true @diff_notes_disabled = true
@ci_commit = @merge_request.ci_commit @pipeline = @merge_request.pipeline
@statuses = @ci_commit.statuses if @ci_commit @statuses = @pipeline.statuses if @pipeline
@note_counts = Note.where(commit_id: @commits.map(&:id)). @note_counts = Note.where(commit_id: @commits.map(&:id)).
group(:commit_id).count group(:commit_id).count
...@@ -200,7 +200,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -200,7 +200,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_request.update(merge_error: nil) @merge_request.update(merge_error: nil)
if params[:merge_when_build_succeeds].present? && @merge_request.ci_commit && @merge_request.ci_commit.active? if params[:merge_when_build_succeeds].present? && @merge_request.pipeline && @merge_request.pipeline.active?
MergeRequests::MergeWhenBuildSucceedsService.new(@project, current_user, merge_params) MergeRequests::MergeWhenBuildSucceedsService.new(@project, current_user, merge_params)
.execute(@merge_request) .execute(@merge_request)
@status = :merge_when_build_succeeds @status = :merge_when_build_succeeds
...@@ -231,10 +231,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -231,10 +231,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def ci_status def ci_status
ci_commit = @merge_request.ci_commit pipeline = @merge_request.pipeline
if ci_commit if pipeline
status = ci_commit.status status = pipeline.status
coverage = ci_commit.try(:coverage) coverage = pipeline.try(:coverage)
status ||= "preparing" status ||= "preparing"
else else
...@@ -317,7 +317,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -317,7 +317,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_request_diff = @merge_request.merge_request_diff @merge_request_diff = @merge_request.merge_request_diff
@ci_commit = @merge_request.ci_commit @ci_commit = @merge_request.pipeline
@statuses = @ci_commit.statuses if @ci_commit @statuses = @ci_commit.statuses if @ci_commit
if @merge_request.locked_long_ago? if @merge_request.locked_long_ago?
...@@ -327,7 +327,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -327,7 +327,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def define_widget_vars def define_widget_vars
@ci_commit = @merge_request.ci_commit @ci_commit = @merge_request.pipeline
@ci_commits = [@ci_commit].compact @ci_commits = [@ci_commit].compact
closes_issues closes_issues
end end
......
...@@ -7,7 +7,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -7,7 +7,7 @@ class Projects::PipelinesController < Projects::ApplicationController
def index def index
@scope = params[:scope] @scope = params[:scope]
all_pipelines = project.ci_commits all_pipelines = project.pipelines
@pipelines_count = all_pipelines.count @pipelines_count = all_pipelines.count
@running_or_pending_count = all_pipelines.running_or_pending.count @running_or_pending_count = all_pipelines.running_or_pending.count
@pipelines = PipelinesFinder.new(project).execute(all_pipelines, @scope) @pipelines = PipelinesFinder.new(project).execute(all_pipelines, @scope)
...@@ -15,7 +15,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -15,7 +15,7 @@ class Projects::PipelinesController < Projects::ApplicationController
end end
def new def new
@pipeline = project.ci_commits.new(ref: @project.default_branch) @pipeline = project.pipelines.new(ref: @project.default_branch)
end end
def create def create
...@@ -50,7 +50,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -50,7 +50,7 @@ class Projects::PipelinesController < Projects::ApplicationController
end end
def pipeline def pipeline
@pipeline ||= project.ci_commits.find_by!(id: params[:id]) @pipeline ||= project.pipelines.find_by!(id: params[:id])
end end
def commit def commit
......
...@@ -45,8 +45,8 @@ module Ci ...@@ -45,8 +45,8 @@ module Ci
new_build.options = build.options new_build.options = build.options
new_build.commands = build.commands new_build.commands = build.commands
new_build.tag_list = build.tag_list new_build.tag_list = build.tag_list
new_build.gl_project_id = build.gl_project_id new_build.project = build.project
new_build.commit_id = build.commit_id new_build.pipeline = build.pipeline
new_build.name = build.name new_build.name = build.name
new_build.allow_failure = build.allow_failure new_build.allow_failure = build.allow_failure
new_build.stage = build.stage new_build.stage = build.stage
...@@ -66,7 +66,7 @@ module Ci ...@@ -66,7 +66,7 @@ module Ci
# We use around_transition to create builds for next stage as soon as possible, before the `after_*` is executed # We use around_transition to create builds for next stage as soon as possible, before the `after_*` is executed
around_transition any => [:success, :failed, :canceled] do |build, block| around_transition any => [:success, :failed, :canceled] do |build, block|
block.call block.call
build.commit.create_next_builds(build) if build.commit build.pipeline.create_next_builds(build) if build.pipeline
end end
after_transition any => [:success, :failed, :canceled] do |build| after_transition any => [:success, :failed, :canceled] do |build|
...@@ -80,7 +80,7 @@ module Ci ...@@ -80,7 +80,7 @@ module Ci
end end
def retried? def retried?
!self.commit.statuses.latest.include?(self) !self.pipeline.statuses.latest.include?(self)
end end
def retry def retry
...@@ -89,7 +89,7 @@ module Ci ...@@ -89,7 +89,7 @@ module Ci
def depends_on_builds def depends_on_builds
# Get builds of the same type # Get builds of the same type
latest_builds = self.commit.builds.latest latest_builds = self.pipeline.builds.latest
# Return builds from previous stages # Return builds from previous stages
latest_builds.where('stage_idx < ?', stage_idx) latest_builds.where('stage_idx < ?', stage_idx)
...@@ -114,16 +114,16 @@ module Ci ...@@ -114,16 +114,16 @@ module Ci
def merge_request def merge_request
merge_requests = MergeRequest.includes(:merge_request_diff) merge_requests = MergeRequest.includes(:merge_request_diff)
.where(source_branch: ref, source_project_id: commit.gl_project_id) .where(source_branch: ref, source_project_id: pipeline.gl_project_id)
.reorder(iid: :asc) .reorder(iid: :asc)
merge_requests.find do |merge_request| merge_requests.find do |merge_request|
merge_request.commits.any? { |ci| ci.id == commit.sha } merge_request.commits.any? { |ci| ci.id == pipeline.sha }
end end
end end
def project_id def project_id
commit.project.id pipeline.project_id
end end
def project_name def project_name
...@@ -360,8 +360,8 @@ module Ci ...@@ -360,8 +360,8 @@ module Ci
end end
def global_yaml_variables def global_yaml_variables
if commit.config_processor if pipeline.config_processor
commit.config_processor.global_variables.map do |key, value| pipeline.config_processor.global_variables.map do |key, value|
{ key: key, value: value, public: true } { key: key, value: value, public: true }
end end
else else
...@@ -370,8 +370,8 @@ module Ci ...@@ -370,8 +370,8 @@ module Ci
end end
def job_yaml_variables def job_yaml_variables
if commit.config_processor if pipeline.config_processor
commit.config_processor.job_variables(name).map do |key, value| pipeline.config_processor.job_variables(name).map do |key, value|
{ key: key, value: value, public: true } { key: key, value: value, public: true }
end end
else else
......
module Ci module Ci
class Commit < ActiveRecord::Base class Pipeline < ActiveRecord::Base
extend Ci::Model extend Ci::Model
include Statuseable include Statuseable
self.table_name = 'ci_commits'
belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id
has_many :statuses, class_name: 'CommitStatus' has_many :statuses, class_name: 'CommitStatus', foreign_key: :commit_id
has_many :builds, class_name: 'Ci::Build' has_many :builds, class_name: 'Ci::Build', foreign_key: :commit_id
has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest' has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest', foreign_key: :commit_id
validates_presence_of :sha validates_presence_of :sha
validates_presence_of :status validates_presence_of :status
...@@ -21,7 +23,7 @@ module Ci ...@@ -21,7 +23,7 @@ module Ci
def self.stages def self.stages
# We use pluck here due to problems with MySQL which doesn't allow LIMIT/OFFSET in queries # We use pluck here due to problems with MySQL which doesn't allow LIMIT/OFFSET in queries
CommitStatus.where(commit: pluck(:id)).stages CommitStatus.where(pipeline: pluck(:id)).stages
end end
def project_id def project_id
...@@ -47,7 +49,7 @@ module Ci ...@@ -47,7 +49,7 @@ module Ci
end end
def short_sha def short_sha
Ci::Commit.truncate_sha(sha) Ci::Pipeline.truncate_sha(sha)
end end
def commit_data def commit_data
......
...@@ -3,7 +3,7 @@ module Ci ...@@ -3,7 +3,7 @@ module Ci
extend Ci::Model extend Ci::Model
belongs_to :trigger, class_name: 'Ci::Trigger' belongs_to :trigger, class_name: 'Ci::Trigger'
belongs_to :commit, class_name: 'Ci::Commit' belongs_to :commit, class_name: 'Ci::Pipeline', foreign_key: :commit_id
has_many :builds, class_name: 'Ci::Build' has_many :builds, class_name: 'Ci::Build'
serialize :variables serialize :variables
......
...@@ -214,13 +214,13 @@ class Commit ...@@ -214,13 +214,13 @@ class Commit
@raw.short_id(7) @raw.short_id(7)
end end
def ci_commits def pipelines
@ci_commits ||= project.ci_commits.where(sha: sha) @pipeline ||= project.pipelines.where(sha: sha)
end end
def status def status
return @status if defined?(@status) return @status if defined?(@status)
@status ||= ci_commits.status @status ||= pipelines.status
end end
def revert_branch_name def revert_branch_name
......
...@@ -4,10 +4,10 @@ class CommitStatus < ActiveRecord::Base ...@@ -4,10 +4,10 @@ class CommitStatus < ActiveRecord::Base
self.table_name = 'ci_builds' self.table_name = 'ci_builds'
belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id
belongs_to :commit, class_name: 'Ci::Commit', touch: true belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :commit_id, touch: true
belongs_to :user belongs_to :user
validates :commit, presence: true validates :pipeline, presence: true
validates_presence_of :name validates_presence_of :name
...@@ -44,18 +44,18 @@ class CommitStatus < ActiveRecord::Base ...@@ -44,18 +44,18 @@ class CommitStatus < ActiveRecord::Base
end end
after_transition [:pending, :running] => :success do |commit_status| after_transition [:pending, :running] => :success do |commit_status|
MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.commit.project, nil).trigger(commit_status) MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.pipeline.project, nil).trigger(commit_status)
end end
after_transition any => :failed do |commit_status| after_transition any => :failed do |commit_status|
MergeRequests::AddTodoWhenBuildFailsService.new(commit_status.commit.project, nil).execute(commit_status) MergeRequests::AddTodoWhenBuildFailsService.new(commit_status.pipeline.project, nil).execute(commit_status)
end end
end end
delegate :sha, :short_sha, to: :commit delegate :sha, :short_sha, to: :pipeline
def before_sha def before_sha
commit.before_sha || Gitlab::Git::BLANK_SHA pipeline.before_sha || Gitlab::Git::BLANK_SHA
end end
def self.stages def self.stages
......
...@@ -579,8 +579,8 @@ class MergeRequest < ActiveRecord::Base ...@@ -579,8 +579,8 @@ class MergeRequest < ActiveRecord::Base
diverged_commits_count > 0 diverged_commits_count > 0
end end
def ci_commit def pipeline
@ci_commit ||= source_project.ci_commit(last_commit.id, source_branch) if last_commit && source_project @pipeline ||= source_project.pipeline(last_commit.id, source_branch) if last_commit && source_project
end end
def diff_refs def diff_refs
......
...@@ -119,7 +119,7 @@ class Project < ActiveRecord::Base ...@@ -119,7 +119,7 @@ class Project < ActiveRecord::Base
has_one :import_data, dependent: :destroy, class_name: "ProjectImportData" has_one :import_data, dependent: :destroy, class_name: "ProjectImportData"
has_many :commit_statuses, dependent: :destroy, class_name: 'CommitStatus', foreign_key: :gl_project_id has_many :commit_statuses, dependent: :destroy, class_name: 'CommitStatus', foreign_key: :gl_project_id
has_many :ci_commits, dependent: :destroy, class_name: 'Ci::Commit', foreign_key: :gl_project_id has_many :pipelines, dependent: :destroy, class_name: 'Ci::Pipeline', foreign_key: :gl_project_id
has_many :builds, class_name: 'Ci::Build', foreign_key: :gl_project_id # the builds are created from the commit_statuses has_many :builds, class_name: 'Ci::Build', foreign_key: :gl_project_id # the builds are created from the commit_statuses
has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject', foreign_key: :gl_project_id has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject', foreign_key: :gl_project_id
has_many :runners, through: :runner_projects, source: :runner, class_name: 'Ci::Runner' has_many :runners, through: :runner_projects, source: :runner, class_name: 'Ci::Runner'
...@@ -930,12 +930,12 @@ class Project < ActiveRecord::Base ...@@ -930,12 +930,12 @@ class Project < ActiveRecord::Base
!namespace.share_with_group_lock !namespace.share_with_group_lock
end end
def ci_commit(sha, ref) def pipeline(sha, ref)
ci_commits.order(id: :desc).find_by(sha: sha, ref: ref) pipelines.order(id: :desc).find_by(sha: sha, ref: ref)
end end
def ensure_ci_commit(sha, ref) def ensure_pipeline(sha, ref)
ci_commit(sha, ref) || ci_commits.create(sha: sha, ref: ref) pipeline(sha, ref) || pipelines.create(sha: sha, ref: ref)
end end
def enable_ci def enable_ci
......
module Ci module Ci
class CreateBuildsService class CreateBuildsService
def initialize(commit) def initialize(pipeline)
@commit = commit @pipeline = pipeline
end end
def execute(stage, user, status, trigger_request = nil) def execute(stage, user, status, trigger_request = nil)
builds_attrs = config_processor.builds_for_stage_and_ref(stage, @commit.ref, @commit.tag, trigger_request) builds_attrs = config_processor.builds_for_stage_and_ref(stage, @pipeline.ref, @pipeline.tag, trigger_request)
# check when to create next build # check when to create next build
builds_attrs = builds_attrs.select do |build_attrs| builds_attrs = builds_attrs.select do |build_attrs|
...@@ -21,8 +21,8 @@ module Ci ...@@ -21,8 +21,8 @@ module Ci
builds_attrs.map do |build_attrs| builds_attrs.map do |build_attrs|
# don't create the same build twice # don't create the same build twice
unless @commit.builds.find_by(ref: @commit.ref, tag: @commit.tag, unless @pipeline.builds.find_by(ref: @pipeline.ref, tag: @pipeline.tag,
trigger_request: trigger_request, name: build_attrs[:name]) trigger_request: trigger_request, name: build_attrs[:name])
build_attrs.slice!(:name, build_attrs.slice!(:name,
:commands, :commands,
:tag_list, :tag_list,
...@@ -31,13 +31,13 @@ module Ci ...@@ -31,13 +31,13 @@ module Ci
:stage, :stage,
:stage_idx) :stage_idx)
build_attrs.merge!(ref: @commit.ref, build_attrs.merge!(ref: @pipeline.ref,
tag: @commit.tag, tag: @pipeline.tag,
trigger_request: trigger_request, trigger_request: trigger_request,
user: user, user: user,
project: @commit.project) project: @pipeline.project)
@commit.builds.create!(build_attrs) @pipeline.builds.create!(build_attrs)
end end
end end
end end
...@@ -45,7 +45,7 @@ module Ci ...@@ -45,7 +45,7 @@ module Ci
private private
def config_processor def config_processor
@config_processor ||= @commit.config_processor @config_processor ||= @pipeline.config_processor
end end
end end
end end
module Ci module Ci
class CreatePipelineService < BaseService class CreatePipelineService < BaseService
def execute def execute
pipeline = project.ci_commits.new(params) pipeline = project.pipelines.new(params)
unless ref_names.include?(params[:ref]) unless ref_names.include?(params[:ref])
pipeline.errors.add(:base, 'Reference not found') pipeline.errors.add(:base, 'Reference not found')
...@@ -19,7 +19,7 @@ module Ci ...@@ -19,7 +19,7 @@ module Ci
end end
begin begin
Ci::Commit.transaction do Ci::Pipeline.transaction do
pipeline.sha = commit.id pipeline.sha = commit.id
unless pipeline.config_processor unless pipeline.config_processor
......
...@@ -7,7 +7,7 @@ module Ci ...@@ -7,7 +7,7 @@ module Ci
# check if ref is tag # check if ref is tag
tag = project.repository.find_tag(ref).present? tag = project.repository.find_tag(ref).present?
ci_commit = project.ci_commits.create(sha: commit.sha, ref: ref, tag: tag) ci_commit = project.pipelines.create(sha: commit.sha, ref: ref, tag: tag)
trigger_request = trigger.trigger_requests.create!( trigger_request = trigger.trigger_requests.create!(
variables: variables, variables: variables,
......
...@@ -3,7 +3,7 @@ module Ci ...@@ -3,7 +3,7 @@ module Ci
def execute(project, opts) def execute(project, opts)
sha = opts[:sha] || ref_sha(project, opts[:ref]) sha = opts[:sha] || ref_sha(project, opts[:ref])
ci_commits = project.ci_commits.where(sha: sha) ci_commits = project.pipelines.where(sha: sha)
ci_commits = ci_commits.where(ref: opts[:ref]) if opts[:ref] ci_commits = ci_commits.where(ref: opts[:ref]) if opts[:ref]
image_name = image_for_status(ci_commits.status) image_name = image_for_status(ci_commits.status)
......
...@@ -18,23 +18,23 @@ class CreateCommitBuildsService ...@@ -18,23 +18,23 @@ class CreateCommitBuildsService
return false return false
end end
commit = Ci::Commit.new(project: project, sha: sha, ref: ref, before_sha: before_sha, tag: tag) pipeline = 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 # Skip creating ci_commit when no gitlab-ci.yml is found
unless commit.ci_yaml_file unless pipeline.ci_yaml_file
return false return false
end end
# Create a new ci_commit # Create a new ci_commit
commit.save! pipeline.save!
# Skip creating builds for commits that have [ci skip] # Skip creating builds for commits that have [ci skip]
unless commit.skip_ci? unless pipeline.skip_ci?
# Create builds for commit # Create builds for commit
commit.create_builds(user) pipeline.create_builds(user)
end end
commit.touch pipeline.touch
commit pipeline
end end
end end
...@@ -55,12 +55,12 @@ module MergeRequests ...@@ -55,12 +55,12 @@ module MergeRequests
def each_merge_request(commit_status) def each_merge_request(commit_status)
merge_request_from(commit_status).each do |merge_request| merge_request_from(commit_status).each do |merge_request|
ci_commit = merge_request.ci_commit pipeline = merge_request.pipeline
next unless ci_commit next unless pipeline
next unless ci_commit.sha == commit_status.sha next unless pipeline.sha == commit_status.sha
yield merge_request, ci_commit yield merge_request, pipeline
end end
end end
end end
......
...@@ -99,8 +99,8 @@ ...@@ -99,8 +99,8 @@
%td.build-link %td.build-link
- if project - if project
= link_to ci_status_path(build.commit) do = link_to ci_status_path(build.pipeline) do
%strong #{build.commit.short_sha} %strong #{build.pipeline.short_sha}
%td.timestamp %td.timestamp
- if build.finished_at - if build.finished_at
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
%p %p
Commit: #{link_to @build.short_sha, namespace_project_commit_url(@build.project.namespace, @build.project, @build.sha)} Commit: #{link_to @build.short_sha, namespace_project_commit_url(@build.project.namespace, @build.project, @build.sha)}
%p %p
Author: #{@build.commit.git_author_name} Author: #{@build.pipeline.git_author_name}
%p %p
Branch: #{@build.ref} Branch: #{@build.ref}
%p %p
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
%p %p
Job: #{@build.name} Job: #{@build.name}
%p %p
Message: #{@build.commit.git_commit_message} Message: #{@build.pipeline.git_commit_message}
%p %p
Build details: #{link_to "Build #{@build.id}", namespace_project_build_url(@build.project.namespace, @build.project, @build)} Build details: #{link_to "Build #{@build.id}", namespace_project_build_url(@build.project.namespace, @build.project, @build)}
Build failed for <%= @project.name %> Build failed for <%= @project.name %>
Status: <%= @build.status %> Status: <%= @build.status %>
Commit: <%= @build.commit.short_sha %> Commit: <%= @build.pipeline.short_sha %>
Author: <%= @build.commit.git_author_name %> Author: <%= @build.pipeline.git_author_name %>
Branch: <%= @build.ref %> Branch: <%= @build.ref %>
Stage: <%= @build.stage %> Stage: <%= @build.stage %>
Job: <%= @build.name %> Job: <%= @build.name %>
Message: <%= @build.commit.git_commit_message %> Message: <%= @build.pipeline.git_commit_message %>
Url: <%= namespace_project_build_url(@build.project.namespace, @build.project, @build) %> Url: <%= namespace_project_build_url(@build.project.namespace, @build.project, @build) %>
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
%p %p
Commit: #{link_to @build.short_sha, namespace_project_commit_url(@build.project.namespace, @build.project, @build.sha)} Commit: #{link_to @build.short_sha, namespace_project_commit_url(@build.project.namespace, @build.project, @build.sha)}
%p %p
Author: #{@build.commit.git_author_name} Author: #{@build.pipeline.git_author_name}
%p %p
Branch: #{@build.ref} Branch: #{@build.ref}
%p %p
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
%p %p
Job: #{@build.name} Job: #{@build.name}
%p %p
Message: #{@build.commit.git_commit_message} Message: #{@build.pipeline.git_commit_message}
%p %p
Build details: #{link_to "Build #{@build.id}", namespace_project_build_url(@build.project.namespace, @build.project, @build)} Build details: #{link_to "Build #{@build.id}", namespace_project_build_url(@build.project.namespace, @build.project, @build)}
Build successful for <%= @project.name %> Build successful for <%= @project.name %>
Status: <%= @build.status %> Status: <%= @build.status %>
Commit: <%= @build.commit.short_sha %> Commit: <%= @build.pipeline.short_sha %>
Author: <%= @build.commit.git_author_name %> Author: <%= @build.pipeline.git_author_name %>
Branch: <%= @build.ref %> Branch: <%= @build.ref %>
Stage: <%= @build.stage %> Stage: <%= @build.stage %>
Job: <%= @build.name %> Job: <%= @build.name %>
Message: <%= @build.commit.git_commit_message %> Message: <%= @build.pipeline.git_commit_message %>
Url: <%= namespace_project_build_url(@build.project.namespace, @build.project, @build) %> Url: <%= namespace_project_build_url(@build.project.namespace, @build.project, @build) %>
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
.build-page .build-page
.row-content-block.top-block .row-content-block.top-block
Build ##{@build.id} for commit Build ##{@build.id} for commit
%strong.monospace= link_to @build.commit.short_sha, ci_status_path(@build.commit) %strong.monospace= link_to @build.pipeline.short_sha, ci_status_path(@build.pipeline)
from from
= link_to @build.ref, namespace_project_commits_path(@project.namespace, @project, @build.ref) = link_to @build.ref, namespace_project_commits_path(@project.namespace, @project, @build.ref)
- merge_request = @build.merge_request - merge_request = @build.merge_request
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
= link_to "merge request #{merge_request.to_reference}", merge_request_path(merge_request) = link_to "merge request #{merge_request.to_reference}", merge_request_path(merge_request)
#up-build-trace #up-build-trace
- builds = @build.commit.builds.latest.to_a - builds = @build.pipeline.builds.latest.to_a
- if builds.size > 1 - if builds.size > 1
%ul.nav-links.no-top.no-bottom %ul.nav-links.no-top.no-bottom
- builds.each do |build| - builds.each do |build|
...@@ -178,16 +178,16 @@ ...@@ -178,16 +178,16 @@
Commit Commit
.pull-right .pull-right
%small %small
= link_to @build.commit.short_sha, ci_status_path(@build.commit), class: "monospace" = link_to @build.pipeline.short_sha, ci_status_path(@build.pipeline), class: "monospace"
%p %p
%span.attr-name Branch: %span.attr-name Branch:
= link_to @build.ref, namespace_project_commits_path(@project.namespace, @project, @build.ref) = link_to @build.ref, namespace_project_commits_path(@project.namespace, @project, @build.ref)
%p %p
%span.attr-name Author: %span.attr-name Author:
#{@build.commit.git_author_name} #{@build.pipeline.git_author_name}
%p %p
%span.attr-name Message: %span.attr-name Message:
#{@build.commit.git_commit_message} #{@build.pipeline.git_commit_message}
- if @build.tags.any? - if @build.tags.any?
.build-widget .build-widget
...@@ -201,7 +201,7 @@ ...@@ -201,7 +201,7 @@
.build-widget .build-widget
%h4.title #{pluralize(@builds.count(:id), "other build")} for %h4.title #{pluralize(@builds.count(:id), "other build")} for
= succeed ":" do = succeed ":" do
= link_to @build.commit.short_sha, ci_status_path(@build.commit), class: "monospace" = link_to @build.pipeline.short_sha, ci_status_path(@build.pipeline), class: "monospace"
%table.table.builds %table.table.builds
- @builds.each_with_index do |build, i| - @builds.each_with_index do |build, i|
%tr.build %tr.build
......
- status = commit.status - status = pipeline.status
%tr.commit %tr.commit
%td.commit-link %td.commit-link
= link_to namespace_project_pipeline_path(@project.namespace, @project, commit.id), class: "ci-status ci-#{status}" do = link_to namespace_project_pipeline_path(@project.namespace, @project, pipeline.id), class: "ci-status ci-#{status}" do
= ci_icon_for_status(status) = ci_icon_for_status(status)
%strong ##{commit.id} %strong ##{pipeline.id}
%td %td
%div.branch-commit %div.branch-commit
- if commit.ref - if pipeline.ref
= link_to commit.ref, namespace_project_commits_path(@project.namespace, @project, commit.ref), class: "monospace" = link_to pipeline.ref, namespace_project_commits_path(@project.namespace, @project, pipeline.ref), class: "monospace"
&middot; &middot;
= link_to commit.short_sha, namespace_project_commit_path(@project.namespace, @project, commit.sha), class: "commit-id monospace" = link_to pipeline.short_sha, namespace_project_commit_path(@project.namespace, @project, pipeline.sha), class: "commit-id monospace"
&nbsp; &nbsp;
- if commit.tag? - if pipeline.tag?
%span.label.label-primary tag %span.label.label-primary tag
- elsif commit.latest? - elsif pipeline.latest?
%span.label.label-success.has-tooltip{ title: 'Latest build for this branch' } latest %span.label.label-success.has-tooltip{ title: 'Latest build for this branch' } latest
- if commit.triggered? - if pipeline.triggered?
%span.label.label-primary triggered %span.label.label-primary triggered
- if commit.yaml_errors.present? - if pipeline.yaml_errors.present?
%span.label.label-danger.has-tooltip{ title: "#{commit.yaml_errors}" } yaml invalid %span.label.label-danger.has-tooltip{ title: "#{pipeline.yaml_errors}" } yaml invalid
- if commit.builds.any?(&:stuck?) - if pipeline.builds.any?(&:stuck?)
%span.label.label-warning stuck %span.label.label-warning stuck
%p.commit-title %p.commit-title
- if commit_data = commit.commit_data - if commit_data = pipeline.commit_data
= link_to_gfm truncate(commit_data.title, length: 60), namespace_project_commit_path(@project.namespace, @project, commit_data.id), class: "commit-row-message" = link_to_gfm truncate(commit_data.title, length: 60), namespace_project_commit_path(@project.namespace, @project, commit_data.id), class: "commit-row-message"
- else - else
Cant find HEAD commit for this branch Cant find HEAD commit for this branch
- stages_status = commit.statuses.stages_status - stages_status = pipeline.statuses.stages_status
- stages.each do |stage| - stages.each do |stage|
%td %td
- status = stages_status[stage] - status = stages_status[stage]
- tooltip = "#{stage.titleize}: #{status || 'not found'}" - tooltip = "#{stage.titleize}: #{status || 'not found'}"
- if status - if status
= link_to namespace_project_pipeline_path(@project.namespace, @project, commit.id, anchor: stage), class: "has-tooltip ci-status-icon-#{status}", title: tooltip do = link_to namespace_project_pipeline_path(@project.namespace, @project, pipeline.id, anchor: stage), class: "has-tooltip ci-status-icon-#{status}", title: tooltip do
= ci_icon_for_status(status) = ci_icon_for_status(status)
- else - else
.light.has-tooltip{ title: tooltip } .light.has-tooltip{ title: tooltip }
\- \-
%td %td
- if commit.started_at && commit.finished_at - if pipeline.started_at && pipeline.finished_at
%p.duration %p.duration
#{duration_in_words(commit.finished_at, commit.started_at)} #{duration_in_words(pipeline.finished_at, pipeline.started_at)}
%td %td
.controls.hidden-xs.pull-right .controls.hidden-xs.pull-right
- artifacts = commit.builds.latest.select { |b| b.artifacts? } - artifacts = pipeline.builds.latest.select { |b| b.artifacts? }
- if artifacts.present? - if artifacts.present?
.dropdown.inline.build-artifacts .dropdown.inline.build-artifacts
%button.dropdown-toggle.btn{type: 'button', 'data-toggle' => 'dropdown'} %button.dropdown-toggle.btn{type: 'button', 'data-toggle' => 'dropdown'}
...@@ -63,9 +63,9 @@ ...@@ -63,9 +63,9 @@
%span #{build.name} %span #{build.name}
- if can?(current_user, :update_pipeline, @project) - if can?(current_user, :update_pipeline, @project)
- if commit.retryable? - if pipeline.retryable?
= link_to retry_namespace_project_pipeline_path(@project.namespace, @project, commit.id), class: 'btn has-tooltip', title: "Retry", method: :post do = link_to retry_namespace_project_pipeline_path(@project.namespace, @project, pipeline.id), class: 'btn has-tooltip', title: "Retry", method: :post do
= icon("repeat") = icon("repeat")
- if commit.cancelable? - if pipeline.cancelable?
= link_to cancel_namespace_project_pipeline_path(@project.namespace, @project, commit.id), class: 'btn btn-remove has-tooltip', title: "Cancel", method: :post do = link_to cancel_namespace_project_pipeline_path(@project.namespace, @project, pipeline.id), class: 'btn btn-remove has-tooltip', title: "Cancel", method: :post do
= icon("remove") = icon("remove")
...@@ -53,13 +53,13 @@ ...@@ -53,13 +53,13 @@
- if @commit.status - if @commit.status
.commit-info-row .commit-info-row
Builds for Builds for
= pluralize(@commit.ci_commits.count, 'pipeline') = pluralize(@commit.pipelines.count, 'pipeline')
= link_to builds_namespace_project_commit_path(@project.namespace, @project, @commit.id), class: "ci-status-link ci-status-icon-#{@commit.status}" do = link_to builds_namespace_project_commit_path(@project.namespace, @project, @commit.id), class: "ci-status-link ci-status-icon-#{@commit.status}" do
= ci_icon_for_status(@commit.status) = ci_icon_for_status(@commit.status)
= ci_label_for_status(@commit.status) = ci_label_for_status(@commit.status)
- if @commit.ci_commits.duration - if @commit.pipelines.duration
in in
= time_interval_in_words @commit.ci_commits.duration = time_interval_in_words @commit.pipelines.duration
.commit-box.content-block .commit-box.content-block
%h3.commit-title %h3.commit-title
......
...@@ -16,4 +16,4 @@ ...@@ -16,4 +16,4 @@
%li %li
Commits covered: Commits covered:
%strong %strong
= @project.ci_commits.count(:all) = @project.pipelines.count(:all)
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
%h2.merge-requests-title %h2.merge-requests-title
= pluralize(@merge_requests.count, 'Related Merge Request') = pluralize(@merge_requests.count, 'Related Merge Request')
%ul.unstyled-list %ul.unstyled-list
- has_any_ci = @merge_requests.any?(&:ci_commit) - has_any_ci = @merge_requests.any?(&:pipeline)
- @merge_requests.each do |merge_request| - @merge_requests.each do |merge_request|
%li %li
%span.merge-request-ci-status %span.merge-request-ci-status
- if merge_request.ci_commit - if merge_request.pipeline
= render_pipeline_status(merge_request.ci_commit) = render_pipeline_status(merge_request.pipeline)
- elsif has_any_ci - elsif has_any_ci
= icon('blank fw') = icon('blank fw')
%span.merge-request-id %span.merge-request-id
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
- @related_branches.each do |branch| - @related_branches.each do |branch|
%li %li
- sha = @project.repository.find_branch(branch).target - sha = @project.repository.find_branch(branch).target
- ci_commit = @project.ci_commit(sha, branch) if sha - pipeline = @project.pipeline(sha, branch) if sha
- if ci_commit - if ci_copipelinemmit
%span.related-branch-ci-status %span.related-branch-ci-status
= render_pipeline_status(ci_commit) = render_pipeline_status(pipeline)
%span.related-branch-info %span.related-branch-info
%strong %strong
= link_to namespace_project_compare_path(@project.namespace, @project, from: @project.default_branch, to: branch), class: "label-branch" do = link_to namespace_project_compare_path(@project.namespace, @project, from: @project.default_branch, to: branch), class: "label-branch" do
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
= icon('ban') = icon('ban')
CLOSED CLOSED
- if merge_request.ci_commit - if merge_request.pipeline
%li %li
= render_pipeline_status(merge_request.ci_commit) = render_pipeline_status(merge_request.pipeline)
- if merge_request.open? && merge_request.broken? - if merge_request.open? && merge_request.broken?
%li %li
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
check_enable: #{@merge_request.unchecked? ? "true" : "false"}, check_enable: #{@merge_request.unchecked? ? "true" : "false"},
ci_status_url: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", ci_status_url: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}",
gitlab_icon: "#{asset_path 'gitlab_logo.png'}", gitlab_icon: "#{asset_path 'gitlab_logo.png'}",
ci_status: "#{@merge_request.ci_commit ? @merge_request.ci_commit.status : ''}", ci_status: "#{@merge_request.pipeline ? @merge_request.pipeline.status : ''}",
ci_message: { ci_message: {
normal: "Build {{status}} for \"{{title}}\"", normal: "Build {{status}} for \"{{title}}\"",
preparing: "{{status}} build for \"{{title}}\"" preparing: "{{status}} build for \"{{title}}\""
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
= link_to project_pipelines_path(@project), title: 'Pipelines', class: 'shortcuts-pipelines' do = link_to project_pipelines_path(@project), title: 'Pipelines', class: 'shortcuts-pipelines' do
%span %span
Pipelines Pipelines
%span.badge.count.ci_counter= number_with_delimiter(@project.ci_commits.running_or_pending.count) %span.badge.count.ci_counter= number_with_delimiter(@project.pipelines.running_or_pending.count)
- if project_nav_tab? :builds - if project_nav_tab? :builds
= nav_link(controller: %w(builds)) do = nav_link(controller: %w(builds)) do
......
...@@ -19,7 +19,7 @@ class Gitlab::Seeder::Builds ...@@ -19,7 +19,7 @@ class Gitlab::Seeder::Builds
commits = @project.repository.commits('master', nil, 5) commits = @project.repository.commits('master', nil, 5)
commits_sha = commits.map { |commit| commit.raw.id } commits_sha = commits.map { |commit| commit.raw.id }
commits_sha.map do |sha| commits_sha.map do |sha|
@project.ensure_ci_commit(sha, 'master') @project.ensure_pipeline(sha, 'master')
end end
rescue rescue
[] []
......
...@@ -164,12 +164,12 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps ...@@ -164,12 +164,12 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps
step 'commit has ci status' do step 'commit has ci status' do
@project.enable_ci @project.enable_ci
ci_commit = create :ci_commit, project: @project, sha: sample_commit.id pipeline = create :ci_pipeline, project: @project, sha: sample_commit.id
create :ci_build, commit: ci_commit create :ci_build, pipeline: pipeline
end end
step 'repository contains ".gitlab-ci.yml" file' do step 'repository contains ".gitlab-ci.yml" file' do
allow_any_instance_of(Ci::Commit).to receive(:ci_yaml_file).and_return(String.new) allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file).and_return(String.new)
end end
step 'I see commit ci info' do step 'I see commit ci info' do
......
...@@ -519,8 +519,8 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -519,8 +519,8 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step '"Bug NS-05" has CI status' do step '"Bug NS-05" has CI status' do
project = merge_request.source_project project = merge_request.source_project
project.enable_ci project.enable_ci
ci_commit = create :ci_commit, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch pipeline = create :ci_pipeline, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch
create :ci_build, commit: ci_commit create :ci_build, pipeline: pipeline
end end
step 'I should see merge request "Bug NS-05" with CI status' do step 'I should see merge request "Bug NS-05" with CI status' do
......
...@@ -10,8 +10,8 @@ module SharedBuilds ...@@ -10,8 +10,8 @@ module SharedBuilds
end end
step 'project has a recent build' do step 'project has a recent build' do
@ci_commit = create(:ci_commit, project: @project, sha: @project.commit.sha, ref: 'master') @pipeline = create(:ci_pipeline, project: @project, sha: @project.commit.sha, ref: 'master')
@build = create(:ci_build_with_coverage, commit: @ci_commit) @build = create(:ci_build_with_coverage, pipeline: @pipeline)
end end
step 'recent build is successful' do step 'recent build is successful' do
...@@ -23,7 +23,7 @@ module SharedBuilds ...@@ -23,7 +23,7 @@ module SharedBuilds
end end
step 'project has another build that is running' do step 'project has another build that is running' do
create(:ci_build, commit: @ci_commit, name: 'second build', status: 'running') create(:ci_build, pipeline: @pipeline, name: 'second build', status: 'running')
end end
step 'I visit recent build details page' do step 'I visit recent build details page' do
......
...@@ -230,7 +230,7 @@ module SharedProject ...@@ -230,7 +230,7 @@ module SharedProject
step 'project "Shop" has CI build' do step 'project "Shop" has CI build' do
project = Project.find_by(name: "Shop") project = Project.find_by(name: "Shop")
create :ci_commit, project: project, sha: project.commit.sha, ref: 'master', status: 'skipped' create :ci_pipeline, project: project, sha: project.commit.sha, ref: 'master', status: 'skipped'
end end
step 'I should see last commit with CI status' do step 'I should see last commit with CI status' do
......
...@@ -33,7 +33,7 @@ module API ...@@ -33,7 +33,7 @@ module API
get ':id/repository/commits/:sha/builds' do get ':id/repository/commits/:sha/builds' do
authorize_read_builds! authorize_read_builds!
commit = user_project.ci_commits.find_by_sha(params[:sha]) commit = user_project.pipelines.find_by_sha(params[:sha])
return not_found! unless commit return not_found! unless commit
builds = commit.builds.order('id DESC') builds = commit.builds.order('id DESC')
......
...@@ -22,8 +22,8 @@ module API ...@@ -22,8 +22,8 @@ module API
not_found!('Commit') unless user_project.commit(params[:sha]) not_found!('Commit') unless user_project.commit(params[:sha])
ci_commits = user_project.ci_commits.where(sha: params[:sha]) ci_commits = user_project.pipelines.where(sha: params[:sha])
statuses = ::CommitStatus.where(commit: ci_commits) statuses = ::CommitStatus.where(pipeline: ci_commits)
statuses = statuses.latest unless parse_boolean(params[:all]) statuses = statuses.latest unless parse_boolean(params[:all])
statuses = statuses.where(ref: params[:ref]) if params[:ref].present? statuses = statuses.where(ref: params[:ref]) if params[:ref].present?
statuses = statuses.where(stage: params[:stage]) if params[:stage].present? statuses = statuses.where(stage: params[:stage]) if params[:stage].present?
...@@ -50,7 +50,7 @@ module API ...@@ -50,7 +50,7 @@ module API
commit = @project.commit(params[:sha]) commit = @project.commit(params[:sha])
not_found! 'Commit' unless commit not_found! 'Commit' unless commit
# Since the CommitStatus is attached to Ci::Commit (in the future Pipeline) # Since the CommitStatus is attached to Ci::Pipeline (in the future Pipeline)
# We need to always have the pipeline object # We need to always have the pipeline object
# To have a valid pipeline object that can be attached to specific MR # To have a valid pipeline object that can be attached to specific MR
# Other CI service needs to send `ref` # Other CI service needs to send `ref`
...@@ -64,11 +64,11 @@ module API ...@@ -64,11 +64,11 @@ module API
ref = branches.first ref = branches.first
end end
ci_commit = @project.ensure_ci_commit(commit.sha, ref) ci_commit = @project.ensure_pipeline(commit.sha, ref)
name = params[:name] || params[:context] name = params[:name] || params[:context]
status = GenericCommitStatus.running_or_pending.find_by(commit: ci_commit, name: name, ref: params[:ref]) status = GenericCommitStatus.running_or_pending.find_by(pipeline: ci_commit, name: name, ref: params[:ref])
status ||= GenericCommitStatus.new(project: @project, commit: ci_commit, user: current_user) status ||= GenericCommitStatus.new(project: @project, pipeline: ci_commit, user: current_user)
status.update(attrs) status.update(attrs)
case params[:state].to_s case params[:state].to_s
......
...@@ -243,7 +243,7 @@ module API ...@@ -243,7 +243,7 @@ module API
should_remove_source_branch: params[:should_remove_source_branch] should_remove_source_branch: params[:should_remove_source_branch]
} }
if parse_boolean(params[:merge_when_build_succeeds]) && merge_request.ci_commit && merge_request.ci_commit.active? if parse_boolean(params[:merge_when_build_succeeds]) && merge_request.pipeline && merge_request.pipeline.active?
::MergeRequests::MergeWhenBuildSucceedsService.new(merge_request.target_project, current_user, merge_params). ::MergeRequests::MergeWhenBuildSucceedsService.new(merge_request.target_project, current_user, merge_params).
execute(merge_request) execute(merge_request)
else else
......
...@@ -60,7 +60,7 @@ module Ci ...@@ -60,7 +60,7 @@ module Ci
class BuildTime < Chart class BuildTime < Chart
def collect def collect
commits = project.ci_commits.last(30) commits = project.pipelines.last(30)
commits.each do |commit| commits.each do |commit|
@labels << commit.short_sha @labels << commit.short_sha
......
...@@ -3,7 +3,7 @@ module Gitlab ...@@ -3,7 +3,7 @@ module Gitlab
class << self class << self
def build(build) def build(build)
project = build.project project = build.project
commit = build.commit commit = build.pipeline
user = build.user user = build.user
data = { data = {
......
...@@ -250,7 +250,7 @@ describe Projects::MergeRequestsController do ...@@ -250,7 +250,7 @@ describe Projects::MergeRequestsController do
end end
before do before do
create(:ci_empty_commit, project: project, sha: merge_request.source_sha, ref: merge_request.source_branch) create(:ci_empty_pipeline, project: project, sha: merge_request.source_sha, ref: merge_request.source_branch)
end end
it 'returns :merge_when_build_succeeds' do it 'returns :merge_when_build_succeeds' do
......
...@@ -16,7 +16,7 @@ FactoryGirl.define do ...@@ -16,7 +16,7 @@ FactoryGirl.define do
} }
end end
commit factory: :ci_commit pipeline factory: :ci_pipeline
trait :success do trait :success do
status 'success' status 'success'
...@@ -43,7 +43,7 @@ FactoryGirl.define do ...@@ -43,7 +43,7 @@ FactoryGirl.define do
end end
after(:build) do |build, evaluator| after(:build) do |build, evaluator|
build.project = build.commit.project build.project = build.pipeline.project
end end
factory :ci_not_started_build do factory :ci_not_started_build do
......
...@@ -17,30 +17,30 @@ ...@@ -17,30 +17,30 @@
# #
FactoryGirl.define do FactoryGirl.define do
factory :ci_empty_commit, class: Ci::Commit do factory :ci_empty_pipeline, class: Ci::Pipeline do
sha '97de212e80737a608d939f648d959671fb0a0142' sha '97de212e80737a608d939f648d959671fb0a0142'
project factory: :empty_project project factory: :empty_project
factory :ci_commit_without_jobs do factory :ci_pipeline_without_jobs do
after(:build) do |commit| after(:build) do |commit|
allow(commit).to receive(:ci_yaml_file) { YAML.dump({}) } allow(commit).to receive(:ci_yaml_file) { YAML.dump({}) }
end end
end end
factory :ci_commit_with_one_job do factory :ci_pipeline_with_one_job do
after(:build) do |commit| after(:build) do |commit|
allow(commit).to receive(:ci_yaml_file) { YAML.dump({ rspec: { script: "ls" } }) } allow(commit).to receive(:ci_yaml_file) { YAML.dump({ rspec: { script: "ls" } }) }
end end
end end
factory :ci_commit_with_two_jobs do factory :ci_pipeline_with_two_job do
after(:build) do |commit| after(:build) do |commit|
allow(commit).to receive(:ci_yaml_file) { YAML.dump({ rspec: { script: "ls" }, spinach: { script: "ls" } }) } allow(commit).to receive(:ci_yaml_file) { YAML.dump({ rspec: { script: "ls" }, spinach: { script: "ls" } }) }
end end
end end
factory :ci_commit do factory :ci_pipeline do
after(:build) do |commit| after(:build) do |commit|
allow(commit).to receive(:ci_yaml_file) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) } allow(commit).to receive(:ci_yaml_file) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) }
end end
......
...@@ -3,12 +3,12 @@ FactoryGirl.define do ...@@ -3,12 +3,12 @@ FactoryGirl.define do
name 'default' name 'default'
status 'success' status 'success'
description 'commit status' description 'commit status'
commit factory: :ci_commit_with_one_job pipeline factory: :ci_pipeline_with_one_job
started_at 'Tue, 26 Jan 2016 08:21:42 +0100' started_at 'Tue, 26 Jan 2016 08:21:42 +0100'
finished_at 'Tue, 26 Jan 2016 08:23:42 +0100' finished_at 'Tue, 26 Jan 2016 08:23:42 +0100'
after(:build) do |build, evaluator| after(:build) do |build, evaluator|
build.project = build.commit.project build.project = build.pipeline.project
end end
factory :generic_commit_status, class: GenericCommitStatus do factory :generic_commit_status, class: GenericCommitStatus do
......
...@@ -6,15 +6,15 @@ describe 'Admin Builds' do ...@@ -6,15 +6,15 @@ describe 'Admin Builds' do
end end
describe 'GET /admin/builds' do describe 'GET /admin/builds' do
let(:commit) { create(:ci_commit) } let(:pipeline) { create(:ci_pipeline) }
context 'All tab' do context 'All tab' do
context 'when have builds' do context 'when have builds' do
it 'shows all builds' do it 'shows all builds' do
create(:ci_build, commit: commit, status: :pending) create(:ci_build, pipeline: pipeline, status: :pending)
create(:ci_build, commit: commit, status: :running) create(:ci_build, pipeline: pipeline, status: :running)
create(:ci_build, commit: commit, status: :success) create(:ci_build, pipeline: pipeline, status: :success)
create(:ci_build, commit: commit, status: :failed) create(:ci_build, pipeline: pipeline, status: :failed)
visit admin_builds_path visit admin_builds_path
...@@ -39,9 +39,9 @@ describe 'Admin Builds' do ...@@ -39,9 +39,9 @@ describe 'Admin Builds' do
context 'Running tab' do context 'Running tab' do
context 'when have running builds' do context 'when have running builds' do
it 'shows running builds' do it 'shows running builds' do
build1 = create(:ci_build, commit: commit, status: :pending) build1 = create(:ci_build, pipeline: pipeline, status: :pending)
build2 = create(:ci_build, commit: commit, status: :success) build2 = create(:ci_build, pipeline: pipeline, status: :success)
build3 = create(:ci_build, commit: commit, status: :failed) build3 = create(:ci_build, pipeline: pipeline, status: :failed)
visit admin_builds_path(scope: :running) visit admin_builds_path(scope: :running)
...@@ -55,7 +55,7 @@ describe 'Admin Builds' do ...@@ -55,7 +55,7 @@ describe 'Admin Builds' do
context 'when have no builds running' do context 'when have no builds running' do
it 'shows a message' do it 'shows a message' do
create(:ci_build, commit: commit, status: :success) create(:ci_build, pipeline: pipeline, status: :success)
visit admin_builds_path(scope: :running) visit admin_builds_path(scope: :running)
...@@ -69,9 +69,9 @@ describe 'Admin Builds' do ...@@ -69,9 +69,9 @@ describe 'Admin Builds' do
context 'Finished tab' do context 'Finished tab' do
context 'when have finished builds' do context 'when have finished builds' do
it 'shows finished builds' do it 'shows finished builds' do
build1 = create(:ci_build, commit: commit, status: :pending) build1 = create(:ci_build, pipeline: pipeline, status: :pending)
build2 = create(:ci_build, commit: commit, status: :running) build2 = create(:ci_build, pipeline: pipeline, status: :running)
build3 = create(:ci_build, commit: commit, status: :success) build3 = create(:ci_build, pipeline: pipeline, status: :success)
visit admin_builds_path(scope: :finished) visit admin_builds_path(scope: :finished)
...@@ -85,7 +85,7 @@ describe 'Admin Builds' do ...@@ -85,7 +85,7 @@ describe 'Admin Builds' do
context 'when have no builds finished' do context 'when have no builds finished' do
it 'shows a message' do it 'shows a message' do
create(:ci_build, commit: commit, status: :running) create(:ci_build, pipeline: pipeline, status: :running)
visit admin_builds_path(scope: :finished) visit admin_builds_path(scope: :finished)
......
...@@ -8,8 +8,8 @@ describe "Admin Runners" do ...@@ -8,8 +8,8 @@ describe "Admin Runners" do
describe "Runners page" do describe "Runners page" do
before do before do
runner = FactoryGirl.create(:ci_runner) runner = FactoryGirl.create(:ci_runner)
commit = FactoryGirl.create(:ci_commit) pipeline = FactoryGirl.create(:ci_pipeline)
FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) FactoryGirl.create(:ci_build, pipeline: pipeline, runner_id: runner.id)
visit admin_runners_path visit admin_runners_path
end end
......
...@@ -5,8 +5,8 @@ describe "Builds" do ...@@ -5,8 +5,8 @@ describe "Builds" do
before do before do
login_as(:user) login_as(:user)
@commit = FactoryGirl.create :ci_commit @commit = FactoryGirl.create :ci_pipeline
@build = FactoryGirl.create :ci_build, commit: @commit @build = FactoryGirl.create :ci_build, pipeline: @commit
@build2 = FactoryGirl.create :ci_build @build2 = FactoryGirl.create :ci_build
@project = @commit.project @project = @commit.project
@project.team << [@user, :developer] @project.team << [@user, :developer]
......
...@@ -8,15 +8,15 @@ describe 'Commits' do ...@@ -8,15 +8,15 @@ describe 'Commits' do
describe 'CI' do describe 'CI' do
before do before do
login_as :user login_as :user
stub_ci_commit_to_return_yaml_file stub_ci_pipeline_to_return_yaml_file
end end
let!(:commit) do let!(:pipeline) do
FactoryGirl.create :ci_commit, project: project, sha: project.commit.sha FactoryGirl.create :ci_pipeline, project: project, sha: project.commit.sha
end end
context 'commit status is Generic Commit Status' do context 'commit status is Generic Commit Status' do
let!(:status) { FactoryGirl.create :generic_commit_status, commit: commit } let!(:status) { FactoryGirl.create :generic_commit_status, pipeline: pipeline }
before do before do
project.team << [@user, :reporter] project.team << [@user, :reporter]
...@@ -24,10 +24,10 @@ describe 'Commits' do ...@@ -24,10 +24,10 @@ describe 'Commits' do
describe 'Commit builds' do describe 'Commit builds' do
before do before do
visit ci_status_path(commit) visit ci_status_path(pipeline)
end end
it { expect(page).to have_content commit.sha[0..7] } it { expect(page).to have_content pipeline.sha[0..7] }
it 'contains generic commit status build' do it 'contains generic commit status build' do
page.within('.table-holder') do page.within('.table-holder') do
...@@ -39,7 +39,7 @@ describe 'Commits' do ...@@ -39,7 +39,7 @@ describe 'Commits' do
end end
context 'commit status is Ci Build' do context 'commit status is Ci Build' do
let!(:build) { FactoryGirl.create :ci_build, commit: commit } let!(:build) { FactoryGirl.create :ci_build, pipeline: pipeline }
let(:artifacts_file) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') } let(:artifacts_file) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
context 'when logged as developer' do context 'when logged as developer' do
...@@ -53,7 +53,7 @@ describe 'Commits' do ...@@ -53,7 +53,7 @@ describe 'Commits' do
end end
it 'should show build status' do it 'should show build status' do
page.within("//li[@id='commit-#{commit.short_sha}']") do page.within("//li[@id='commit-#{pipeline.short_sha}']") do
expect(page).to have_css(".ci-status-link") expect(page).to have_css(".ci-status-link")
end end
end end
...@@ -61,12 +61,12 @@ describe 'Commits' do ...@@ -61,12 +61,12 @@ describe 'Commits' do
describe 'Commit builds' do describe 'Commit builds' do
before do before do
visit ci_status_path(commit) visit ci_status_path(pipeline)
end end
it { expect(page).to have_content commit.sha[0..7] } it { expect(page).to have_content pipeline.sha[0..7] }
it { expect(page).to have_content commit.git_commit_message } it { expect(page).to have_content pipeline.git_commit_message }
it { expect(page).to have_content commit.git_author_name } it { expect(page).to have_content pipeline.git_author_name }
end end
context 'Download artifacts' do context 'Download artifacts' do
...@@ -75,7 +75,7 @@ describe 'Commits' do ...@@ -75,7 +75,7 @@ describe 'Commits' do
end end
it do it do
visit ci_status_path(commit) visit ci_status_path(pipeline)
click_on 'Download artifacts' click_on 'Download artifacts'
expect(page.response_headers['Content-Type']).to eq(artifacts_file.content_type) expect(page.response_headers['Content-Type']).to eq(artifacts_file.content_type)
end end
...@@ -83,7 +83,7 @@ describe 'Commits' do ...@@ -83,7 +83,7 @@ describe 'Commits' do
describe 'Cancel all builds' do describe 'Cancel all builds' do
it 'cancels commit' do it 'cancels commit' do
visit ci_status_path(commit) visit ci_status_path(pipeline)
click_on 'Cancel running' click_on 'Cancel running'
expect(page).to have_content 'canceled' expect(page).to have_content 'canceled'
end end
...@@ -91,7 +91,7 @@ describe 'Commits' do ...@@ -91,7 +91,7 @@ describe 'Commits' do
describe 'Cancel build' do describe 'Cancel build' do
it 'cancels build' do it 'cancels build' do
visit ci_status_path(commit) visit ci_status_path(pipeline)
click_on 'Cancel' click_on 'Cancel'
expect(page).to have_content 'canceled' expect(page).to have_content 'canceled'
end end
...@@ -100,13 +100,13 @@ describe 'Commits' do ...@@ -100,13 +100,13 @@ describe 'Commits' do
describe '.gitlab-ci.yml not found warning' do describe '.gitlab-ci.yml not found warning' do
context 'ci builds enabled' do context 'ci builds enabled' do
it "does not show warning" do it "does not show warning" do
visit ci_status_path(commit) visit ci_status_path(pipeline)
expect(page).not_to have_content '.gitlab-ci.yml not found in this commit' expect(page).not_to have_content '.gitlab-ci.yml not found in this commit'
end end
it 'shows warning' do it 'shows warning' do
stub_ci_commit_yaml_file(nil) stub_ci_pipeline_yaml_file(nil)
visit ci_status_path(commit) visit ci_status_path(pipeline)
expect(page).to have_content '.gitlab-ci.yml not found in this commit' expect(page).to have_content '.gitlab-ci.yml not found in this commit'
end end
end end
...@@ -114,8 +114,8 @@ describe 'Commits' do ...@@ -114,8 +114,8 @@ describe 'Commits' do
context 'ci builds disabled' do context 'ci builds disabled' do
before do before do
stub_ci_builds_disabled stub_ci_builds_disabled
stub_ci_commit_yaml_file(nil) stub_ci_pipeline_yaml_file(nil)
visit ci_status_path(commit) visit ci_status_path(pipeline)
end end
it 'does not show warning' do it 'does not show warning' do
...@@ -129,13 +129,13 @@ describe 'Commits' do ...@@ -129,13 +129,13 @@ describe 'Commits' do
before do before do
project.team << [@user, :reporter] project.team << [@user, :reporter]
build.update_attributes(artifacts_file: artifacts_file) build.update_attributes(artifacts_file: artifacts_file)
visit ci_status_path(commit) visit ci_status_path(pipeline)
end end
it do it do
expect(page).to have_content commit.sha[0..7] expect(page).to have_content pipeline.sha[0..7]
expect(page).to have_content commit.git_commit_message expect(page).to have_content pipeline.git_commit_message
expect(page).to have_content commit.git_author_name expect(page).to have_content pipeline.git_author_name
expect(page).to have_link('Download artifacts') expect(page).to have_link('Download artifacts')
expect(page).not_to have_link('Cancel running') expect(page).not_to have_link('Cancel running')
expect(page).not_to have_link('Retry failed') expect(page).not_to have_link('Retry failed')
...@@ -148,13 +148,13 @@ describe 'Commits' do ...@@ -148,13 +148,13 @@ describe 'Commits' do
visibility_level: Gitlab::VisibilityLevel::INTERNAL, visibility_level: Gitlab::VisibilityLevel::INTERNAL,
public_builds: false) public_builds: false)
build.update_attributes(artifacts_file: artifacts_file) build.update_attributes(artifacts_file: artifacts_file)
visit ci_status_path(commit) visit ci_status_path(pipeline)
end end
it do it do
expect(page).to have_content commit.sha[0..7] expect(page).to have_content pipeline.sha[0..7]
expect(page).to have_content commit.git_commit_message expect(page).to have_content pipeline.git_commit_message
expect(page).to have_content commit.git_author_name expect(page).to have_content pipeline.git_author_name
expect(page).not_to have_link('Download artifacts') expect(page).not_to have_link('Download artifacts')
expect(page).not_to have_link('Cancel running') expect(page).not_to have_link('Cancel running')
expect(page).not_to have_link('Retry failed') expect(page).not_to have_link('Retry failed')
......
...@@ -29,9 +29,9 @@ feature 'Merge request created from fork' do ...@@ -29,9 +29,9 @@ feature 'Merge request created from fork' do
include WaitForAjax include WaitForAjax
given(:pipeline) do given(:pipeline) do
create(:ci_commit_with_two_jobs, project: fork_project, create(:ci_pipeline_with_two_job, project: fork_project,
sha: merge_request.last_commit.id, sha: merge_request.last_commit.id,
ref: merge_request.source_branch) ref: merge_request.source_branch)
end end
background { pipeline.create_builds(user) } background { pipeline.create_builds(user) }
......
...@@ -12,8 +12,8 @@ feature 'Merge When Build Succeeds', feature: true, js: true do ...@@ -12,8 +12,8 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
end end
context "Active build for Merge Request" do context "Active build for Merge Request" do
let!(:ci_commit) { create(:ci_commit, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch) } let!(:pipeline) { create(:ci_pipeline, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch) }
let!(:ci_build) { create(:ci_build, commit: ci_commit) } let!(:ci_build) { create(:ci_build, pipeline: pipeline) }
before do before do
login_as user login_as user
...@@ -47,8 +47,8 @@ feature 'Merge When Build Succeeds', feature: true, js: true do ...@@ -47,8 +47,8 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
merge_user: user, title: "MepMep", merge_when_build_succeeds: true) merge_user: user, title: "MepMep", merge_when_build_succeeds: true)
end end
let!(:ci_commit) { create(:ci_commit, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch) } let!(:pipeline) { create(:ci_pipeline, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch) }
let!(:ci_build) { create(:ci_build, commit: ci_commit) } let!(:ci_build) { create(:ci_build, pipeline: pipeline) }
before do before do
login_as user login_as user
......
...@@ -12,7 +12,7 @@ describe "Pipelines" do ...@@ -12,7 +12,7 @@ describe "Pipelines" do
end end
describe 'GET /:project/pipelines' do describe 'GET /:project/pipelines' do
let!(:pipeline) { create(:ci_commit, project: project, ref: 'master', status: 'running') } let!(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', status: 'running') }
[:all, :running, :branches].each do |scope| [:all, :running, :branches].each do |scope|
context "displaying #{scope}" do context "displaying #{scope}" do
...@@ -31,7 +31,7 @@ describe "Pipelines" do ...@@ -31,7 +31,7 @@ describe "Pipelines" do
end end
context 'cancelable pipeline' do context 'cancelable pipeline' do
let!(:running) { create(:ci_build, :running, commit: pipeline, stage: 'test', commands: 'test') } let!(:running) { create(:ci_build, :running, pipeline: pipeline, stage: 'test', commands: 'test') }
before { visit namespace_project_pipelines_path(project.namespace, project) } before { visit namespace_project_pipelines_path(project.namespace, project) }
...@@ -47,7 +47,7 @@ describe "Pipelines" do ...@@ -47,7 +47,7 @@ describe "Pipelines" do
end end
context 'retryable pipelines' do context 'retryable pipelines' do
let!(:failed) { create(:ci_build, :failed, commit: pipeline, stage: 'test', commands: 'test') } let!(:failed) { create(:ci_build, :failed, pipeline: pipeline, stage: 'test', commands: 'test') }
before { visit namespace_project_pipelines_path(project.namespace, project) } before { visit namespace_project_pipelines_path(project.namespace, project) }
...@@ -64,7 +64,7 @@ describe "Pipelines" do ...@@ -64,7 +64,7 @@ describe "Pipelines" do
context 'for generic statuses' do context 'for generic statuses' do
context 'when running' do context 'when running' do
let!(:running) { create(:generic_commit_status, status: 'running', commit: pipeline, stage: 'test') } let!(:running) { create(:generic_commit_status, status: 'running', pipeline: pipeline, stage: 'test') }
before { visit namespace_project_pipelines_path(project.namespace, project) } before { visit namespace_project_pipelines_path(project.namespace, project) }
...@@ -78,7 +78,7 @@ describe "Pipelines" do ...@@ -78,7 +78,7 @@ describe "Pipelines" do
end end
context 'when failed' do context 'when failed' do
let!(:running) { create(:generic_commit_status, status: 'failed', commit: pipeline, stage: 'test') } let!(:running) { create(:generic_commit_status, status: 'failed', pipeline: pipeline, stage: 'test') }
before { visit namespace_project_pipelines_path(project.namespace, project) } before { visit namespace_project_pipelines_path(project.namespace, project) }
...@@ -94,7 +94,7 @@ describe "Pipelines" do ...@@ -94,7 +94,7 @@ describe "Pipelines" do
context 'downloadable pipelines' do context 'downloadable pipelines' do
context 'with artifacts' do context 'with artifacts' do
let!(:with_artifacts) { create(:ci_build, :artifacts, :success, commit: pipeline, name: 'rspec tests', stage: 'test') } let!(:with_artifacts) { create(:ci_build, :artifacts, :success, pipeline: pipeline, name: 'rspec tests', stage: 'test') }
before { visit namespace_project_pipelines_path(project.namespace, project) } before { visit namespace_project_pipelines_path(project.namespace, project) }
...@@ -103,7 +103,7 @@ describe "Pipelines" do ...@@ -103,7 +103,7 @@ describe "Pipelines" do
end end
context 'without artifacts' do context 'without artifacts' do
let!(:without_artifacts) { create(:ci_build, :success, commit: pipeline, name: 'rspec', stage: 'test') } let!(:without_artifacts) { create(:ci_build, :success, pipeline: pipeline, name: 'rspec', stage: 'test') }
it { expect(page).not_to have_selector('.build-artifacts') } it { expect(page).not_to have_selector('.build-artifacts') }
end end
...@@ -111,13 +111,13 @@ describe "Pipelines" do ...@@ -111,13 +111,13 @@ describe "Pipelines" do
end end
describe 'GET /:project/pipelines/:id' do describe 'GET /:project/pipelines/:id' do
let(:pipeline) { create(:ci_commit, project: project, ref: 'master') } let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master') }
before do before do
@success = create(:ci_build, :success, commit: pipeline, stage: 'build', name: 'build') @success = create(:ci_build, :success, pipeline: pipeline, stage: 'build', name: 'build')
@failed = create(:ci_build, :failed, commit: pipeline, stage: 'test', name: 'test', commands: 'test') @failed = create(:ci_build, :failed, pipeline: pipeline, stage: 'test', name: 'test', commands: 'test')
@running = create(:ci_build, :running, commit: pipeline, stage: 'deploy', name: 'deploy') @running = create(:ci_build, :running, pipeline: pipeline, stage: 'deploy', name: 'deploy')
@external = create(:generic_commit_status, status: 'success', commit: pipeline, name: 'jenkins', stage: 'external') @external = create(:generic_commit_status, status: 'success', pipeline: pipeline, name: 'jenkins', stage: 'external')
end end
before { visit namespace_project_pipeline_path(project.namespace, project, pipeline) } before { visit namespace_project_pipeline_path(project.namespace, project, pipeline) }
...@@ -165,9 +165,9 @@ describe "Pipelines" do ...@@ -165,9 +165,9 @@ describe "Pipelines" do
before { fill_in('Create for', with: 'master') } before { fill_in('Create for', with: 'master') }
context 'with gitlab-ci.yml' do context 'with gitlab-ci.yml' do
before { stub_ci_commit_to_return_yaml_file } before { stub_ci_pipeline_to_return_yaml_file }
it { expect{ click_on 'Create pipeline' }.to change{ Ci::Commit.count }.by(1) } it { expect{ click_on 'Create pipeline' }.to change{ Ci::Pipeline.count }.by(1) }
end end
context 'without gitlab-ci.yml' do context 'without gitlab-ci.yml' do
......
...@@ -11,9 +11,9 @@ feature 'project commit builds' do ...@@ -11,9 +11,9 @@ feature 'project commit builds' do
context 'when no builds triggered yet' do context 'when no builds triggered yet' do
background do background do
create(:ci_commit, project: project, create(:ci_pipeline, project: project,
sha: project.commit.sha, sha: project.commit.sha,
ref: 'master') ref: 'master')
end end
scenario 'user views commit builds page' do scenario 'user views commit builds page' do
......
...@@ -142,8 +142,8 @@ describe "Public Project Access", feature: true do ...@@ -142,8 +142,8 @@ describe "Public Project Access", feature: true do
end end
describe "GET /:project_path/builds/:id" do describe "GET /:project_path/builds/:id" do
let(:commit) { create(:ci_commit, project: project) } let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, commit: commit) } let(:build) { create(:ci_build, pipeline: pipeline) }
subject { namespace_project_build_path(project.namespace, project, build.id) } subject { namespace_project_build_path(project.namespace, project, build.id) }
context "when allowed for public" do context "when allowed for public" do
......
...@@ -3,8 +3,8 @@ require 'spec_helper' ...@@ -3,8 +3,8 @@ require 'spec_helper'
describe CiStatusHelper do describe CiStatusHelper do
include IconsHelper include IconsHelper
let(:success_commit) { double("Ci::Commit", status: 'success') } let(:success_commit) { double("Ci::Pipeline", status: 'success') }
let(:failed_commit) { double("Ci::Commit", status: 'failed') } let(:failed_commit) { double("Ci::Pipeline", status: 'failed') }
describe 'ci_icon_for_status' do describe 'ci_icon_for_status' do
it { expect(helper.ci_icon_for_status(success_commit.status)).to include('fa-check') } it { expect(helper.ci_icon_for_status(success_commit.status)).to include('fa-check') }
......
...@@ -5,7 +5,7 @@ describe MergeRequestsHelper do ...@@ -5,7 +5,7 @@ describe MergeRequestsHelper do
let(:project) { create :project } let(:project) { create :project }
let(:merge_request) { MergeRequest.new } let(:merge_request) { MergeRequest.new }
let(:ci_service) { CiService.new } let(:ci_service) { CiService.new }
let(:last_commit) { Ci::Commit.new({}) } let(:last_commit) { Ci::Pipeline.new({}) }
before do before do
allow(merge_request).to receive(:source_project).and_return(project) allow(merge_request).to receive(:source_project).and_return(project)
......
...@@ -4,19 +4,19 @@ describe Ci::Charts, lib: true do ...@@ -4,19 +4,19 @@ describe Ci::Charts, lib: true do
context "build_times" do context "build_times" do
before do before do
@commit = FactoryGirl.create(:ci_commit) @pipeline = FactoryGirl.create(:ci_pipeline)
FactoryGirl.create(:ci_build, commit: @commit) FactoryGirl.create(:ci_build, pipeline: @pipeline)
end end
it 'should return build times in minutes' do it 'should return build times in minutes' do
chart = Ci::Charts::BuildTime.new(@commit.project) chart = Ci::Charts::BuildTime.new(@pipeline.project)
expect(chart.build_times).to eq([2]) expect(chart.build_times).to eq([2])
end end
it 'should handle nil build times' do it 'should handle nil build times' do
create(:ci_commit, duration: nil, project: @commit.project) create(:ci_pipeline, duration: nil, project: @pipeline.project)
chart = Ci::Charts::BuildTime.new(@commit.project) chart = Ci::Charts::BuildTime.new(@pipeline.project)
expect(chart.build_times).to eq([2, 0]) expect(chart.build_times).to eq([2, 0])
end end
end end
......
...@@ -109,11 +109,11 @@ describe Gitlab::Badge::Build do ...@@ -109,11 +109,11 @@ describe Gitlab::Badge::Build do
end end
def create_build(project, sha, branch) def create_build(project, sha, branch)
ci_commit = create(:ci_commit, project: project, pipeline = create(:ci_pipeline, project: project,
sha: sha, sha: sha,
ref: branch) ref: branch)
create(:ci_build, commit: ci_commit) create(:ci_build, pipeline: pipeline)
end end
def status_node(data, status) def status_node(data, status)
......
...@@ -2,16 +2,16 @@ require 'spec_helper' ...@@ -2,16 +2,16 @@ require 'spec_helper'
describe Ci::Build, models: true do describe Ci::Build, models: true do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:commit) { create(:ci_commit, project: project) } let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, commit: commit) } let(:build) { create(:ci_build, pipeline: pipeline) }
it { is_expected.to validate_presence_of :ref } it { is_expected.to validate_presence_of :ref }
it { is_expected.to respond_to :trace_html } it { is_expected.to respond_to :trace_html }
describe '#first_pending' do describe '#first_pending' do
let!(:first) { create(:ci_build, commit: commit, status: 'pending', created_at: Date.yesterday) } let!(:first) { create(:ci_build, pipeline: pipeline, status: 'pending', created_at: Date.yesterday) }
let!(:second) { create(:ci_build, commit: commit, status: 'pending') } let!(:second) { create(:ci_build, pipeline: pipeline, status: 'pending') }
subject { Ci::Build.first_pending } subject { Ci::Build.first_pending }
it { is_expected.to be_a(Ci::Build) } it { is_expected.to be_a(Ci::Build) }
...@@ -97,7 +97,7 @@ describe Ci::Build, models: true do ...@@ -97,7 +97,7 @@ describe Ci::Build, models: true do
# describe :timeout do # describe :timeout do
# subject { build.timeout } # subject { build.timeout }
# #
# it { is_expected.to eq(commit.project.timeout) } # it { is_expected.to eq(pipeline.project.timeout) }
# end # end
describe '#options' do describe '#options' do
...@@ -124,13 +124,13 @@ describe Ci::Build, models: true do ...@@ -124,13 +124,13 @@ describe Ci::Build, models: true do
describe '#project' do describe '#project' do
subject { build.project } subject { build.project }
it { is_expected.to eq(commit.project) } it { is_expected.to eq(pipeline.project) }
end end
describe '#project_id' do describe '#project_id' do
subject { build.project_id } subject { build.project_id }
it { is_expected.to eq(commit.project_id) } it { is_expected.to eq(pipeline.project_id) }
end end
describe '#project_name' do describe '#project_name' do
...@@ -219,7 +219,7 @@ describe Ci::Build, models: true do ...@@ -219,7 +219,7 @@ describe Ci::Build, models: true do
context 'and trigger variables' do context 'and trigger variables' do
let(:trigger) { create(:ci_trigger, project: project) } let(:trigger) { create(:ci_trigger, project: project) }
let(:trigger_request) { create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger) } let(:trigger_request) { create(:ci_trigger_request_with_variables, commit: pipeline, trigger: trigger) }
let(:trigger_variables) do let(:trigger_variables) do
[ [
{ key: :TRIGGER_KEY, value: 'TRIGGER_VALUE', public: false } { key: :TRIGGER_KEY, value: 'TRIGGER_VALUE', public: false }
...@@ -428,10 +428,10 @@ describe Ci::Build, models: true do ...@@ -428,10 +428,10 @@ describe Ci::Build, models: true do
end end
describe '#depends_on_builds' do describe '#depends_on_builds' do
let!(:build) { create(:ci_build, commit: commit, name: 'build', stage_idx: 0, stage: 'build') } let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') }
let!(:rspec_test) { create(:ci_build, commit: commit, name: 'rspec', stage_idx: 1, stage: 'test') } let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') }
let!(:rubocop_test) { create(:ci_build, commit: commit, name: 'rubocop', stage_idx: 1, stage: 'test') } let!(:rubocop_test) { create(:ci_build, pipeline: pipeline, name: 'rubocop', stage_idx: 1, stage: 'test') }
let!(:staging) { create(:ci_build, commit: commit, name: 'staging', stage_idx: 2, stage: 'deploy') } let!(:staging) { create(:ci_build, pipeline: pipeline, name: 'staging', stage_idx: 2, stage: 'deploy') }
it 'to have no dependents if this is first build' do it 'to have no dependents if this is first build' do
expect(build.depends_on_builds).to be_empty expect(build.depends_on_builds).to be_empty
...@@ -451,19 +451,19 @@ describe Ci::Build, models: true do ...@@ -451,19 +451,19 @@ describe Ci::Build, models: true do
end end
end end
def create_mr(build, commit, factory: :merge_request, created_at: Time.now) def create_mr(build, pipeline, factory: :merge_request, created_at: Time.now)
create(factory, source_project_id: commit.gl_project_id, create(factory, source_project_id: pipeline.gl_project_id,
target_project_id: commit.gl_project_id, target_project_id: pipeline.gl_project_id,
source_branch: build.ref, source_branch: build.ref,
created_at: created_at) created_at: created_at)
end end
describe '#merge_request' do describe '#merge_request' do
context 'when a MR has a reference to the commit' do context 'when a MR has a reference to the pipeline' do
before do before do
@merge_request = create_mr(build, commit, factory: :merge_request) @merge_request = create_mr(build, pipeline, factory: :merge_request)
commits = [double(id: commit.sha)] commits = [double(id: pipeline.sha)]
allow(@merge_request).to receive(:commits).and_return(commits) allow(@merge_request).to receive(:commits).and_return(commits)
allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request]) allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request])
end end
...@@ -473,19 +473,19 @@ describe Ci::Build, models: true do ...@@ -473,19 +473,19 @@ describe Ci::Build, models: true do
end end
end end
context 'when there is not a MR referencing the commit' do context 'when there is not a MR referencing the pipeline' do
it 'returns nil' do it 'returns nil' do
expect(build.merge_request).to be_nil expect(build.merge_request).to be_nil
end end
end end
context 'when more than one MR have a reference to the commit' do context 'when more than one MR have a reference to the pipeline' do
before do before do
@merge_request = create_mr(build, commit, factory: :merge_request) @merge_request = create_mr(build, pipeline, factory: :merge_request)
@merge_request.close! @merge_request.close!
@merge_request2 = create_mr(build, commit, factory: :merge_request) @merge_request2 = create_mr(build, pipeline, factory: :merge_request)
commits = [double(id: commit.sha)] commits = [double(id: pipeline.sha)]
allow(@merge_request).to receive(:commits).and_return(commits) allow(@merge_request).to receive(:commits).and_return(commits)
allow(@merge_request2).to receive(:commits).and_return(commits) allow(@merge_request2).to receive(:commits).and_return(commits)
allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request, @merge_request2]) allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request, @merge_request2])
...@@ -498,11 +498,11 @@ describe Ci::Build, models: true do ...@@ -498,11 +498,11 @@ describe Ci::Build, models: true do
context 'when a Build is created after the MR' do context 'when a Build is created after the MR' do
before do before do
@merge_request = create_mr(build, commit, factory: :merge_request_with_diffs) @merge_request = create_mr(build, pipeline, factory: :merge_request_with_diffs)
commit2 = create(:ci_commit, project: project) pipeline2 = create(:ci_pipeline, project: project)
@build2 = create(:ci_build, commit: commit2) @build2 = create(:ci_build, pipeline: pipeline2)
commits = [double(id: commit.sha), double(id: commit2.sha)] commits = [double(id: pipeline.sha), double(id: pipeline2.sha)]
allow(@merge_request).to receive(:commits).and_return(commits) allow(@merge_request).to receive(:commits).and_return(commits)
allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request]) allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request])
end end
......
require 'spec_helper' require 'spec_helper'
describe Ci::Commit, models: true do describe Ci::Pipeline, models: true do
let(:project) { FactoryGirl.create :empty_project } let(:project) { FactoryGirl.create :empty_project }
let(:commit) { FactoryGirl.create :ci_commit, project: project } let(:pipeline) { FactoryGirl.create :ci_pipeline, project: project }
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
it { is_expected.to have_many(:statuses) } it { is_expected.to have_many(:statuses) }
...@@ -18,62 +18,62 @@ describe Ci::Commit, models: true do ...@@ -18,62 +18,62 @@ describe Ci::Commit, models: true do
describe :valid_commit_sha do describe :valid_commit_sha do
context 'commit.sha can not start with 00000000' do context 'commit.sha can not start with 00000000' do
before do before do
commit.sha = '0' * 40 pipeline.sha = '0' * 40
commit.valid_commit_sha pipeline.valid_commit_sha
end end
it('commit errors should not be empty') { expect(commit.errors).not_to be_empty } it('commit errors should not be empty') { expect(pipeline.errors).not_to be_empty }
end end
end end
describe :short_sha do describe :short_sha do
subject { commit.short_sha } subject { pipeline.short_sha }
it 'has 8 items' do it 'has 8 items' do
expect(subject.size).to eq(8) expect(subject.size).to eq(8)
end end
it { expect(commit.sha).to start_with(subject) } it { expect(pipeline.sha).to start_with(subject) }
end end
describe :create_next_builds do describe :create_next_builds do
end end
describe :retried do describe :retried do
subject { commit.retried } subject { pipeline.retried }
before do before do
@commit1 = FactoryGirl.create :ci_build, commit: commit, name: 'deploy' @build1 = FactoryGirl.create :ci_build, pipeline: pipeline, name: 'deploy'
@commit2 = FactoryGirl.create :ci_build, commit: commit, name: 'deploy' @build2 = FactoryGirl.create :ci_build, pipeline: pipeline, name: 'deploy'
end end
it 'returns old builds' do it 'returns old builds' do
is_expected.to contain_exactly(@commit1) is_expected.to contain_exactly(@build1)
end end
end end
describe :create_builds do describe :create_builds do
let!(:commit) { FactoryGirl.create :ci_commit, project: project, ref: 'master', tag: false } let!(:pipeline) { FactoryGirl.create :ci_pipeline, project: project, ref: 'master', tag: false }
def create_builds(trigger_request = nil) def create_builds(trigger_request = nil)
commit.create_builds(nil, trigger_request) pipeline.create_builds(nil, trigger_request)
end end
def create_next_builds def create_next_builds
commit.create_next_builds(commit.builds.order(:id).last) pipeline.create_next_builds(pipeline.builds.order(:id).last)
end end
it 'creates builds' do it 'creates builds' do
expect(create_builds).to be_truthy expect(create_builds).to be_truthy
commit.builds.update_all(status: "success") pipeline.builds.update_all(status: "success")
expect(commit.builds.count(:all)).to eq(2) expect(pipeline.builds.count(:all)).to eq(2)
expect(create_next_builds).to be_truthy expect(create_next_builds).to be_truthy
commit.builds.update_all(status: "success") pipeline.builds.update_all(status: "success")
expect(commit.builds.count(:all)).to eq(4) expect(pipeline.builds.count(:all)).to eq(4)
expect(create_next_builds).to be_truthy expect(create_next_builds).to be_truthy
commit.builds.update_all(status: "success") pipeline.builds.update_all(status: "success")
expect(commit.builds.count(:all)).to eq(5) expect(pipeline.builds.count(:all)).to eq(5)
expect(create_next_builds).to be_falsey expect(create_next_builds).to be_falsey
end end
...@@ -95,14 +95,14 @@ describe Ci::Commit, models: true do ...@@ -95,14 +95,14 @@ describe Ci::Commit, models: true do
end end
before do before do
stub_ci_commit_yaml_file(YAML.dump(yaml)) stub_ci_pipeline_yaml_file(YAML.dump(yaml))
create_builds create_builds
end end
it 'properly schedules builds' do it 'properly schedules builds' do
expect(commit.builds.pluck(:status)).to contain_exactly('pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:drop) pipeline.builds.running_or_pending.each(&:drop)
expect(commit.builds.pluck(:status)).to contain_exactly('pending', 'failed') expect(pipeline.builds.pluck(:status)).to contain_exactly('pending', 'failed')
end end
end end
...@@ -136,183 +136,183 @@ describe Ci::Commit, models: true do ...@@ -136,183 +136,183 @@ describe Ci::Commit, models: true do
end end
before do before do
stub_ci_commit_yaml_file(YAML.dump(yaml)) stub_ci_pipeline_yaml_file(YAML.dump(yaml))
end end
context 'when builds are successful' do context 'when builds are successful' do
it 'properly creates builds' do it 'properly creates builds' do
expect(create_builds).to be_truthy expect(create_builds).to be_truthy
expect(commit.builds.pluck(:name)).to contain_exactly('build') expect(pipeline.builds.pluck(:name)).to contain_exactly('build')
expect(commit.builds.pluck(:status)).to contain_exactly('pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'success', 'pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy', 'cleanup') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy', 'cleanup')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'success', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'success', 'success', 'pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'success', 'success') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'success', 'success', 'success')
commit.reload pipeline.reload
expect(commit.status).to eq('success') expect(pipeline.status).to eq('success')
end end
end end
context 'when test job fails' do context 'when test job fails' do
it 'properly creates builds' do it 'properly creates builds' do
expect(create_builds).to be_truthy expect(create_builds).to be_truthy
expect(commit.builds.pluck(:name)).to contain_exactly('build') expect(pipeline.builds.pluck(:name)).to contain_exactly('build')
expect(commit.builds.pluck(:status)).to contain_exactly('pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'pending')
commit.builds.running_or_pending.each(&:drop) pipeline.builds.running_or_pending.each(&:drop)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'failed', 'pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'success', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'failed', 'success', 'pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'success', 'success') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'failed', 'success', 'success')
commit.reload pipeline.reload
expect(commit.status).to eq('failed') expect(pipeline.status).to eq('failed')
end end
end end
context 'when test and test_failure jobs fail' do context 'when test and test_failure jobs fail' do
it 'properly creates builds' do it 'properly creates builds' do
expect(create_builds).to be_truthy expect(create_builds).to be_truthy
expect(commit.builds.pluck(:name)).to contain_exactly('build') expect(pipeline.builds.pluck(:name)).to contain_exactly('build')
expect(commit.builds.pluck(:status)).to contain_exactly('pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'pending')
commit.builds.running_or_pending.each(&:drop) pipeline.builds.running_or_pending.each(&:drop)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'failed', 'pending')
commit.builds.running_or_pending.each(&:drop) pipeline.builds.running_or_pending.each(&:drop)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'failed', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'failed', 'failed', 'pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'failed', 'success') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'failed', 'failed', 'success')
commit.reload pipeline.reload
expect(commit.status).to eq('failed') expect(pipeline.status).to eq('failed')
end end
end end
context 'when deploy job fails' do context 'when deploy job fails' do
it 'properly creates builds' do it 'properly creates builds' do
expect(create_builds).to be_truthy expect(create_builds).to be_truthy
expect(commit.builds.pluck(:name)).to contain_exactly('build') expect(pipeline.builds.pluck(:name)).to contain_exactly('build')
expect(commit.builds.pluck(:status)).to contain_exactly('pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'success', 'pending')
commit.builds.running_or_pending.each(&:drop) pipeline.builds.running_or_pending.each(&:drop)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy', 'cleanup') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy', 'cleanup')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'failed', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'success', 'failed', 'pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'failed', 'success') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'success', 'failed', 'success')
commit.reload pipeline.reload
expect(commit.status).to eq('failed') expect(pipeline.status).to eq('failed')
end end
end end
context 'when build is canceled in the second stage' do context 'when build is canceled in the second stage' do
it 'does not schedule builds after build has been canceled' do it 'does not schedule builds after build has been canceled' do
expect(create_builds).to be_truthy expect(create_builds).to be_truthy
expect(commit.builds.pluck(:name)).to contain_exactly('build') expect(pipeline.builds.pluck(:name)).to contain_exactly('build')
expect(commit.builds.pluck(:status)).to contain_exactly('pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:success) pipeline.builds.running_or_pending.each(&:success)
expect(commit.builds.running_or_pending).not_to be_empty expect(pipeline.builds.running_or_pending).not_to be_empty
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test') expect(pipeline.builds.pluck(:name)).to contain_exactly('build', 'test')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending') expect(pipeline.builds.pluck(:status)).to contain_exactly('success', 'pending')
commit.builds.running_or_pending.each(&:cancel) pipeline.builds.running_or_pending.each(&:cancel)
expect(commit.builds.running_or_pending).to be_empty expect(pipeline.builds.running_or_pending).to be_empty
expect(commit.reload.status).to eq('canceled') expect(pipeline.reload.status).to eq('canceled')
end end
end end
end end
end end
describe "#finished_at" do describe "#finished_at" do
let(:commit) { FactoryGirl.create :ci_commit } let(:pipeline) { FactoryGirl.create :ci_pipeline }
it "returns finished_at of latest build" do it "returns finished_at of latest build" do
build = FactoryGirl.create :ci_build, commit: commit, finished_at: Time.now - 60 build = FactoryGirl.create :ci_build, pipeline: pipeline, finished_at: Time.now - 60
FactoryGirl.create :ci_build, commit: commit, finished_at: Time.now - 120 FactoryGirl.create :ci_build, pipeline: pipeline, finished_at: Time.now - 120
expect(commit.finished_at.to_i).to eq(build.finished_at.to_i) expect(pipeline.finished_at.to_i).to eq(build.finished_at.to_i)
end end
it "returns nil if there is no finished build" do it "returns nil if there is no finished build" do
FactoryGirl.create :ci_not_started_build, commit: commit FactoryGirl.create :ci_not_started_build, pipeline: pipeline
expect(commit.finished_at).to be_nil expect(pipeline.finished_at).to be_nil
end end
end end
describe "coverage" do describe "coverage" do
let(:project) { FactoryGirl.create :empty_project, build_coverage_regex: "/.*/" } let(:project) { FactoryGirl.create :empty_project, build_coverage_regex: "/.*/" }
let(:commit) { FactoryGirl.create :ci_commit, project: project } let(:pipeline) { FactoryGirl.create :ci_pipeline, project: project }
it "calculates average when there are two builds with coverage" do it "calculates average when there are two builds with coverage" do
FactoryGirl.create :ci_build, name: "rspec", coverage: 30, commit: commit FactoryGirl.create :ci_build, name: "rspec", coverage: 30, pipeline: pipeline
FactoryGirl.create :ci_build, name: "rubocop", coverage: 40, commit: commit FactoryGirl.create :ci_build, name: "rubocop", coverage: 40, pipeline: pipeline
expect(commit.coverage).to eq("35.00") expect(pipeline.coverage).to eq("35.00")
end end
it "calculates average when there are two builds with coverage and one with nil" do it "calculates average when there are two builds with coverage and one with nil" do
FactoryGirl.create :ci_build, name: "rspec", coverage: 30, commit: commit FactoryGirl.create :ci_build, name: "rspec", coverage: 30, pipeline: pipeline
FactoryGirl.create :ci_build, name: "rubocop", coverage: 40, commit: commit FactoryGirl.create :ci_build, name: "rubocop", coverage: 40, pipeline: pipeline
FactoryGirl.create :ci_build, commit: commit FactoryGirl.create :ci_build, pipeline: pipeline
expect(commit.coverage).to eq("35.00") expect(pipeline.coverage).to eq("35.00")
end end
it "calculates average when there are two builds with coverage and one is retried" do it "calculates average when there are two builds with coverage and one is retried" do
FactoryGirl.create :ci_build, name: "rspec", coverage: 30, commit: commit FactoryGirl.create :ci_build, name: "rspec", coverage: 30, pipeline: pipeline
FactoryGirl.create :ci_build, name: "rubocop", coverage: 30, commit: commit FactoryGirl.create :ci_build, name: "rubocop", coverage: 30, pipeline: pipeline
FactoryGirl.create :ci_build, name: "rubocop", coverage: 40, commit: commit FactoryGirl.create :ci_build, name: "rubocop", coverage: 40, pipeline: pipeline
expect(commit.coverage).to eq("35.00") expect(pipeline.coverage).to eq("35.00")
end end
it "calculates average when there is one build without coverage" do it "calculates average when there is one build without coverage" do
FactoryGirl.create :ci_build, commit: commit FactoryGirl.create :ci_build, pipeline: pipeline
expect(commit.coverage).to be_nil expect(pipeline.coverage).to be_nil
end end
end end
describe '#retryable?' do describe '#retryable?' do
subject { commit.retryable? } subject { pipeline.retryable? }
context 'no failed builds' do context 'no failed builds' do
before do before do
FactoryGirl.create :ci_build, name: "rspec", commit: commit, status: 'success' FactoryGirl.create :ci_build, name: "rspec", pipeline: pipeline, status: 'success'
end end
it 'be not retryable' do it 'be not retryable' do
...@@ -322,8 +322,8 @@ describe Ci::Commit, models: true do ...@@ -322,8 +322,8 @@ describe Ci::Commit, models: true do
context 'with failed builds' do context 'with failed builds' do
before do before do
FactoryGirl.create :ci_build, name: "rspec", commit: commit, status: 'running' FactoryGirl.create :ci_build, name: "rspec", pipeline: pipeline, status: 'running'
FactoryGirl.create :ci_build, name: "rubocop", commit: commit, status: 'failed' FactoryGirl.create :ci_build, name: "rubocop", pipeline: pipeline, status: 'failed'
end end
it 'be retryable' do it 'be retryable' do
...@@ -333,12 +333,12 @@ describe Ci::Commit, models: true do ...@@ -333,12 +333,12 @@ describe Ci::Commit, models: true do
end end
describe '#stages' do describe '#stages' do
let(:commit2) { FactoryGirl.create :ci_commit, project: project } let(:pipeline2) { FactoryGirl.create :ci_pipeline, project: project }
subject { CommitStatus.where(commit: [commit, commit2]).stages } subject { CommitStatus.where(pipeline: [pipeline, pipeline2]).stages }
before do before do
FactoryGirl.create :ci_build, commit: commit2, stage: 'test', stage_idx: 1 FactoryGirl.create :ci_build, pipeline: pipeline2, stage: 'test', stage_idx: 1
FactoryGirl.create :ci_build, commit: commit, stage: 'build', stage_idx: 0 FactoryGirl.create :ci_build, pipeline: pipeline, stage: 'build', stage_idx: 0
end end
it 'return all stages' do it 'return all stages' do
...@@ -348,22 +348,22 @@ describe Ci::Commit, models: true do ...@@ -348,22 +348,22 @@ describe Ci::Commit, models: true do
describe '#update_state' do describe '#update_state' do
it 'execute update_state after touching object' do it 'execute update_state after touching object' do
expect(commit).to receive(:update_state).and_return(true) expect(pipeline).to receive(:update_state).and_return(true)
commit.touch pipeline.touch
end end
context 'dependent objects' do context 'dependent objects' do
let(:commit_status) { build :commit_status, commit: commit } let(:commit_status) { build :commit_status, pipeline: pipeline }
it 'execute update_state after saving dependent object' do it 'execute update_state after saving dependent object' do
expect(commit).to receive(:update_state).and_return(true) expect(pipeline).to receive(:update_state).and_return(true)
commit_status.save commit_status.save
end end
end end
context 'update state' do context 'update state' do
let(:current) { Time.now.change(usec: 0) } let(:current) { Time.now.change(usec: 0) }
let(:build) { FactoryGirl.create :ci_build, :success, commit: commit, started_at: current - 120, finished_at: current - 60 } let(:build) { FactoryGirl.create :ci_build, :success, pipeline: pipeline, started_at: current - 120, finished_at: current - 60 }
before do before do
build build
...@@ -371,18 +371,18 @@ describe Ci::Commit, models: true do ...@@ -371,18 +371,18 @@ describe Ci::Commit, models: true do
[:status, :started_at, :finished_at, :duration].each do |param| [:status, :started_at, :finished_at, :duration].each do |param|
it "update #{param}" do it "update #{param}" do
expect(commit.send(param)).to eq(build.send(param)) expect(pipeline.send(param)).to eq(build.send(param))
end end
end end
end end
end end
describe '#branch?' do describe '#branch?' do
subject { commit.branch? } subject { pipeline.branch? }
context 'is not a tag' do context 'is not a tag' do
before do before do
commit.tag = false pipeline.tag = false
end end
it 'return true when tag is set to false' do it 'return true when tag is set to false' do
...@@ -392,7 +392,7 @@ describe Ci::Commit, models: true do ...@@ -392,7 +392,7 @@ describe Ci::Commit, models: true do
context 'is not a tag' do context 'is not a tag' do
before do before do
commit.tag = true pipeline.tag = true
end end
it 'return false when tag is set to true' do it 'return false when tag is set to true' do
......
require 'spec_helper' require 'spec_helper'
describe CommitStatus, models: true do describe CommitStatus, models: true do
let(:commit) { FactoryGirl.create :ci_commit } let(:pipeline) { FactoryGirl.create :ci_pipeline }
let(:commit_status) { FactoryGirl.create :commit_status, commit: commit } let(:commit_status) { FactoryGirl.create :commit_status, pipeline: pipeline }
it { is_expected.to belong_to(:commit) } it { is_expected.to belong_to(:pipeline) }
it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_inclusion_of(:status).in_array(%w(pending running failed success canceled)) } it { is_expected.to validate_inclusion_of(:status).in_array(%w(pending running failed success canceled)) }
it { is_expected.to delegate_method(:sha).to(:commit) } it { is_expected.to delegate_method(:sha).to(:pipeline) }
it { is_expected.to delegate_method(:short_sha).to(:commit) } it { is_expected.to delegate_method(:short_sha).to(:pipeline) }
it { is_expected.to respond_to :success? } it { is_expected.to respond_to :success? }
it { is_expected.to respond_to :failed? } it { is_expected.to respond_to :failed? }
...@@ -121,11 +121,11 @@ describe CommitStatus, models: true do ...@@ -121,11 +121,11 @@ describe CommitStatus, models: true do
subject { CommitStatus.latest.order(:id) } subject { CommitStatus.latest.order(:id) }
before do before do
@commit1 = FactoryGirl.create :commit_status, commit: commit, name: 'aa', ref: 'bb', status: 'running' @commit1 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: 'bb', status: 'running'
@commit2 = FactoryGirl.create :commit_status, commit: commit, name: 'cc', ref: 'cc', status: 'pending' @commit2 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'cc', ref: 'cc', status: 'pending'
@commit3 = FactoryGirl.create :commit_status, commit: commit, name: 'aa', ref: 'cc', status: 'success' @commit3 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: 'cc', status: 'success'
@commit4 = FactoryGirl.create :commit_status, commit: commit, name: 'cc', ref: 'bb', status: 'success' @commit4 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'cc', ref: 'bb', status: 'success'
@commit5 = FactoryGirl.create :commit_status, commit: commit, name: 'aa', ref: 'bb', status: 'success' @commit5 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: 'bb', status: 'success'
end end
it 'return unique statuses' do it 'return unique statuses' do
...@@ -137,11 +137,11 @@ describe CommitStatus, models: true do ...@@ -137,11 +137,11 @@ describe CommitStatus, models: true do
subject { CommitStatus.running_or_pending.order(:id) } subject { CommitStatus.running_or_pending.order(:id) }
before do before do
@commit1 = FactoryGirl.create :commit_status, commit: commit, name: 'aa', ref: 'bb', status: 'running' @commit1 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: 'bb', status: 'running'
@commit2 = FactoryGirl.create :commit_status, commit: commit, name: 'cc', ref: 'cc', status: 'pending' @commit2 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'cc', ref: 'cc', status: 'pending'
@commit3 = FactoryGirl.create :commit_status, commit: commit, name: 'aa', ref: nil, status: 'success' @commit3 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: nil, status: 'success'
@commit4 = FactoryGirl.create :commit_status, commit: commit, name: 'dd', ref: nil, status: 'failed' @commit4 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'dd', ref: nil, status: 'failed'
@commit5 = FactoryGirl.create :commit_status, commit: commit, name: 'ee', ref: nil, status: 'canceled' @commit5 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'ee', ref: nil, status: 'canceled'
end end
it 'return statuses that are running or pending' do it 'return statuses that are running or pending' do
...@@ -152,17 +152,17 @@ describe CommitStatus, models: true do ...@@ -152,17 +152,17 @@ describe CommitStatus, models: true do
describe '#before_sha' do describe '#before_sha' do
subject { commit_status.before_sha } subject { commit_status.before_sha }
context 'when no before_sha is set for ci::commit' do context 'when no before_sha is set for pipeline' do
before { commit.before_sha = nil } before { pipeline.before_sha = nil }
it 'return blank sha' do it 'return blank sha' do
is_expected.to eq(Gitlab::Git::BLANK_SHA) is_expected.to eq(Gitlab::Git::BLANK_SHA)
end end
end end
context 'for before_sha set for ci::commit' do context 'for before_sha set for pipeline' do
let(:value) { '1234' } let(:value) { '1234' }
before { commit.before_sha = value } before { pipeline.before_sha = value }
it 'return the set value' do it 'return the set value' do
is_expected.to eq(value) is_expected.to eq(value)
...@@ -172,14 +172,14 @@ describe CommitStatus, models: true do ...@@ -172,14 +172,14 @@ describe CommitStatus, models: true do
describe '#stages' do describe '#stages' do
before do before do
FactoryGirl.create :commit_status, commit: commit, stage: 'build', stage_idx: 0, status: 'success' FactoryGirl.create :commit_status, pipeline: pipeline, stage: 'build', stage_idx: 0, status: 'success'
FactoryGirl.create :commit_status, commit: commit, stage: 'build', stage_idx: 0, status: 'failed' FactoryGirl.create :commit_status, pipeline: pipeline, stage: 'build', stage_idx: 0, status: 'failed'
FactoryGirl.create :commit_status, commit: commit, stage: 'deploy', stage_idx: 2, status: 'running' FactoryGirl.create :commit_status, pipeline: pipeline, stage: 'deploy', stage_idx: 2, status: 'running'
FactoryGirl.create :commit_status, commit: commit, stage: 'test', stage_idx: 1, status: 'success' FactoryGirl.create :commit_status, pipeline: pipeline, stage: 'test', stage_idx: 1, status: 'success'
end end
context 'stages list' do context 'stages list' do
subject { CommitStatus.where(commit: commit).stages } subject { CommitStatus.where(pipeline: pipeline).stages }
it 'return ordered list of stages' do it 'return ordered list of stages' do
is_expected.to eq(%w(build test deploy)) is_expected.to eq(%w(build test deploy))
...@@ -187,7 +187,7 @@ describe CommitStatus, models: true do ...@@ -187,7 +187,7 @@ describe CommitStatus, models: true do
end end
context 'stages with statuses' do context 'stages with statuses' do
subject { CommitStatus.where(commit: commit).stages_status } subject { CommitStatus.where(pipeline: pipeline).stages_status }
it 'return list of stages with statuses' do it 'return list of stages with statuses' do
is_expected.to eq({ is_expected.to eq({
......
require 'spec_helper' require 'spec_helper'
describe GenericCommitStatus, models: true do describe GenericCommitStatus, models: true do
let(:commit) { FactoryGirl.create :ci_commit } let(:pipeline) { FactoryGirl.create :ci_pipeline }
let(:generic_commit_status) { FactoryGirl.create :generic_commit_status, commit: commit } let(:generic_commit_status) { FactoryGirl.create :generic_commit_status, pipeline: pipeline }
describe :context do describe :context do
subject { generic_commit_status.context } subject { generic_commit_status.context }
......
...@@ -390,19 +390,19 @@ describe MergeRequest, models: true do ...@@ -390,19 +390,19 @@ describe MergeRequest, models: true do
subject { create :merge_request, :simple } subject { create :merge_request, :simple }
end end
describe '#ci_commit' do describe '#pipeline' do
describe 'when the source project exists' do describe 'when the source project exists' do
it 'returns the latest commit' do it 'returns the latest commit' do
commit = double(:commit, id: '123abc') commit = double(:commit, id: '123abc')
ci_commit = double(:ci_commit, ref: 'master') pipeline = double(:ci_pipeline, ref: 'master')
allow(subject).to receive(:last_commit).and_return(commit) allow(subject).to receive(:last_commit).and_return(commit)
expect(subject.source_project).to receive(:ci_commit). expect(subject.source_project).to receive(:pipeline).
with('123abc', 'master'). with('123abc', 'master').
and_return(ci_commit) and_return(pipeline)
expect(subject.ci_commit).to eq(ci_commit) expect(subject.pipeline).to eq(pipeline)
end end
end end
...@@ -410,7 +410,7 @@ describe MergeRequest, models: true do ...@@ -410,7 +410,7 @@ describe MergeRequest, models: true do
it 'returns nil' do it 'returns nil' do
allow(subject).to receive(:source_project).and_return(nil) allow(subject).to receive(:source_project).and_return(nil)
expect(subject.ci_commit).to be_nil expect(subject.pipeline).to be_nil
end end
end end
end end
......
...@@ -22,7 +22,7 @@ describe Project, models: true do ...@@ -22,7 +22,7 @@ describe Project, models: true do
it { is_expected.to have_one(:pushover_service).dependent(:destroy) } it { is_expected.to have_one(:pushover_service).dependent(:destroy) }
it { is_expected.to have_one(:asana_service).dependent(:destroy) } it { is_expected.to have_one(:asana_service).dependent(:destroy) }
it { is_expected.to have_many(:commit_statuses) } it { is_expected.to have_many(:commit_statuses) }
it { is_expected.to have_many(:ci_commits) } it { is_expected.to have_many(:pipelines) }
it { is_expected.to have_many(:builds) } it { is_expected.to have_many(:builds) }
it { is_expected.to have_many(:runner_projects) } it { is_expected.to have_many(:runner_projects) }
it { is_expected.to have_many(:runners) } it { is_expected.to have_many(:runners) }
...@@ -399,23 +399,23 @@ describe Project, models: true do ...@@ -399,23 +399,23 @@ describe Project, models: true do
end end
end end
describe :ci_commit do describe :pipeline do
let(:project) { create :project } let(:project) { create :project }
let(:commit) { create :ci_commit, project: project, ref: 'master' } let(:pipeline) { create :ci_pipeline, project: project, ref: 'master' }
subject { project.ci_commit(commit.sha, 'master') } subject { project.pipeline(pipeline.sha, 'master') }
it { is_expected.to eq(commit) } it { is_expected.to eq(pipeline) }
context 'return latest' do context 'return latest' do
let(:commit2) { create :ci_commit, project: project, ref: 'master' } let(:pipeline2) { create :ci_pipeline, project: project, ref: 'master' }
before do before do
commit pipeline
commit2 pipeline2
end end
it { is_expected.to eq(commit2) } it { is_expected.to eq(pipeline2) }
end end
end end
......
...@@ -9,8 +9,8 @@ describe API::API, api: true do ...@@ -9,8 +9,8 @@ describe API::API, api: true do
let!(:project) { create(:project, creator_id: user.id) } let!(:project) { create(:project, creator_id: user.id) }
let!(:developer) { create(:project_member, :developer, user: user, project: project) } let!(:developer) { create(:project_member, :developer, user: user, project: project) }
let!(:reporter) { create(:project_member, :reporter, user: user2, project: project) } let!(:reporter) { create(:project_member, :reporter, user: user2, project: project) }
let(:commit) { create(:ci_commit, project: project)} let(:pipeline) { create(:ci_pipeline, project: project)}
let(:build) { create(:ci_build, commit: commit) } let(:build) { create(:ci_build, pipeline: pipeline) }
describe 'GET /projects/:id/builds ' do describe 'GET /projects/:id/builds ' do
let(:query) { '' } let(:query) { '' }
...@@ -59,8 +59,8 @@ describe API::API, api: true do ...@@ -59,8 +59,8 @@ describe API::API, api: true do
describe 'GET /projects/:id/repository/commits/:sha/builds' do describe 'GET /projects/:id/repository/commits/:sha/builds' do
before do before do
project.ensure_ci_commit(commit.sha, 'master') project.ensure_pipeline(pipeline.sha, 'master')
get api("/projects/#{project.id}/repository/commits/#{commit.sha}/builds", api_user) get api("/projects/#{project.id}/repository/commits/#{pipeline.sha}/builds", api_user)
end end
context 'authorized user' do context 'authorized user' do
...@@ -102,7 +102,7 @@ describe API::API, api: true do ...@@ -102,7 +102,7 @@ describe API::API, api: true do
before { get api("/projects/#{project.id}/builds/#{build.id}/artifacts", api_user) } before { get api("/projects/#{project.id}/builds/#{build.id}/artifacts", api_user) }
context 'build with artifacts' do context 'build with artifacts' do
let(:build) { create(:ci_build, :artifacts, commit: commit) } let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
context 'authorized user' do context 'authorized user' do
let(:download_headers) do let(:download_headers) do
...@@ -131,7 +131,7 @@ describe API::API, api: true do ...@@ -131,7 +131,7 @@ describe API::API, api: true do
end end
describe 'GET /projects/:id/builds/:build_id/trace' do describe 'GET /projects/:id/builds/:build_id/trace' do
let(:build) { create(:ci_build, :trace, commit: commit) } let(:build) { create(:ci_build, :trace, pipeline: pipeline) }
before { get api("/projects/#{project.id}/builds/#{build.id}/trace", api_user) } before { get api("/projects/#{project.id}/builds/#{build.id}/trace", api_user) }
...@@ -181,7 +181,7 @@ describe API::API, api: true do ...@@ -181,7 +181,7 @@ describe API::API, api: true do
end end
describe 'POST /projects/:id/builds/:build_id/retry' do describe 'POST /projects/:id/builds/:build_id/retry' do
let(:build) { create(:ci_build, :canceled, commit: commit) } let(:build) { create(:ci_build, :canceled, pipeline: pipeline) }
before { post api("/projects/#{project.id}/builds/#{build.id}/retry", api_user) } before { post api("/projects/#{project.id}/builds/#{build.id}/retry", api_user) }
...@@ -218,7 +218,7 @@ describe API::API, api: true do ...@@ -218,7 +218,7 @@ describe API::API, api: true do
end end
context 'build is erasable' do context 'build is erasable' do
let(:build) { create(:ci_build, :trace, :artifacts, :success, project: project, commit: commit) } let(:build) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline) }
it 'should erase build content' do it 'should erase build content' do
expect(response.status).to eq 201 expect(response.status).to eq 201
...@@ -234,7 +234,7 @@ describe API::API, api: true do ...@@ -234,7 +234,7 @@ describe API::API, api: true do
end end
context 'build is not erasable' do context 'build is not erasable' do
let(:build) { create(:ci_build, :trace, project: project, commit: commit) } let(:build) { create(:ci_build, :trace, project: project, pipeline: pipeline) }
it 'should respond with forbidden' do it 'should respond with forbidden' do
expect(response.status).to eq 403 expect(response.status).to eq 403
......
...@@ -5,7 +5,7 @@ describe API::CommitStatuses, api: true do ...@@ -5,7 +5,7 @@ describe API::CommitStatuses, api: true do
let!(:project) { create(:project) } let!(:project) { create(:project) }
let(:commit) { project.repository.commit } let(:commit) { project.repository.commit }
let(:commit_status) { create(:commit_status, commit: ci_commit) } let(:commit_status) { create(:commit_status, pipeline: pipeline) }
let(:guest) { create_user(:guest) } let(:guest) { create_user(:guest) }
let(:reporter) { create_user(:reporter) } let(:reporter) { create_user(:reporter) }
let(:developer) { create_user(:developer) } let(:developer) { create_user(:developer) }
...@@ -16,8 +16,8 @@ describe API::CommitStatuses, api: true do ...@@ -16,8 +16,8 @@ describe API::CommitStatuses, api: true do
let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" } let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" }
context 'ci commit exists' do context 'ci commit exists' do
let!(:master) { project.ci_commits.create(sha: commit.id, ref: 'master') } let!(:master) { project.pipelines.create(sha: commit.id, ref: 'master') }
let!(:develop) { project.ci_commits.create(sha: commit.id, ref: 'develop') } let!(:develop) { project.pipelines.create(sha: commit.id, ref: 'develop') }
it_behaves_like 'a paginated resources' do it_behaves_like 'a paginated resources' do
let(:request) { get api(get_url, reporter) } let(:request) { get api(get_url, reporter) }
...@@ -27,7 +27,7 @@ describe API::CommitStatuses, api: true do ...@@ -27,7 +27,7 @@ describe API::CommitStatuses, api: true do
let(:statuses_id) { json_response.map { |status| status['id'] } } let(:statuses_id) { json_response.map { |status| status['id'] } }
def create_status(commit, opts = {}) def create_status(commit, opts = {})
create(:commit_status, { commit: commit, ref: commit.ref }.merge(opts)) create(:commit_status, { pipeline: commit, ref: commit.ref }.merge(opts))
end end
let!(:status1) { create_status(master, status: 'running') } let!(:status1) { create_status(master, status: 'running') }
......
...@@ -90,10 +90,10 @@ describe API::API, api: true do ...@@ -90,10 +90,10 @@ describe API::API, api: true do
end end
it "should return status for CI" do it "should return status for CI" do
ci_commit = project.ensure_ci_commit(project.repository.commit.sha, 'master') pipeline = project.ensure_pipeline(project.repository.commit.sha, 'master')
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(json_response['status']).to eq(ci_commit.status) expect(json_response['status']).to eq(pipeline.status)
end end
end end
......
...@@ -387,7 +387,7 @@ describe API::API, api: true do ...@@ -387,7 +387,7 @@ describe API::API, api: true do
end end
describe "PUT /projects/:id/merge_requests/:merge_request_id/merge" do describe "PUT /projects/:id/merge_requests/:merge_request_id/merge" do
let(:ci_commit) { create(:ci_commit_without_jobs) } let(:pipeline) { create(:ci_pipeline_without_jobs) }
it "should return merge_request in case of success" do it "should return merge_request in case of success" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user)
...@@ -441,8 +441,8 @@ describe API::API, api: true do ...@@ -441,8 +441,8 @@ describe API::API, api: true do
end end
it "enables merge when build succeeds if the ci is active" do it "enables merge when build succeeds if the ci is active" do
allow_any_instance_of(MergeRequest).to receive(:ci_commit).and_return(ci_commit) allow_any_instance_of(MergeRequest).to receive(:pipeline).and_return(pipeline)
allow(ci_commit).to receive(:active?).and_return(true) allow(pipeline).to receive(:active?).and_return(true)
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), merge_when_build_succeeds: true put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), merge_when_build_succeeds: true
......
...@@ -23,7 +23,7 @@ describe API::API do ...@@ -23,7 +23,7 @@ describe API::API do
end end
before do before do
stub_ci_commit_to_return_yaml_file stub_ci_pipeline_to_return_yaml_file
end end
context 'Handles errors' do context 'Handles errors' do
...@@ -44,13 +44,13 @@ describe API::API do ...@@ -44,13 +44,13 @@ describe API::API do
end end
context 'Have a commit' do context 'Have a commit' do
let(:commit) { project.ci_commits.last } let(:pipeline) { project.pipelines.last }
it 'should create builds' do it 'should create builds' do
post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'master') post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'master')
expect(response.status).to eq(201) expect(response.status).to eq(201)
commit.builds.reload pipeline.builds.reload
expect(commit.builds.size).to eq(2) expect(pipeline.builds.size).to eq(2)
end end
it 'should return bad request with no builds created if there\'s no commit for that ref' do it 'should return bad request with no builds created if there\'s no commit for that ref' do
...@@ -79,8 +79,8 @@ describe API::API do ...@@ -79,8 +79,8 @@ describe API::API do
it 'create trigger request with variables' do it 'create trigger request with variables' do
post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: variables, ref: 'master') post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: variables, ref: 'master')
expect(response.status).to eq(201) expect(response.status).to eq(201)
commit.builds.reload pipeline.builds.reload
expect(commit.builds.first.trigger_request.variables).to eq(variables) expect(pipeline.builds.first.trigger_request.variables).to eq(variables)
end end
end end
end end
......
...@@ -7,7 +7,7 @@ describe Ci::API::API do ...@@ -7,7 +7,7 @@ describe Ci::API::API do
let(:project) { FactoryGirl.create(:empty_project) } let(:project) { FactoryGirl.create(:empty_project) }
before do before do
stub_ci_commit_to_return_yaml_file stub_ci_pipeline_to_return_yaml_file
end end
describe "Builds API for runners" do describe "Builds API for runners" do
...@@ -20,9 +20,9 @@ describe Ci::API::API do ...@@ -20,9 +20,9 @@ describe Ci::API::API do
describe "POST /builds/register" do describe "POST /builds/register" do
it "should start a build" do it "should start a build" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master') pipeline = FactoryGirl.create(:ci_pipeline, project: project, ref: 'master')
commit.create_builds(nil) pipeline.create_builds(nil)
build = commit.builds.first build = pipeline.builds.first
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
...@@ -38,8 +38,8 @@ describe Ci::API::API do ...@@ -38,8 +38,8 @@ describe Ci::API::API do
end end
it "should return 404 error if no builds for specific runner" do it "should return 404 error if no builds for specific runner" do
commit = FactoryGirl.create(:ci_commit, project: shared_project) pipeline = FactoryGirl.create(:ci_pipeline, project: shared_project)
FactoryGirl.create(:ci_build, commit: commit, status: 'pending') FactoryGirl.create(:ci_build, pipeline: pipeline, status: 'pending')
post ci_api("/builds/register"), token: runner.token post ci_api("/builds/register"), token: runner.token
...@@ -47,8 +47,8 @@ describe Ci::API::API do ...@@ -47,8 +47,8 @@ describe Ci::API::API do
end end
it "should return 404 error if no builds for shared runner" do it "should return 404 error if no builds for shared runner" do
commit = FactoryGirl.create(:ci_commit, project: project) pipeline = FactoryGirl.create(:ci_pipeline, project: project)
FactoryGirl.create(:ci_build, commit: commit, status: 'pending') FactoryGirl.create(:ci_build, pipeline: pipeline, status: 'pending')
post ci_api("/builds/register"), token: shared_runner.token post ci_api("/builds/register"), token: shared_runner.token
...@@ -56,8 +56,8 @@ describe Ci::API::API do ...@@ -56,8 +56,8 @@ describe Ci::API::API do
end end
it "returns options" do it "returns options" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master') pipeline = FactoryGirl.create(:ci_pipeline, project: project, ref: 'master')
commit.create_builds(nil) pipeline.create_builds(nil)
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
...@@ -66,8 +66,8 @@ describe Ci::API::API do ...@@ -66,8 +66,8 @@ describe Ci::API::API do
end end
it "returns variables" do it "returns variables" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master') pipeline = FactoryGirl.create(:ci_pipeline, project: project, ref: 'master')
commit.create_builds(nil) pipeline.create_builds(nil)
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
...@@ -83,10 +83,10 @@ describe Ci::API::API do ...@@ -83,10 +83,10 @@ describe Ci::API::API do
it "returns variables for triggers" do it "returns variables for triggers" do
trigger = FactoryGirl.create(:ci_trigger, project: project) trigger = FactoryGirl.create(:ci_trigger, project: project)
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master') pipeline = FactoryGirl.create(:ci_pipeline, project: project, ref: 'master')
trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger) trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: pipeline, trigger: trigger)
commit.create_builds(nil, trigger_request) pipeline.create_builds(nil, trigger_request)
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
...@@ -103,9 +103,9 @@ describe Ci::API::API do ...@@ -103,9 +103,9 @@ describe Ci::API::API do
end end
it "returns dependent builds" do it "returns dependent builds" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master') pipeline = FactoryGirl.create(:ci_pipeline, project: project, ref: 'master')
commit.create_builds(nil, nil) pipeline.create_builds(nil, nil)
commit.builds.where(stage: 'test').each(&:success) pipeline.builds.where(stage: 'test').each(&:success)
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
...@@ -131,8 +131,8 @@ describe Ci::API::API do ...@@ -131,8 +131,8 @@ describe Ci::API::API do
context 'when build has no tags' do context 'when build has no tags' do
before do before do
commit = create(:ci_commit, project: project) pipeline = create(:ci_pipeline, project: project)
create(:ci_build, commit: commit, tags: []) create(:ci_build, pipeline: pipeline, tags: [])
end end
context 'when runner is allowed to pick untagged builds' do context 'when runner is allowed to pick untagged builds' do
...@@ -163,8 +163,8 @@ describe Ci::API::API do ...@@ -163,8 +163,8 @@ describe Ci::API::API do
end end
describe "PUT /builds/:id" do describe "PUT /builds/:id" do
let(:commit) {create(:ci_commit, project: project)} let(:pipeline) {create(:ci_pipeline, project: project)}
let(:build) { create(:ci_build, :trace, commit: commit, runner_id: runner.id) } let(:build) { create(:ci_build, :trace, pipeline: pipeline, runner_id: runner.id) }
before do before do
build.run! build.run!
...@@ -237,8 +237,8 @@ describe Ci::API::API do ...@@ -237,8 +237,8 @@ describe Ci::API::API do
context "Artifacts" do context "Artifacts" do
let(:file_upload) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') } let(:file_upload) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
let(:file_upload2) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/gif') } let(:file_upload2) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/gif') }
let(:commit) { create(:ci_commit, project: project) } let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, commit: commit, runner_id: runner.id) } let(:build) { create(:ci_build, pipeline: pipeline, runner_id: runner.id) }
let(:authorize_url) { ci_api("/builds/#{build.id}/artifacts/authorize") } let(:authorize_url) { ci_api("/builds/#{build.id}/artifacts/authorize") }
let(:post_url) { ci_api("/builds/#{build.id}/artifacts") } let(:post_url) { ci_api("/builds/#{build.id}/artifacts") }
let(:delete_url) { ci_api("/builds/#{build.id}/artifacts") } let(:delete_url) { ci_api("/builds/#{build.id}/artifacts") }
......
...@@ -15,7 +15,7 @@ describe Ci::API::API do ...@@ -15,7 +15,7 @@ describe Ci::API::API do
end end
before do before do
stub_ci_commit_to_return_yaml_file stub_ci_pipeline_to_return_yaml_file
end end
context 'Handles errors' do context 'Handles errors' do
...@@ -36,13 +36,13 @@ describe Ci::API::API do ...@@ -36,13 +36,13 @@ describe Ci::API::API do
end end
context 'Have a commit' do context 'Have a commit' do
let(:commit) { project.ci_commits.last } let(:pipeline) { project.pipelines.last }
it 'should create builds' do it 'should create builds' do
post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options
expect(response.status).to eq(201) expect(response.status).to eq(201)
commit.builds.reload pipeline.builds.reload
expect(commit.builds.size).to eq(2) expect(pipeline.builds.size).to eq(2)
end end
it 'should return bad request with no builds created if there\'s no commit for that ref' do it 'should return bad request with no builds created if there\'s no commit for that ref' do
...@@ -71,8 +71,8 @@ describe Ci::API::API do ...@@ -71,8 +71,8 @@ describe Ci::API::API do
it 'create trigger request with variables' do it 'create trigger request with variables' do
post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: variables) post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: variables)
expect(response.status).to eq(201) expect(response.status).to eq(201)
commit.builds.reload pipeline.builds.reload
expect(commit.builds.first.trigger_request.variables).to eq(variables) expect(pipeline.builds.first.trigger_request.variables).to eq(variables)
end end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Ci::CreateBuildsService, services: true do describe Ci::CreateBuildsService, services: true do
let(:commit) { create(:ci_commit, ref: 'master') } let(:pipeline) { create(:ci_pipeline, ref: 'master') }
let(:user) { create(:user) } let(:user) { create(:user) }
describe '#execute' do describe '#execute' do
...@@ -9,7 +9,7 @@ describe Ci::CreateBuildsService, services: true do ...@@ -9,7 +9,7 @@ describe Ci::CreateBuildsService, services: true do
# #
subject do subject do
described_class.new(commit).execute(commit, nil, user, status) described_class.new(pipeline).execute('test', nil, user, status)
end end
context 'next builds available' do context 'next builds available' do
......
...@@ -6,7 +6,7 @@ describe Ci::CreateTriggerRequestService, services: true do ...@@ -6,7 +6,7 @@ describe Ci::CreateTriggerRequestService, services: true do
let(:trigger) { create(:ci_trigger, project: project) } let(:trigger) { create(:ci_trigger, project: project) }
before do before do
stub_ci_commit_to_return_yaml_file stub_ci_pipeline_to_return_yaml_file
end end
describe :execute do describe :execute do
...@@ -27,8 +27,8 @@ describe Ci::CreateTriggerRequestService, services: true do ...@@ -27,8 +27,8 @@ describe Ci::CreateTriggerRequestService, services: true do
subject { service.execute(project, trigger, 'master') } subject { service.execute(project, trigger, 'master') }
before do before do
stub_ci_commit_yaml_file('{}') stub_ci_pipeline_yaml_file('{}')
FactoryGirl.create :ci_commit, project: project FactoryGirl.create :ci_pipeline, project: project
end end
it { expect(subject).to be_nil } it { expect(subject).to be_nil }
......
...@@ -5,8 +5,8 @@ module Ci ...@@ -5,8 +5,8 @@ module Ci
let(:service) { ImageForBuildService.new } let(:service) { ImageForBuildService.new }
let(:project) { FactoryGirl.create(:empty_project) } let(:project) { FactoryGirl.create(:empty_project) }
let(:commit_sha) { '01234567890123456789' } let(:commit_sha) { '01234567890123456789' }
let(:commit) { project.ensure_ci_commit(commit_sha, 'master') } let(:commit) { project.ensure_pipeline(commit_sha, 'master') }
let(:build) { FactoryGirl.create(:ci_build, commit: commit) } let(:build) { FactoryGirl.create(:ci_build, pipeline: commit) }
describe :execute do describe :execute do
before { build } before { build }
......
...@@ -4,8 +4,8 @@ module Ci ...@@ -4,8 +4,8 @@ module Ci
describe RegisterBuildService, services: true do describe RegisterBuildService, services: true do
let!(:service) { RegisterBuildService.new } let!(:service) { RegisterBuildService.new }
let!(:project) { FactoryGirl.create :empty_project, shared_runners_enabled: false } let!(:project) { FactoryGirl.create :empty_project, shared_runners_enabled: false }
let!(:commit) { FactoryGirl.create :ci_commit, project: project } let!(:pipeline) { FactoryGirl.create :ci_pipeline, project: project }
let!(:pending_build) { FactoryGirl.create :ci_build, commit: commit } let!(:pending_build) { FactoryGirl.create :ci_build, pipeline: pipeline }
let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) } let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) }
let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) } let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) }
......
...@@ -6,12 +6,12 @@ describe CreateCommitBuildsService, services: true do ...@@ -6,12 +6,12 @@ describe CreateCommitBuildsService, services: true do
let(:user) { nil } let(:user) { nil }
before do before do
stub_ci_commit_to_return_yaml_file stub_ci_pipeline_to_return_yaml_file
end end
describe :execute do describe :execute do
context 'valid params' do context 'valid params' do
let(:commit) do let(:pipeline) do
service.execute(project, user, service.execute(project, user,
ref: 'refs/heads/master', ref: 'refs/heads/master',
before: '00000000', before: '00000000',
...@@ -20,11 +20,11 @@ describe CreateCommitBuildsService, services: true do ...@@ -20,11 +20,11 @@ describe CreateCommitBuildsService, services: true do
) )
end end
it { expect(commit).to be_kind_of(Ci::Commit) } it { expect(pipeline).to be_kind_of(Ci::Pipeline) }
it { expect(commit).to be_valid } it { expect(pipeline).to be_valid }
it { expect(commit).to be_persisted } it { expect(pipeline).to be_persisted }
it { expect(commit).to eq(project.ci_commits.last) } it { expect(pipeline).to eq(project.pipelines.last) }
it { expect(commit.builds.first).to be_kind_of(Ci::Build) } it { expect(pipeline.builds.first).to be_kind_of(Ci::Build) }
end end
context "skip tag if there is no build for it" do context "skip tag if there is no build for it" do
...@@ -40,7 +40,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -40,7 +40,7 @@ describe CreateCommitBuildsService, services: true do
it "creates commit if there is no appropriate job but deploy job has right ref setting" do it "creates commit if there is no appropriate job but deploy job has right ref setting" do
config = YAML.dump({ deploy: { deploy: "ls", only: ["0_1"] } }) config = YAML.dump({ deploy: { deploy: "ls", only: ["0_1"] } })
stub_ci_commit_yaml_file(config) stub_ci_pipeline_yaml_file(config)
result = service.execute(project, user, result = service.execute(project, user,
ref: 'refs/heads/0_1', ref: 'refs/heads/0_1',
...@@ -52,8 +52,8 @@ describe CreateCommitBuildsService, services: true do ...@@ -52,8 +52,8 @@ describe CreateCommitBuildsService, services: true do
end end
end end
it 'skips creating ci_commit for refs without .gitlab-ci.yml' do it 'skips creating pipeline for refs without .gitlab-ci.yml' do
stub_ci_commit_yaml_file(nil) stub_ci_pipeline_yaml_file(nil)
result = service.execute(project, user, result = service.execute(project, user,
ref: 'refs/heads/0_1', ref: 'refs/heads/0_1',
before: '00000000', before: '00000000',
...@@ -61,115 +61,115 @@ describe CreateCommitBuildsService, services: true do ...@@ -61,115 +61,115 @@ describe CreateCommitBuildsService, services: true do
commits: [{ message: 'Message' }] commits: [{ message: 'Message' }]
) )
expect(result).to be_falsey expect(result).to be_falsey
expect(Ci::Commit.count).to eq(0) expect(Ci::Pipeline.count).to eq(0)
end end
it 'fails commits if yaml is invalid' do it 'fails commits if yaml is invalid' do
message = 'message' message = 'message'
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message } allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { message }
stub_ci_commit_yaml_file('invalid: file: file') stub_ci_pipeline_yaml_file('invalid: file: file')
commits = [{ message: message }] commits = [{ message: message }]
commit = service.execute(project, user, pipeline = service.execute(project, user,
ref: 'refs/tags/0_1', ref: 'refs/tags/0_1',
before: '00000000', before: '00000000',
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted expect(pipeline).to be_persisted
expect(commit.builds.any?).to be false expect(pipeline.builds.any?).to be false
expect(commit.status).to eq('failed') expect(pipeline.status).to eq('failed')
expect(commit.yaml_errors).not_to be_nil expect(pipeline.yaml_errors).not_to be_nil
end end
describe :ci_skip? do describe :ci_skip? do
let(:message) { "some message[ci skip]" } let(:message) { "some message[ci skip]" }
before do before do
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message } allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { message }
end end
it "skips builds creation if there is [ci skip] tag in commit message" do it "skips builds creation if there is [ci skip] tag in commit message" do
commits = [{ message: message }] commits = [{ message: message }]
commit = service.execute(project, user, pipeline = service.execute(project, user,
ref: 'refs/tags/0_1', ref: 'refs/tags/0_1',
before: '00000000', before: '00000000',
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted expect(pipeline).to be_persisted
expect(commit.builds.any?).to be false expect(pipeline.builds.any?).to be false
expect(commit.status).to eq("skipped") expect(pipeline.status).to eq("skipped")
end end
it "does not skips builds creation if there is no [ci skip] tag in commit message" do it "does not skips builds creation if there is no [ci skip] tag in commit message" do
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { "some message" } allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { "some message" }
commits = [{ message: "some message" }] commits = [{ message: "some message" }]
commit = service.execute(project, user, pipeline = service.execute(project, user,
ref: 'refs/tags/0_1', ref: 'refs/tags/0_1',
before: '00000000', before: '00000000',
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted expect(pipeline).to be_persisted
expect(commit.builds.first.name).to eq("staging") expect(pipeline.builds.first.name).to eq("staging")
end end
it "skips builds creation if there is [ci skip] tag in commit message and yaml is invalid" do it "skips builds creation if there is [ci skip] tag in commit message and yaml is invalid" do
stub_ci_commit_yaml_file('invalid: file: fiile') stub_ci_pipeline_yaml_file('invalid: file: fiile')
commits = [{ message: message }] commits = [{ message: message }]
commit = service.execute(project, user, pipeline = service.execute(project, user,
ref: 'refs/tags/0_1', ref: 'refs/tags/0_1',
before: '00000000', before: '00000000',
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted expect(pipeline).to be_persisted
expect(commit.builds.any?).to be false expect(pipeline.builds.any?).to be false
expect(commit.status).to eq("skipped") expect(pipeline.status).to eq("skipped")
expect(commit.yaml_errors).to be_nil expect(pipeline.yaml_errors).to be_nil
end end
end end
it "skips build creation if there are already builds" do it "skips build creation if there are already builds" do
allow_any_instance_of(Ci::Commit).to receive(:ci_yaml_file) { gitlab_ci_yaml } allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file) { gitlab_ci_yaml }
commits = [{ message: "message" }] commits = [{ message: "message" }]
commit = service.execute(project, user, pipeline = service.execute(project, user,
ref: 'refs/heads/master', ref: 'refs/heads/master',
before: '00000000', before: '00000000',
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted expect(pipeline).to be_persisted
expect(commit.builds.count(:all)).to eq(2) expect(pipeline.builds.count(:all)).to eq(2)
commit = service.execute(project, user, pipeline = service.execute(project, user,
ref: 'refs/heads/master', ref: 'refs/heads/master',
before: '00000000', before: '00000000',
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted expect(pipeline).to be_persisted
expect(commit.builds.count(:all)).to eq(2) expect(pipeline.builds.count(:all)).to eq(2)
end end
it "creates commit with failed status if yaml is invalid" do it "creates commit with failed status if yaml is invalid" do
stub_ci_commit_yaml_file('invalid: file') stub_ci_pipeline_yaml_file('invalid: file')
commits = [{ message: "some message" }] commits = [{ message: "some message" }]
commit = service.execute(project, user, pipeline = service.execute(project, user,
ref: 'refs/tags/0_1', ref: 'refs/tags/0_1',
before: '00000000', before: '00000000',
after: '31das312', after: '31das312',
commits: commits commits: commits
) )
expect(commit).to be_persisted expect(pipeline).to be_persisted
expect(commit.status).to eq("failed") expect(pipeline.status).to eq("failed")
expect(commit.builds.any?).to be false expect(pipeline.builds.any?).to be false
end end
end end
end end
...@@ -6,7 +6,7 @@ describe MergeRequests::AddTodoWhenBuildFailsService do ...@@ -6,7 +6,7 @@ describe MergeRequests::AddTodoWhenBuildFailsService do
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:sha) { '1234567890abcdef1234567890abcdef12345678' } let(:sha) { '1234567890abcdef1234567890abcdef12345678' }
let(:ci_commit) { create(:ci_commit_with_one_job, ref: merge_request.source_branch, project: project, sha: sha) } let(:pipeline) { create(:ci_pipeline_with_one_job, ref: merge_request.source_branch, project: project, sha: sha) }
let(:service) { MergeRequests::AddTodoWhenBuildFailsService.new(project, user, commit_message: 'Awesome message') } let(:service) { MergeRequests::AddTodoWhenBuildFailsService.new(project, user, commit_message: 'Awesome message') }
let(:todo_service) { TodoService.new } let(:todo_service) { TodoService.new }
...@@ -17,13 +17,13 @@ describe MergeRequests::AddTodoWhenBuildFailsService do ...@@ -17,13 +17,13 @@ describe MergeRequests::AddTodoWhenBuildFailsService do
end end
before do before do
allow_any_instance_of(MergeRequest).to receive(:ci_commit).and_return(ci_commit) allow_any_instance_of(MergeRequest).to receive(:pipeline).and_return(pipeline)
allow(service).to receive(:todo_service).and_return(todo_service) allow(service).to receive(:todo_service).and_return(todo_service)
end end
describe '#execute' do describe '#execute' do
context 'commit status with ref' do context 'commit status with ref' do
let(:commit_status) { create(:generic_commit_status, ref: merge_request.source_branch, commit: ci_commit) } let(:commit_status) { create(:generic_commit_status, ref: merge_request.source_branch, pipeline: pipeline) }
it 'notifies the todo service' do it 'notifies the todo service' do
expect(todo_service).to receive(:merge_request_build_failed).with(merge_request) expect(todo_service).to receive(:merge_request_build_failed).with(merge_request)
...@@ -52,7 +52,7 @@ describe MergeRequests::AddTodoWhenBuildFailsService do ...@@ -52,7 +52,7 @@ describe MergeRequests::AddTodoWhenBuildFailsService do
describe '#close' do describe '#close' do
context 'commit status with ref' do context 'commit status with ref' do
let(:commit_status) { create(:generic_commit_status, ref: merge_request.source_branch, commit: ci_commit) } let(:commit_status) { create(:generic_commit_status, ref: merge_request.source_branch, pipeline: pipeline) }
it 'notifies the todo service' do it 'notifies the todo service' do
expect(todo_service).to receive(:merge_request_build_retried).with(merge_request) expect(todo_service).to receive(:merge_request_build_retried).with(merge_request)
......
...@@ -10,7 +10,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -10,7 +10,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
source_project: project, target_project: project, state: "opened") source_project: project, target_project: project, state: "opened")
end end
let(:ci_commit) { create(:ci_commit_with_one_job, ref: mr_merge_if_green_enabled.source_branch, project: project) } let(:pipeline) { create(:ci_pipeline_with_one_job, ref: mr_merge_if_green_enabled.source_branch, project: project) }
let(:service) { MergeRequests::MergeWhenBuildSucceedsService.new(project, user, commit_message: 'Awesome message') } let(:service) { MergeRequests::MergeWhenBuildSucceedsService.new(project, user, commit_message: 'Awesome message') }
describe "#execute" do describe "#execute" do
...@@ -21,7 +21,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -21,7 +21,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
context 'first time enabling' do context 'first time enabling' do
before do before do
allow(merge_request).to receive(:ci_commit).and_return(ci_commit) allow(merge_request).to receive(:pipeline).and_return(pipeline)
service.execute(merge_request) service.execute(merge_request)
end end
...@@ -43,9 +43,9 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -43,9 +43,9 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
let(:build) { create(:ci_build, ref: mr_merge_if_green_enabled.source_branch) } let(:build) { create(:ci_build, ref: mr_merge_if_green_enabled.source_branch) }
before do before do
allow(mr_merge_if_green_enabled).to receive(:ci_commit).and_return(ci_commit) allow(mr_merge_if_green_enabled).to receive(:pipeline).and_return(pipeline)
allow(mr_merge_if_green_enabled).to receive(:mergeable?).and_return(true) allow(mr_merge_if_green_enabled).to receive(:mergeable?).and_return(true)
allow(ci_commit).to receive(:success?).and_return(true) allow(pipeline).to receive(:success?).and_return(true)
end end
it 'updates the merge params' do it 'updates the merge params' do
...@@ -62,8 +62,8 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -62,8 +62,8 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
let(:build) { create(:ci_build, ref: mr_merge_if_green_enabled.source_branch, status: "success") } let(:build) { create(:ci_build, ref: mr_merge_if_green_enabled.source_branch, status: "success") }
it "merges all merge requests with merge when build succeeds enabled" do it "merges all merge requests with merge when build succeeds enabled" do
allow_any_instance_of(MergeRequest).to receive(:ci_commit).and_return(ci_commit) allow_any_instance_of(MergeRequest).to receive(:pipeline).and_return(pipeline)
allow(ci_commit).to receive(:success?).and_return(true) allow(pipeline).to receive(:success?).and_return(true)
expect(MergeWorker).to receive(:perform_async) expect(MergeWorker).to receive(:perform_async)
service.trigger(build) service.trigger(build)
...@@ -75,8 +75,8 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -75,8 +75,8 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
let(:build) { create(:ci_build, ref: mr_merge_if_green_enabled.source_branch, status: "success") } let(:build) { create(:ci_build, ref: mr_merge_if_green_enabled.source_branch, status: "success") }
it "merges all merge requests with merge when build succeeds enabled" do it "merges all merge requests with merge when build succeeds enabled" do
allow_any_instance_of(MergeRequest).to receive(:ci_commit).and_return(ci_commit) allow_any_instance_of(MergeRequest).to receive(:pipeline).and_return(pipeline)
allow(ci_commit).to receive(:success?).and_return(true) allow(pipeline).to receive(:success?).and_return(true)
allow(old_build).to receive(:sha).and_return('1234abcdef') allow(old_build).to receive(:sha).and_return('1234abcdef')
expect(MergeWorker).not_to receive(:perform_async) expect(MergeWorker).not_to receive(:perform_async)
...@@ -99,9 +99,9 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -99,9 +99,9 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
it 'discovers branches and merges all merge requests when status is success' do it 'discovers branches and merges all merge requests when status is success' do
allow(project.repository).to receive(:branch_names_contains). allow(project.repository).to receive(:branch_names_contains).
with(commit_status.sha).and_return([mr_merge_if_green_enabled.source_branch]) with(commit_status.sha).and_return([mr_merge_if_green_enabled.source_branch])
allow(ci_commit).to receive(:success?).and_return(true) allow(pipeline).to receive(:success?).and_return(true)
allow_any_instance_of(MergeRequest).to receive(:ci_commit).and_return(ci_commit) allow_any_instance_of(MergeRequest).to receive(:pipeline).and_return(pipeline)
allow(ci_commit).to receive(:success?).and_return(true) allow(pipeline).to receive(:success?).and_return(true)
expect(MergeWorker).to receive(:perform_async) expect(MergeWorker).to receive(:perform_async)
service.trigger(commit_status) service.trigger(commit_status)
...@@ -110,17 +110,17 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -110,17 +110,17 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
context 'properly handles multiple stages' do context 'properly handles multiple stages' do
let(:ref) { mr_merge_if_green_enabled.source_branch } let(:ref) { mr_merge_if_green_enabled.source_branch }
let(:build) { create(:ci_build, commit: ci_commit, ref: ref, name: 'build', stage: 'build') } let(:build) { create(:ci_build, pipeline: pipeline, ref: ref, name: 'build', stage: 'build') }
let(:test) { create(:ci_build, commit: ci_commit, ref: ref, name: 'test', stage: 'test') } let(:test) { create(:ci_build, pipeline: pipeline, ref: ref, name: 'test', stage: 'test') }
before do before do
# This behavior of MergeRequest: we instantiate a new object # This behavior of MergeRequest: we instantiate a new object
allow_any_instance_of(MergeRequest).to receive(:ci_commit).and_wrap_original do allow_any_instance_of(MergeRequest).to receive(:pipeline).and_wrap_original do
Ci::Commit.find(ci_commit.id) Ci::Pipeline.find(pipeline.id)
end end
# We create test after the build # We create test after the build
allow(ci_commit).to receive(:create_next_builds).and_wrap_original do allow(pipeline).to receive(:create_next_builds).and_wrap_original do
test test
end end
end end
......
...@@ -208,7 +208,7 @@ describe SystemNoteService, services: true do ...@@ -208,7 +208,7 @@ describe SystemNoteService, services: true do
end end
describe '.merge_when_build_succeeds' do describe '.merge_when_build_succeeds' do
let(:ci_commit) { build(:ci_commit_without_jobs )} let(:pipeline) { build(:ci_pipeline_without_jobs )}
let(:noteable) do let(:noteable) do
create(:merge_request, source_project: project, target_project: project) create(:merge_request, source_project: project, target_project: project)
end end
...@@ -223,7 +223,6 @@ describe SystemNoteService, services: true do ...@@ -223,7 +223,6 @@ describe SystemNoteService, services: true do
end end
describe '.cancel_merge_when_build_succeeds' do describe '.cancel_merge_when_build_succeeds' do
let(:ci_commit) { build(:ci_commit_without_jobs) }
let(:noteable) do let(:noteable) do
create(:merge_request, source_project: project, target_project: project) create(:merge_request, source_project: project, target_project: project)
end end
......
...@@ -13,12 +13,12 @@ module StubGitlabCalls ...@@ -13,12 +13,12 @@ module StubGitlabCalls
allow_any_instance_of(Network).to receive(:projects) { project_hash_array } allow_any_instance_of(Network).to receive(:projects) { project_hash_array }
end end
def stub_ci_commit_to_return_yaml_file def stub_ci_pipeline_to_return_yaml_file
stub_ci_commit_yaml_file(gitlab_ci_yaml) stub_ci_pipeline_yaml_file(gitlab_ci_yaml)
end end
def stub_ci_commit_yaml_file(ci_yaml) def stub_ci_pipeline_yaml_file(ci_yaml)
allow_any_instance_of(Ci::Commit).to receive(:ci_yaml_file) { ci_yaml } allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file) { ci_yaml }
end end
def stub_ci_builds_disabled def stub_ci_builds_disabled
......
...@@ -52,16 +52,16 @@ describe PostReceive do ...@@ -52,16 +52,16 @@ describe PostReceive do
context "gitlab-ci.yml" do context "gitlab-ci.yml" do
subject { PostReceive.new.perform(pwd(project), key_id, base64_changes) } subject { PostReceive.new.perform(pwd(project), key_id, base64_changes) }
context "creates a Ci::Commit for every change" do context "creates a Ci::Pipeline for every change" do
before { stub_ci_commit_to_return_yaml_file } before { stub_ci_pipeline_to_return_yaml_file }
it { expect{ subject }.to change{ Ci::Commit.count }.by(2) } it { expect{ subject }.to change{ Ci::Pipeline.count }.by(2) }
end end
context "does not create a Ci::Commit" do context "does not create a Ci::Pipeline" do
before { stub_ci_commit_yaml_file(nil) } before { stub_ci_pipeline_yaml_file(nil) }
it { expect{ subject }.not_to change{ Ci::Commit.count } } it { expect{ subject }.not_to change{ Ci::Pipeline.count } }
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment