Commit 9f31fbc9831f4742618116fbc3c534fb4d3b7798
Exists in
master
and in
4 other branches
Merge pull request #5340 from Undev/feature/branches_on_commit_page_pr
Show branches list (which branches contains commit) on commit page
Showing
5 changed files
with
29 additions
and
0 deletions
Show diff stats
app/assets/javascripts/main.js.coffee
@@ -123,6 +123,10 @@ $ -> | @@ -123,6 +123,10 @@ $ -> | ||
123 | $(@).next('table').show() | 123 | $(@).next('table').show() |
124 | $(@).remove() | 124 | $(@).remove() |
125 | 125 | ||
126 | + $(".content").on "click", ".js-details-expand", -> | ||
127 | + $(@).next('.js-details-contain').removeClass("hide") | ||
128 | + $(@).remove() | ||
129 | + | ||
126 | (($) -> | 130 | (($) -> |
127 | _chosen = $.fn.chosen | 131 | _chosen = $.fn.chosen |
128 | $.fn.extend chosen: (options) -> | 132 | $.fn.extend chosen: (options) -> |
app/contexts/commit_load_context.rb
@@ -18,6 +18,7 @@ class CommitLoadContext < BaseContext | @@ -18,6 +18,7 @@ class CommitLoadContext < BaseContext | ||
18 | result[:note] = project.build_commit_note(commit) | 18 | result[:note] = project.build_commit_note(commit) |
19 | result[:line_notes] = line_notes | 19 | result[:line_notes] = line_notes |
20 | result[:notes_count] = project.notes.for_commit_id(commit.id).count | 20 | result[:notes_count] = project.notes.for_commit_id(commit.id).count |
21 | + result[:branches] = project.repository.branch_names_contains(commit.id) | ||
21 | 22 | ||
22 | begin | 23 | begin |
23 | result[:suppress_diff] = true if commit.diff_suppress? && !params[:force_show_diff] | 24 | result[:suppress_diff] = true if commit.diff_suppress? && !params[:force_show_diff] |
app/controllers/projects/commit_controller.rb
@@ -22,6 +22,7 @@ class Projects::CommitController < Projects::ApplicationController | @@ -22,6 +22,7 @@ class Projects::CommitController < Projects::ApplicationController | ||
22 | 22 | ||
23 | @note = result[:note] | 23 | @note = result[:note] |
24 | @line_notes = result[:line_notes] | 24 | @line_notes = result[:line_notes] |
25 | + @branches = result[:branches] | ||
25 | @notes_count = result[:notes_count] | 26 | @notes_count = result[:notes_count] |
26 | @target_type = :commit | 27 | @target_type = :commit |
27 | @target_id = @commit.id | 28 | @target_id = @commit.id |
app/helpers/commits_helper.rb
@@ -94,6 +94,17 @@ module CommitsHelper | @@ -94,6 +94,17 @@ module CommitsHelper | ||
94 | crumbs.html_safe | 94 | crumbs.html_safe |
95 | end | 95 | end |
96 | 96 | ||
97 | + # Return Project default branch, if it present in array | ||
98 | + # Else - first branch in array (mb last actual branch) | ||
99 | + def commit_default_branch(project, branches) | ||
100 | + branches.include?(project.default_branch) ? branches.delete(project.default_branch) : branches.pop | ||
101 | + end | ||
102 | + | ||
103 | + # Returns the sorted alphabetically links to branches, separated by a comma | ||
104 | + def commit_branches_links(project, branches) | ||
105 | + branches.sort.map { |branch| link_to(branch, project_tree_path(project, branch)) }.join(", ").html_safe | ||
106 | + end | ||
107 | + | ||
97 | protected | 108 | protected |
98 | 109 | ||
99 | # Private: Returns a link to a person. If the person has a matching user and | 110 | # Private: Returns a link to a person. If the person has a matching user and |
app/views/projects/commit/_commit_box.html.haml
@@ -39,6 +39,18 @@ | @@ -39,6 +39,18 @@ | ||
39 | - @commit.parents.each do |parent| | 39 | - @commit.parents.each do |parent| |
40 | = link_to parent.id[0...10], project_commit_path(@project, parent) | 40 | = link_to parent.id[0...10], project_commit_path(@project, parent) |
41 | 41 | ||
42 | +.commit-info-row | ||
43 | + %span.cgray | ||
44 | + Exists in | ||
45 | + %span | ||
46 | + - branch = commit_default_branch(@project, @branches) | ||
47 | + = link_to(branch, project_tree_path(@project, branch)) | ||
48 | + - if @branches.any? | ||
49 | + and in | ||
50 | + = link_to("#{pluralize(@branches.count, "other branch")}", "#", class: "js-details-expand") | ||
51 | + %span.js-details-contain.hide | ||
52 | + = commit_branches_links(@project, @branches) | ||
53 | + | ||
42 | .commit-box | 54 | .commit-box |
43 | %h3.commit-title | 55 | %h3.commit-title |
44 | = gfm escape_once(@commit.title) | 56 | = gfm escape_once(@commit.title) |