diff --git a/CHANGELOG b/CHANGELOG index aa7daa11947cea77563ba54bb287bed424719654..b93c15679077bdf1012e0ddf711acd6cf1fc4856 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -28,7 +28,7 @@ v 7.8.0 - Added Rubocop for code style checks - Fix commits pagination - - - + - Async load a branch information at the commit page - - - Add a commit calendar to the user profile (Hannes Rosenögger) diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 470efbd2114377e7b8e1308a45d28eda10eb5f76..96a782bdf7ab8f211c128b99b55e4078706339a9 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -11,8 +11,6 @@ class Projects::CommitController < Projects::ApplicationController return git_not_found! unless @commit @line_notes = @project.notes.for_commit_id(commit.id).inline - @branches = @project.repository.branch_names_contains(commit.id) - @tags = @project.repository.tag_names_contains(commit.id) @diffs = @commit.diffs @note = @project.build_commit_note(commit) @notes_count = @project.notes.for_commit_id(commit.id).count @@ -31,6 +29,12 @@ class Projects::CommitController < Projects::ApplicationController end end + def branches + @branches = @project.repository.branch_names_contains(commit.id) + @tags = @project.repository.tag_names_contains(commit.id) + render layout: false + end + def commit @commit ||= @project.repository.commit(params[:id]) end diff --git a/app/views/projects/commit/_commit_box.html.haml b/app/views/projects/commit/_commit_box.html.haml index b41fb1437f25c193bbd4ab33db5bf23af87ee3ed..dd28a35d41de04a3937773fbd8feb43bd5ea667a 100644 --- a/app/views/projects/commit/_commit_box.html.haml +++ b/app/views/projects/commit/_commit_box.html.haml @@ -37,23 +37,8 @@ - @commit.parents.each do |parent| = link_to parent.short_id, project_commit_path(@project, parent) -.commit-info-row - - if @branches.any? - %span - - branch = commit_default_branch(@project, @branches) - = link_to(project_tree_path(@project, branch)) do - %span.label.label-gray - %i.fa.fa-code-fork - = branch - - if @branches.any? || @tags.any? - = link_to("#", class: "js-details-expand") do - %span.label.label-gray - \... - %span.js-details-content.hide - - if @branches.any? - = commit_branches_links(@project, @branches) - - if @tags.any? - = commit_tags_links(@project, @tags) +.commit-info-row.branches + %i.fa.fa-spinner.fa-spin .commit-box %h3.commit-title @@ -61,3 +46,7 @@ - if @commit.description.present? %pre.commit-description = preserve(gfm(escape_once(@commit.description))) + +:coffeescript + $ -> + $(".commit-info-row.branches").load("#{branches_project_commit_path(@project, @commit.id)}") \ No newline at end of file diff --git a/app/views/projects/commit/branches.html.haml b/app/views/projects/commit/branches.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..b01e806210cba5bbf85c8357bb1a9b39a048c3fb --- /dev/null +++ b/app/views/projects/commit/branches.html.haml @@ -0,0 +1,16 @@ +- if @branches.any? + %span + - branch = commit_default_branch(@project, @branches) + = link_to(project_tree_path(@project, branch)) do + %span.label.label-gray + %i.fa.fa-code-fork + = branch + - if @branches.any? || @tags.any? + = link_to("#", class: "js-details-expand") do + %span.label.label-gray + \... + %span.js-details-content.hide + - if @branches.any? + = commit_branches_links(@project, @branches) + - if @tags.any? + = commit_tags_links(@project, @tags) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a2d782cf633dc30b1e130bfc4276b91e26096877..f0abd876ecda998d3d8b0efff67eb2a860a129f8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -228,7 +228,11 @@ Gitlab::Application.routes.draw do resources :raw, only: [:show], constraints: { id: /.+/ } resources :tree, only: [:show], constraints: { id: /.+/, format: /(html|js)/ } resource :avatar, only: [:show, :destroy] - resources :commit, only: [:show], constraints: { id: /[[:alnum:]]{6,40}/ } + + resources :commit, only: [:show], constraints: { id: /[[:alnum:]]{6,40}/ } do + get :branches, on: :member + end + resources :commits, only: [:show], constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ } resources :compare, only: [:index, :create] resources :blame, only: [:show], constraints: { id: /.+/ } diff --git a/spec/controllers/commit_controller_spec.rb b/spec/controllers/commit_controller_spec.rb index f5822157ea4152f4af914e2edf165c8ffbcb0212..cd8b46d7672e67ac2e439e922905d9049d93dac6 100644 --- a/spec/controllers/commit_controller_spec.rb +++ b/spec/controllers/commit_controller_spec.rb @@ -70,4 +70,13 @@ describe Projects::CommitController do end end end + + describe "#branches" do + it "contains branch and tags information" do + get :branches, project_id: project.to_param, id: commit.id + + expect(assigns(:branches)).to include("master", "feature_conflict") + expect(assigns(:tags)).to include("v1.1.0") + end + end end