Commit 9423547f authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix other places where we still use commit attribute of Build

parent 4d5f7aa0
...@@ -104,7 +104,7 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -104,7 +104,7 @@ class Projects::CommitController < Projects::ApplicationController
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)
......
...@@ -23,7 +23,7 @@ module Ci ...@@ -23,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
......
...@@ -23,7 +23,7 @@ module API ...@@ -23,7 +23,7 @@ module API
not_found!('Commit') unless user_project.commit(params[:sha]) not_found!('Commit') unless user_project.commit(params[:sha])
ci_commits = user_project.pipelines.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?
...@@ -67,8 +67,8 @@ module API ...@@ -67,8 +67,8 @@ module API
ci_commit = @project.ensure_pipeline(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
......
...@@ -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_commit_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, pipeline: 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, pipeline: 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_commit_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, pipeline: 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, pipeline: 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::Pipeline.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
......
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