Commit cb196194 authored by Igor Drozdov's avatar Igor Drozdov

Display stale branches oldest at the top

Currently, branches#index (overview and stale) displays the most
recent stale branch (updated 3 months ago). It's more reasonable
to display the stalest branches there instead.
parent 2f219efa
...@@ -18,8 +18,8 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -18,8 +18,8 @@ class Projects::BranchesController < Projects::ApplicationController
def index def index
respond_to do |format| respond_to do |format|
format.html do format.html do
@sort = params[:sort].presence || sort_value_recently_updated
@mode = params[:state].presence || 'overview' @mode = params[:state].presence || 'overview'
@sort = sort_value_for_mode
@overview_max_branches = 5 @overview_max_branches = 5
# Fetch branches for the specified mode # Fetch branches for the specified mode
...@@ -125,6 +125,12 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -125,6 +125,12 @@ class Projects::BranchesController < Projects::ApplicationController
private private
def sort_value_for_mode
return params[:sort] if params[:sort].present?
'stale' == @mode ? sort_value_oldest_updated : sort_value_recently_updated
end
# It can be expensive to calculate the diverging counts for each # It can be expensive to calculate the diverging counts for each
# branch. Normally the frontend should be specifying a set of branch # branch. Normally the frontend should be specifying a set of branch
# names, but prior to # names, but prior to
......
...@@ -512,7 +512,8 @@ RSpec.describe Projects::BranchesController do ...@@ -512,7 +512,8 @@ RSpec.describe Projects::BranchesController do
state: 'all' state: 'all'
} }
expect(controller.instance_variable_get(:@branch_pipeline_statuses)["master"].group).to eq("success") expect(assigns[:branch_pipeline_statuses]["master"].group).to eq("success")
expect(assigns[:sort]).to eq('updated_desc')
end end
end end
...@@ -543,8 +544,8 @@ RSpec.describe Projects::BranchesController do ...@@ -543,8 +544,8 @@ RSpec.describe Projects::BranchesController do
state: 'all' state: 'all'
} }
expect(controller.instance_variable_get(:@branch_pipeline_statuses)["master"].group).to eq("running") expect(assigns[:branch_pipeline_statuses]["master"].group).to eq("running")
expect(controller.instance_variable_get(:@branch_pipeline_statuses)["test"].group).to eq("success") expect(assigns[:branch_pipeline_statuses]["test"].group).to eq("success")
end end
end end
...@@ -555,10 +556,11 @@ RSpec.describe Projects::BranchesController do ...@@ -555,10 +556,11 @@ RSpec.describe Projects::BranchesController do
params: { params: {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
state: 'all' state: 'stale'
} }
expect(controller.instance_variable_get(:@branch_pipeline_statuses)).to be_blank expect(assigns[:branch_pipeline_statuses]).to be_blank
expect(assigns[:sort]).to eq('updated_asc')
end end
end end
...@@ -573,10 +575,12 @@ RSpec.describe Projects::BranchesController do ...@@ -573,10 +575,12 @@ RSpec.describe Projects::BranchesController do
params: { params: {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
sort: 'name_asc',
state: 'all' state: 'all'
} }
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(assigns[:sort]).to eq('name_asc')
end end
end end
......
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