Correct the cherry-pick message for merge commits
The list of commits must be generated from the merge request, not from a diff of the branches.
This commit is contained in:
parent
919c0c7ba7
commit
c0f921606c
5 changed files with 45 additions and 23 deletions
|
@ -251,19 +251,16 @@ class Commit
|
|||
project.repository.next_branch("cherry-pick-#{short_id}", mild: true)
|
||||
end
|
||||
|
||||
def cherry_pick_description(start_project, start_branch_name)
|
||||
def cherry_pick_description(user)
|
||||
message_buffer = "(cherry picked from commit #{sha})"
|
||||
|
||||
if merge_commit?
|
||||
compare = CompareService.new(project, sha).execute(start_project, start_branch_name)
|
||||
if merged_merge_request?(user)
|
||||
commits_in_merge_request = merged_merge_request(user).commits
|
||||
|
||||
# Ignore the merge commit.
|
||||
commits_in_merge = compare.commits[0..-2]
|
||||
|
||||
if commits_in_merge.present?
|
||||
if commits_in_merge_request.present?
|
||||
message_buffer << "\n"
|
||||
|
||||
commits_in_merge.each do |commit_in_merge|
|
||||
commits_in_merge_request.each do |commit_in_merge|
|
||||
message_buffer << "\n#{commit_in_merge.short_id} #{commit_in_merge.title}"
|
||||
end
|
||||
end
|
||||
|
@ -272,8 +269,8 @@ class Commit
|
|||
message_buffer
|
||||
end
|
||||
|
||||
def cherry_pick_message(start_project, start_branch_name)
|
||||
%Q{#{message}\n\n#{cherry_pick_description(start_project, start_branch_name)}}
|
||||
def cherry_pick_message(user)
|
||||
%Q{#{message}\n\n#{cherry_pick_description(user)}}
|
||||
end
|
||||
|
||||
def revert_description(user)
|
||||
|
|
|
@ -879,9 +879,7 @@ class Repository
|
|||
|
||||
committer = user_to_committer(user)
|
||||
|
||||
commit_message = commit.cherry_pick_message(start_project, start_branch_name)
|
||||
|
||||
create_commit(message: commit_message,
|
||||
create_commit(message: commit.cherry_pick_message(user),
|
||||
author: {
|
||||
email: commit.author_email,
|
||||
name: commit.author_name,
|
||||
|
|
|
@ -196,25 +196,52 @@ eos
|
|||
end
|
||||
|
||||
describe '#cherry_pick_message' do
|
||||
let(:regular_commit) { project.commit('video') }
|
||||
let(:merge_commit) { project.commit('wip') }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
context 'of a regular commit' do
|
||||
it { expect(regular_commit.cherry_pick_message(project, 'master')).to include("\n\n(cherry picked from commit 88790590ed1337ab189bccaa355f068481c90bec)") }
|
||||
let(:commit) { project.commit('video') }
|
||||
|
||||
it { expect(commit.cherry_pick_message(user)).to include("\n\n(cherry picked from commit 88790590ed1337ab189bccaa355f068481c90bec)") }
|
||||
end
|
||||
|
||||
context 'of a merge commit' do
|
||||
let(:repository) { project.repository }
|
||||
|
||||
let(:commit_options) do
|
||||
author = repository.user_to_committer(user)
|
||||
commit_options = { message: 'Test message', committer: author, author: author }
|
||||
end
|
||||
|
||||
let(:merge_commit) do
|
||||
merge_request = create(:merge_request,
|
||||
source_branch: 'feature',
|
||||
target_branch: 'master',
|
||||
source_project: project,
|
||||
author: user)
|
||||
|
||||
merge_commit_id = repository.merge(user,
|
||||
merge_request.diff_head_sha,
|
||||
merge_request,
|
||||
commit_options)
|
||||
|
||||
merge_commit = repository.commit(merge_commit_id)
|
||||
|
||||
# Manually mark as completed.
|
||||
#
|
||||
merge_request.update(merge_commit_sha: merge_commit_id)
|
||||
|
||||
merge_commit
|
||||
end
|
||||
|
||||
it do
|
||||
expected_appended_text = <<~STR.rstrip
|
||||
|
||||
(cherry picked from commit #{merge_commit.sha})
|
||||
|
||||
(cherry picked from commit b9238ee5bf1d7359dd3b8c89fd76c1c7f8b75aba)
|
||||
|
||||
6d664995 This commit will be fixupped against
|
||||
64117577 fixup! This commit will be fixupped against
|
||||
0b4bc9a4 Feature added
|
||||
STR
|
||||
|
||||
expect(merge_commit.cherry_pick_message(project, 'master')).to include(expected_appended_text)
|
||||
expect(merge_commit.cherry_pick_message(user)).to include(expected_appended_text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -791,7 +791,7 @@ describe API::Commits do
|
|||
expect(response).to have_gitlab_http_status(201)
|
||||
expect(response).to match_response_schema('public_api/v4/commit/basic')
|
||||
expect(json_response['title']).to eq(commit.title)
|
||||
expect(json_response['message']).to eq(commit.cherry_pick_message(project, branch))
|
||||
expect(json_response['message']).to eq(commit.cherry_pick_message(user))
|
||||
expect(json_response['author_name']).to eq(commit.author_name)
|
||||
expect(json_response['committer_name']).to eq(user.name)
|
||||
end
|
||||
|
|
|
@ -474,7 +474,7 @@ describe API::V3::Commits do
|
|||
|
||||
expect(response).to have_http_status(201)
|
||||
expect(json_response['title']).to eq(master_pickable_commit.title)
|
||||
expect(json_response['message']).to eq(master_pickable_commit.cherry_pick_message(project, 'master'))
|
||||
expect(json_response['message']).to eq(master_pickable_commit.cherry_pick_message(user))
|
||||
expect(json_response['author_name']).to eq(master_pickable_commit.author_name)
|
||||
expect(json_response['committer_name']).to eq(user.name)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue