Commit fc9955ce authored by Robert Speicher's avatar Robert Speicher

Merge branch '43809-not-seeing-mentioned-in-commit-system-message-after-merging' into 'master'

Resolve "Not seeing "mentioned in commit" system message after merging"

Closes #43809

See merge request gitlab-org/gitlab-ce!17524
parents 0736197f 641b058b
...@@ -30,10 +30,9 @@ class ProcessCommitWorker ...@@ -30,10 +30,9 @@ class ProcessCommitWorker
end end
def process_commit_message(project, commit, user, author, default = false) def process_commit_message(project, commit, user, author, default = false)
# this is a GitLab generated commit message, ignore it. # Ignore closing references from GitLab-generated commit messages.
return if commit.merged_merge_request?(user) find_closing_issues = default && !commit.merged_merge_request?(user)
closed_issues = find_closing_issues ? commit.closes_issues(user) : []
closed_issues = default ? commit.closes_issues(user) : []
close_issues(project, user, author, commit, closed_issues) if closed_issues.any? close_issues(project, user, author, commit, closed_issues) if closed_issues.any?
commit.create_cross_references!(author, closed_issues) commit.create_cross_references!(author, closed_issues)
......
...@@ -20,32 +20,6 @@ describe ProcessCommitWorker do ...@@ -20,32 +20,6 @@ describe ProcessCommitWorker do
worker.perform(project.id, -1, commit.to_hash) worker.perform(project.id, -1, commit.to_hash)
end end
context 'when commit is a merge request merge commit' do
let(:merge_request) do
create(:merge_request,
description: "Closes #{issue.to_reference}",
source_branch: 'feature-merged',
target_branch: 'master',
source_project: project)
end
let(:commit) do
project.repository.create_branch('feature-merged', 'feature')
sha = project.repository.merge(user,
merge_request.diff_head_sha,
merge_request,
"Closes #{issue.to_reference}")
project.repository.commit(sha)
end
it 'it does not close any issues from the commit message' do
expect(worker).not_to receive(:close_issues)
worker.perform(project.id, user.id, commit.to_hash)
end
end
it 'processes the commit message' do it 'processes the commit message' do
expect(worker).to receive(:process_commit_message).and_call_original expect(worker).to receive(:process_commit_message).and_call_original
...@@ -73,13 +47,21 @@ describe ProcessCommitWorker do ...@@ -73,13 +47,21 @@ describe ProcessCommitWorker do
describe '#process_commit_message' do describe '#process_commit_message' do
context 'when pushing to the default branch' do context 'when pushing to the default branch' do
it 'closes issues that should be closed per the commit message' do before do
allow(commit).to receive(:safe_message).and_return("Closes #{issue.to_reference}") allow(commit).to receive(:safe_message).and_return("Closes #{issue.to_reference}")
end
it 'closes issues that should be closed per the commit message' do
expect(worker).to receive(:close_issues).with(project, user, user, commit, [issue]) expect(worker).to receive(:close_issues).with(project, user, user, commit, [issue])
worker.process_commit_message(project, commit, user, user, true) worker.process_commit_message(project, commit, user, user, true)
end end
it 'creates cross references' do
expect(commit).to receive(:create_cross_references!).with(user, [issue])
worker.process_commit_message(project, commit, user, user, true)
end
end end
context 'when pushing to a non-default branch' do context 'when pushing to a non-default branch' do
...@@ -90,12 +72,44 @@ describe ProcessCommitWorker do ...@@ -90,12 +72,44 @@ describe ProcessCommitWorker do
worker.process_commit_message(project, commit, user, user, false) worker.process_commit_message(project, commit, user, user, false)
end end
it 'does not create cross references' do
expect(commit).to receive(:create_cross_references!).with(user, [])
worker.process_commit_message(project, commit, user, user, false)
end
end end
it 'creates cross references' do context 'when commit is a merge request merge commit to the default branch' do
expect(commit).to receive(:create_cross_references!) let(:merge_request) do
create(:merge_request,
description: "Closes #{issue.to_reference}",
source_branch: 'feature-merged',
target_branch: 'master',
source_project: project)
end
worker.process_commit_message(project, commit, user, user) let(:commit) do
project.repository.create_branch('feature-merged', 'feature')
MergeRequests::MergeService
.new(project, merge_request.author)
.execute(merge_request)
merge_request.reload.merge_commit
end
it 'does not close any issues from the commit message' do
expect(worker).not_to receive(:close_issues)
worker.process_commit_message(project, commit, user, user, true)
end
it 'still creates cross references' do
expect(commit).to receive(:create_cross_references!).with(user, [])
worker.process_commit_message(project, commit, user, user, true)
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