Commit fa0ff124 authored by Kassio Borges's avatar Kassio Borges

GithubImporter: Fixes merged_by importer when merger user is nil

When the user who merged the Github Pull Request was deleted, github API
sends `nil` in the `merged_by` field. To avoid an exception, when
creating the complementary note that mentions the original merger user,
fallbacks to 'ghost' in the note.

Related to: https://gitlab.com/gitlab-org/gitlab/-/issues/334213
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65152
Changelog: fixed
parent 809d8f6c
......@@ -43,7 +43,7 @@ module Gitlab
def missing_author_note
s_("GitHubImporter|*Merged by: %{author} at %{timestamp}*") % {
author: pull_request.merged_by.login,
author: pull_request.merged_by&.login || 'ghost',
timestamp: pull_request.merged_at
}
end
......
......@@ -8,13 +8,14 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestMergedByImporter, :cle
let(:project) { merge_request.project }
let(:merged_at) { Time.new(2017, 1, 1, 12, 00).utc }
let(:client_double) { double(user: double(id: 999, login: 'merger', email: 'merger@email.com')) }
let(:merger_user) { double(id: 999, login: 'merger') }
let(:pull_request) do
instance_double(
Gitlab::GithubImport::Representation::PullRequest,
iid: merge_request.iid,
merged_at: merged_at,
merged_by: double(id: 999, login: 'merger')
merged_by: merger_user
)
end
......@@ -48,4 +49,23 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestMergedByImporter, :cle
expect(last_note.author).to eq(project.creator)
end
end
context 'when the merger user is not provided' do
let(:merger_user) { nil }
it 'adds a note referencing the merger user' do
expect { subject.execute }
.to change(Note, :count).by(1)
.and not_change(merge_request, :updated_at)
metrics = merge_request.metrics.reload
expect(metrics.merged_by).to be_nil
expect(metrics.merged_at).to eq(merged_at)
last_note = merge_request.notes.last
expect(last_note.note).to eq("*Merged by: ghost at 2017-01-01 12:00:00 UTC*")
expect(last_note.created_at).to eq(merged_at)
expect(last_note.author).to eq(project.creator)
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