Commit b7bbef2f authored by Furkan Ayhan's avatar Furkan Ayhan

Handle Gitaly error on fetching total-branches for pipeline editor

When fetching total-branches, it needs to call Gitaly. And sometimes,
Gitaly returns error. This commit fixes it by checking
if the repository exists.

Changelog: fixed
parent 641928a7
......@@ -12,6 +12,8 @@ module Ci
initial_branch = params[:branch_name]
latest_commit = project.repository.commit(initial_branch) || project.commit
commit_sha = latest_commit ? latest_commit.sha : ''
total_branches = project.repository_exists? ? project.repository.branch_count : 0
{
"ci-config-path": project.ci_config_path_or_default,
"ci-examples-help-page-path" => help_page_path('ci/examples/index'),
......@@ -29,7 +31,7 @@ module Ci
"project-full-path" => project.full_path,
"project-namespace" => project.namespace.full_path,
"runner-help-page-path" => help_page_path('ci/runners/index'),
"total-branches" => project.repository.branches.length,
"total-branches" => total_branches,
"yml-help-page-path" => help_page_path('ci/yaml/index')
}
end
......
......@@ -88,6 +88,17 @@ RSpec.describe Ci::PipelineEditorHelper do
end
end
context 'with a project with no repository' do
let(:project) { create(:project) }
it 'returns pipeline editor data' do
expect(pipeline_editor_data).to include({
"pipeline_etag" => '',
"total-branches" => 0
})
end
end
context 'with a non-default branch name' do
let(:user) { create(:user) }
......
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