mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-14 15:16:04 +10:00
Rename MergeRequest methods that return commits or shas to be more clear and consistent
This commit is contained in:
@@ -212,7 +212,7 @@ describe Projects::MergeRequestsController do
|
||||
|
||||
context 'when the sha parameter matches the source SHA' do
|
||||
def merge_with_sha
|
||||
post :merge, base_params.merge(sha: merge_request.source_sha)
|
||||
post :merge, base_params.merge(sha: merge_request.diff_head_sha)
|
||||
end
|
||||
|
||||
it 'returns :success' do
|
||||
@@ -229,11 +229,11 @@ describe Projects::MergeRequestsController do
|
||||
|
||||
context 'when merge_when_build_succeeds is passed' do
|
||||
def merge_when_build_succeeds
|
||||
post :merge, base_params.merge(sha: merge_request.source_sha, merge_when_build_succeeds: '1')
|
||||
post :merge, base_params.merge(sha: merge_request.diff_head_sha, merge_when_build_succeeds: '1')
|
||||
end
|
||||
|
||||
before do
|
||||
create(:ci_empty_pipeline, project: project, sha: merge_request.source_sha, ref: merge_request.source_branch)
|
||||
create(:ci_empty_pipeline, project: project, sha: merge_request.diff_head_sha, ref: merge_request.source_branch)
|
||||
end
|
||||
|
||||
it 'returns :merge_when_build_succeeds' do
|
||||
|
||||
@@ -30,7 +30,7 @@ feature 'Merge request created from fork' do
|
||||
|
||||
given(:pipeline) do
|
||||
create(:ci_pipeline_with_two_job, project: fork_project,
|
||||
sha: merge_request.last_commit.id,
|
||||
sha: merge_request.diff_head_sha,
|
||||
ref: merge_request.source_branch)
|
||||
end
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
|
||||
end
|
||||
|
||||
context "Active build for Merge Request" do
|
||||
let!(:pipeline) { create(:ci_pipeline, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch) }
|
||||
let!(:pipeline) { create(:ci_pipeline, project: project, sha: merge_request.diff_head_sha, ref: merge_request.source_branch) }
|
||||
let!(:ci_build) { create(:ci_build, pipeline: pipeline) }
|
||||
|
||||
before do
|
||||
@@ -47,7 +47,7 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
|
||||
merge_user: user, title: "MepMep", merge_when_build_succeeds: true)
|
||||
end
|
||||
|
||||
let!(:pipeline) { create(:ci_pipeline, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch) }
|
||||
let!(:pipeline) { create(:ci_pipeline, project: project, sha: merge_request.diff_head_sha, ref: merge_request.source_branch) }
|
||||
let!(:ci_build) { create(:ci_build, pipeline: pipeline) }
|
||||
|
||||
before do
|
||||
|
||||
@@ -19,7 +19,7 @@ feature 'Only allow merge requests to be merged if the build succeeds', feature:
|
||||
end
|
||||
|
||||
context 'when project has CI enabled' do
|
||||
let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch) }
|
||||
let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: merge_request.diff_head_sha, ref: merge_request.source_branch) }
|
||||
|
||||
context 'when merge requests can only be merged if the build succeeds' do
|
||||
before do
|
||||
|
||||
@@ -43,10 +43,10 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
|
||||
description: "*Created by: octocat*\n\nPlease pull these awesome changes",
|
||||
source_project: project,
|
||||
source_branch: 'feature',
|
||||
head_source_sha: source_sha,
|
||||
source_branch_sha: source_sha,
|
||||
target_project: project,
|
||||
target_branch: 'master',
|
||||
base_target_sha: target_sha,
|
||||
target_branch_sha: target_sha,
|
||||
state: 'opened',
|
||||
milestone: nil,
|
||||
author_id: project.creator_id,
|
||||
@@ -70,10 +70,10 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
|
||||
description: "*Created by: octocat*\n\nPlease pull these awesome changes",
|
||||
source_project: project,
|
||||
source_branch: 'feature',
|
||||
head_source_sha: source_sha,
|
||||
source_branch_sha: source_sha,
|
||||
target_project: project,
|
||||
target_branch: 'master',
|
||||
base_target_sha: target_sha,
|
||||
target_branch_sha: target_sha,
|
||||
state: 'closed',
|
||||
milestone: nil,
|
||||
author_id: project.creator_id,
|
||||
@@ -97,10 +97,10 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
|
||||
description: "*Created by: octocat*\n\nPlease pull these awesome changes",
|
||||
source_project: project,
|
||||
source_branch: 'feature',
|
||||
head_source_sha: source_sha,
|
||||
source_branch_sha: source_sha,
|
||||
target_project: project,
|
||||
target_branch: 'master',
|
||||
base_target_sha: target_sha,
|
||||
target_branch_sha: target_sha,
|
||||
state: 'merged',
|
||||
milestone: nil,
|
||||
author_id: project.creator_id,
|
||||
|
||||
@@ -125,7 +125,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
|
||||
|
||||
ci_pipeline = create(:ci_pipeline,
|
||||
project: project,
|
||||
sha: merge_request.last_commit.id,
|
||||
sha: merge_request.diff_head_sha,
|
||||
ref: merge_request.source_branch,
|
||||
statuses: [commit_status])
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ describe MergeRequest, models: true do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#target_sha' do
|
||||
describe '#target_branch_sha' do
|
||||
context 'when the target branch does not exist anymore' do
|
||||
let(:project) { create(:project) }
|
||||
|
||||
@@ -73,32 +73,32 @@ describe MergeRequest, models: true do
|
||||
end
|
||||
|
||||
it 'returns nil' do
|
||||
expect(subject.target_sha).to be_nil
|
||||
expect(subject.target_branch_sha).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#source_sha' do
|
||||
describe '#source_branch_sha' do
|
||||
let(:last_branch_commit) { subject.source_project.repository.commit(subject.source_branch) }
|
||||
|
||||
context 'with diffs' do
|
||||
subject { create(:merge_request, :with_diffs) }
|
||||
it 'returns the sha of the source branch last commit' do
|
||||
expect(subject.source_sha).to eq(last_branch_commit.sha)
|
||||
expect(subject.source_branch_sha).to eq(last_branch_commit.sha)
|
||||
end
|
||||
end
|
||||
|
||||
context 'without diffs' do
|
||||
subject { create(:merge_request, :without_diffs) }
|
||||
it 'returns the sha of the source branch last commit' do
|
||||
expect(subject.source_sha).to eq(last_branch_commit.sha)
|
||||
expect(subject.source_branch_sha).to eq(last_branch_commit.sha)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the merge request is being created' do
|
||||
subject { build(:merge_request, source_branch: nil, compare_commits: []) }
|
||||
it 'returns nil' do
|
||||
expect(subject.source_sha).to be_nil
|
||||
expect(subject.source_branch_sha).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -252,12 +252,14 @@ describe MergeRequest, models: true do
|
||||
end
|
||||
|
||||
it "can be removed if the last commit is the head of the source branch" do
|
||||
allow(subject.source_project).to receive(:commit).and_return(subject.last_commit)
|
||||
allow(subject.source_project).to receive(:commit).and_return(subject.diff_head_commit)
|
||||
|
||||
expect(subject.can_remove_source_branch?(user)).to be_truthy
|
||||
end
|
||||
|
||||
it "cannot be removed if the last commit is not also the head of the source branch" do
|
||||
subject.source_branch = "lfs"
|
||||
|
||||
expect(subject.can_remove_source_branch?(user)).to be_falsey
|
||||
end
|
||||
end
|
||||
@@ -363,7 +365,7 @@ describe MergeRequest, models: true do
|
||||
and_return(2)
|
||||
|
||||
subject.diverged_commits_count
|
||||
allow(subject).to receive(:source_sha).and_return('123abc')
|
||||
allow(subject).to receive(:source_branch_sha).and_return('123abc')
|
||||
subject.diverged_commits_count
|
||||
end
|
||||
|
||||
@@ -373,7 +375,7 @@ describe MergeRequest, models: true do
|
||||
and_return(2)
|
||||
|
||||
subject.diverged_commits_count
|
||||
allow(subject).to receive(:target_sha).and_return('123abc')
|
||||
allow(subject).to receive(:target_branch_sha).and_return('123abc')
|
||||
subject.diverged_commits_count
|
||||
end
|
||||
end
|
||||
@@ -392,11 +394,10 @@ describe MergeRequest, models: true do
|
||||
|
||||
describe '#pipeline' do
|
||||
describe 'when the source project exists' do
|
||||
it 'returns the latest commit' do
|
||||
commit = double(:commit, id: '123abc')
|
||||
it 'returns the latest pipeline' do
|
||||
pipeline = double(:ci_pipeline, ref: 'master')
|
||||
|
||||
allow(subject).to receive(:last_commit).and_return(commit)
|
||||
allow(subject).to receive(:diff_head_sha).and_return('123abc')
|
||||
|
||||
expect(subject.source_project).to receive(:pipeline).
|
||||
with('123abc', 'master').
|
||||
@@ -464,7 +465,7 @@ describe MergeRequest, models: true do
|
||||
context 'when it is not broken and has no conflicts' do
|
||||
it 'is marked as mergeable' do
|
||||
allow(subject).to receive(:broken?) { false }
|
||||
allow(project.repository).to receive(:can_be_merged?) { true }
|
||||
allow(project.repository).to receive(:can_be_merged?).and_return(true)
|
||||
|
||||
expect { subject.check_if_can_be_merged }.to change { subject.merge_status }.to('can_be_merged')
|
||||
end
|
||||
@@ -481,7 +482,7 @@ describe MergeRequest, models: true do
|
||||
context 'when it has conflicts' do
|
||||
before do
|
||||
allow(subject).to receive(:broken?) { false }
|
||||
allow(project.repository).to receive(:can_be_merged?) { false }
|
||||
allow(project.repository).to receive(:can_be_merged?).and_return(false)
|
||||
end
|
||||
|
||||
it 'becomes unmergeable' do
|
||||
|
||||
@@ -312,7 +312,7 @@ describe Project, models: true do
|
||||
it 'should update merge request commits with new one if pushed to source branch' do
|
||||
project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.source_branch}", key.user)
|
||||
merge_request.reload
|
||||
expect(merge_request.last_commit.id).to eq(commit_id)
|
||||
expect(merge_request.diff_head_sha).to eq(commit_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ describe Repository, models: true do
|
||||
end
|
||||
let(:merge_commit) do
|
||||
source_sha = repository.find_branch('feature').target
|
||||
merge_commit_id = repository.merge(user, source_sha, 'master', commit_options)
|
||||
repository.commit(merge_commit_id)
|
||||
merge_commit_sha = repository.merge(user, source_sha, 'master', commit_options)
|
||||
repository.commit(merge_commit_sha)
|
||||
end
|
||||
|
||||
describe :branch_names_contains do
|
||||
|
||||
@@ -439,14 +439,14 @@ describe API::API, api: true do
|
||||
end
|
||||
|
||||
it "returns 409 if the SHA parameter doesn't match" do
|
||||
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), sha: merge_request.source_sha.succ
|
||||
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), sha: merge_request.diff_head_sha.reverse
|
||||
|
||||
expect(response).to have_http_status(409)
|
||||
expect(json_response['message']).to start_with('SHA does not match HEAD of source branch')
|
||||
end
|
||||
|
||||
it "succeeds if the SHA parameter matches" do
|
||||
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), sha: merge_request.source_sha
|
||||
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), sha: merge_request.diff_head_sha
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
@@ -213,7 +213,7 @@ describe SystemNoteService, services: true do
|
||||
create(:merge_request, source_project: project, target_project: project)
|
||||
end
|
||||
|
||||
subject { described_class.merge_when_build_succeeds(noteable, project, author, noteable.last_commit) }
|
||||
subject { described_class.merge_when_build_succeeds(noteable, project, author, noteable.diff_head_commit) }
|
||||
|
||||
it_behaves_like 'a system note'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user