summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-03-12 16:22:32 -0700
committerStan Hu <stanhu@gmail.com>2019-03-12 17:33:33 -0700
commit118d12405a8ed1e8251c74a08044e47cd17998c2 (patch)
tree33d9d6afd153e18c748e96cece30574856ee27df
parente17074139e0c6d91076fc775e50c44d45f956b1f (diff)
downloadgitlab-ce-118d12405a8ed1e8251c74a08044e47cd17998c2.tar.gz
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
-rw-r--r--changelogs/unreleased/sh-fix-blank-codeowners-ce.yml5
-rw-r--r--lib/gitlab/user_extractor.rb6
-rw-r--r--spec/lib/gitlab/user_extractor_spec.rb8
3 files changed, 18 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-fix-blank-codeowners-ce.yml b/changelogs/unreleased/sh-fix-blank-codeowners-ce.yml
new file mode 100644
index 00000000000..05ea5869eb1
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-blank-codeowners-ce.yml
@@ -0,0 +1,5 @@
+---
+title: Fix 500 error caused by CODEOWNERS with no matches
+merge_request: 26072
+author:
+type: fixed
diff --git a/lib/gitlab/user_extractor.rb b/lib/gitlab/user_extractor.rb
index 874599688bb..076781fdd96 100644
--- a/lib/gitlab/user_extractor.rb
+++ b/lib/gitlab/user_extractor.rb
@@ -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
diff --git a/spec/lib/gitlab/user_extractor_spec.rb b/spec/lib/gitlab/user_extractor_spec.rb
index fcc05ab3a0c..6e2bb81fbda 100644
--- a/spec/lib/gitlab/user_extractor_spec.rb
+++ b/spec/lib/gitlab/user_extractor_spec.rb
@@ -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