Fix 500 error caused by CODEOWNERS with no matches

Including a CODEOWNERS file with lines without any matching username or
e-mail regular expressions would cause an Error 500. Don't attempt a
database query if there is nothing to query.

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/10282
This commit is contained in:
Stan Hu 2019-03-12 16:22:32 -07:00
parent e17074139e
commit 118d12405a
3 changed files with 18 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
title: Fix 500 error caused by CODEOWNERS with no matches
merge_request: 26072
author:
type: fixed

View File

@ -17,7 +17,11 @@ module Gitlab
def users
return User.none unless @text.present?
@users ||= User.from_union(union_relations)
relations = union_relations
return User.none unless relations.any?
@users ||= User.from_union(relations)
end
def usernames

View File

@ -48,6 +48,14 @@ describe Gitlab::UserExtractor do
it 'includes all mentioned usernames' do
expect(extractor.matches[:usernames]).to contain_exactly('user-1', 'user-2', 'user-4')
end
context 'input has no matching e-mail or usernames' do
it 'returns an empty list of users' do
extractor = described_class.new('My test')
expect(extractor.users).to be_empty
end
end
end
describe '#references' do