diff --git a/lib/api/v3/github.rb b/lib/api/v3/github.rb index be5caa8651098f614cd267d0680804d0fe5d17e5..bded2fb21e3fa68e8e7491f081ad3679bb60f4fa 100644 --- a/lib/api/v3/github.rb +++ b/lib/api/v3/github.rb @@ -214,6 +214,8 @@ def find_notes(noteable) update_project_feature_usage_for(user_project) + next [] unless user_project.repo_exists? + branches = ::Kaminari.paginate_array(user_project.repository.branches.sort_by(&:name)) present paginate(branches), with: ::API::Github::Entities::Branch, project: user_project diff --git a/spec/requests/api/v3/github_spec.rb b/spec/requests/api/v3/github_spec.rb index 4100b24621801246d0ab6c6d3fe83521ccc6aa15..255f53e4c7c730e5616ef71ffb389c2c9cb5c17f 100644 --- a/spec/requests/api/v3/github_spec.rb +++ b/spec/requests/api/v3/github_spec.rb @@ -472,6 +472,17 @@ def expect_project_under_namespace(projects, namespace, user) expect(response).to have_gitlab_http_status(:ok) end + + context 'when the project has no repository', :aggregate_failures do + let_it_be(:project) { create(:project, creator: user) } + + it 'returns an empty collection response' do + jira_get v3_api("/repos/#{project.namespace.path}/#{project.path}/branches", user) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to be_empty + end + end end context 'unauthenticated' do