summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-08-16 14:46:22 +0000
committerNick Thomas <nick@gitlab.com>2019-08-16 14:46:22 +0000
commit94c7a93dcae1a0e865d11df00ac24add676b636b (patch)
treed6df82a55295bd973f4dad50da66403262540980
parent648e5a942d4a8c66631354e05aa3f59206576dea (diff)
parenteb35728201b7f7c36979c314b86fdaafc564e190 (diff)
downloadgitlab-ce-94c7a93dcae1a0e865d11df00ac24add676b636b.tar.gz
Merge branch 'fix/commits-api-empty-refname' into 'master'
fix handling of empty ref_name parameter string in commits api Closes #64745 See merge request gitlab-org/gitlab-ce!31687
-rw-r--r--changelogs/unreleased/fix-commits-api-empty-refname.yml5
-rw-r--r--lib/api/commits.rb2
-rw-r--r--spec/requests/api/commits_spec.rb6
3 files changed, 12 insertions, 1 deletions
diff --git a/changelogs/unreleased/fix-commits-api-empty-refname.yml b/changelogs/unreleased/fix-commits-api-empty-refname.yml
new file mode 100644
index 00000000000..efdb950e45d
--- /dev/null
+++ b/changelogs/unreleased/fix-commits-api-empty-refname.yml
@@ -0,0 +1,5 @@
+---
+title: Fix 500 errors in commits api caused by empty ref_name parameter
+merge_request:
+author:
+type: fixed
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index e4f4e79cd46..a2f3e87ebd2 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -43,7 +43,7 @@ module API
path = params[:path]
before = params[:until]
after = params[:since]
- ref = params[:ref_name] || user_project.try(:default_branch) || 'master' unless params[:all]
+ ref = params[:ref_name].presence || user_project.try(:default_branch) || 'master' unless params[:all]
offset = (params[:page] - 1) * params[:per_page]
all = params[:all]
with_stats = params[:with_stats]
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb
index e8e17228523..5e6ff40e8cf 100644
--- a/spec/requests/api/commits_spec.rb
+++ b/spec/requests/api/commits_spec.rb
@@ -126,6 +126,12 @@ describe API::Commits do
end
end
+ context "with empty ref_name parameter" do
+ let(:route) { "/projects/#{project_id}/repository/commits?ref_name=" }
+
+ it_behaves_like 'project commits'
+ end
+
context "path optional parameter" do
it "returns project commits matching provided path parameter" do
path = 'files/ruby/popen.rb'